npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cycle-fela

v0.2.1

Published

Use fela in cycle js

Downloads

11

Readme

Unofficial Cycle bindings for Fela.

Build Status codecov

npm install --save cycle-fela
# or if you're using yarn
yarn add cycle-fela

Usage

Behind the scene, this driver use @cycle/dom to handle the DOM. docs. But he does more than that (obviously :P). He creates a rendered for fela and handle a property in the props of your dom element. The driver looks for the component prop and use it to create the fela style.


import xs from 'xstream'
import { run } from '@cycle/run'
import { createRenderer } from 'fela'
import { span, hr } from '@cycle/dom'
import { makeFelaDomDriver, createComponent } from 'cycle-fela'

const styleNode = document.createElement('style')
document.head.appendChild(styleNode)

const root = document.createElement('div')
document.body.appendChild(root)

const RedLabel = createComponent(() => ({ color: 'red' }), 'label')
const Container = createComponent(({ mobile = true }) => ({
  display: 'flex',
  flex: mobile ? '1' : '2',
}))

function main(sources) {
  const vdom$ = xs.of(
    Container({ mobile: false }, [RedLabel('test'), span('Name:'), hr(), span(`Hello`)]),
  )
  return {
    DOM: vdom$
  }
}

run(main, {
  DOM: makeFelaDomDriver(
    root,
    { customStyleNode: styleNode }
  )
})

Example

Created with create-cycle-app and then add cycle-fela

Docs

makeFelaDomDriver

Create the driver for fela and DOM. Replace the makeDomDriver from @cycle/dom.

   makeFelaDomDriver('#app')

   const root = document.createElement('div')
   root.id = 'app'
   document.head.appendChild(root)
   makeFelaDomDriver(root)

   const nodeStyle = document.createElement('style')
   document.head.appendChild(nodeStyle)
   makeFelaDomDriver('#app-with-style', { customStyleNode: nodeStyle })

   makeFelaDomDriver('#app', { renderedOpts: { plugins: [...webPresets] } })

   // and pass it to your cycle app :
   run(main, { DOM: makeFelaDomDriver('#app') })

It takes 3 parameters :

  • selector : domNode || string -- (same as makeDomDriver)
  • options : ?Object -- default: { renderedOpts = {}, customStyleNode }
  • staticRules : ?Array -- default: []
options take two parameters:
  • rendererdOpts are the options pass to fela renderer. Config can be found here
  • customStyleNode let you specify a custom DOMNodeStyle to the renderer of fela. By default the driver create one without any id or class
staticRules take an array of staticRule for fela:

Allow to pass staticRules to fela renderer, each element of the array should be compatible with fela's renderStatic function parameters.

createComponent

Create a fela component with pre defined style and selector.


const RedLabel = createComponent(() => ({color: 'red'}), 'label')
const Container = createComponent(({mobile = true}) => ({display: 'flex', flex: mobile ? '1' : '2'}))
function main(sources) {
  const vdom$ = xs.of(
    Container({ mobile: true }, [
      RedLabel('test'),
      label('Name:'),
      hr(),
      h1(`Hello ${name}`),
    ]),
  )
  return { DOM: vdom$ }
}

const el = document.createElement('div')
el.id = 'app-test'
document.body.appendChild(el)

run(main, { DOM: makeFelaDomDriver('#app') })

The first call takes 2 parameters and return a new function:

  • style: (props:Object) => Object
  • selector: ?string -- default: 'div'
style

Takes the rules for the fela component. docs

selector

Takes a tag or a tag/selector like h() from snabbdom

The second call takes 2 parameters too and return a DOMNode:

  • props: ?Object -- default: {}
  • children: string | DOMNode | Array

if the function is called with only one parameter which is not an object, then it consider the parameter to be the children.

props

props passed to the component. Like this props of h() from snabbdom

children

Children of the component. He can be a string, a DOMNode or an array of DOMNode. Like this children of h() from snabbdom

License

Copyright © 2017 Castandet William. Licensed under the MIT License, see LICENSE.md for more information!