Skip to content
cluelessjoe edited this page Apr 5, 2017 · 3 revisions

Frequently Asked Questions

How do you create a dynamic list of child components?

tl;dr version

There are 4 solutions:

  1. Manually build the dataflow, which will contain circular dependencies. Check out this example
  2. Global state at the top-most component (main).
  3. Use Stanga and similars.
  4. Use Cycle Collections

For more information on the pros and cons of each method, look at this issue for more info.

How do you manage your application state?

There's a few ways to go about managing your application state.

  1. Using a fold/scan to change the state over time in your model. For more advanced example look at cyclejs/examples. Simple example shown below.

    // intent
    const add$ = sources.DOM.select('.add').events('click').mapTo(1)
    const minus$ = sources.DOM.select('.minus').events('click').mapTo(-1)
    const action$ = xs.merge(add$, minus$)
    
    // model
    const state$ = action$.fold((x, y) => x + y, 0)
  2. Using stanga but does not adhere to the CycleJS philosophy

How do we recover from errors? (e.g from HTTPSource)

Look at this issue for more info.

How to integration of third party components (from JQuery and the like)?

Usually the answer is to use snabbdom hooks. If the component provides callbacks of interest, emit custom events on the vnode.elm from within the callbacks. Custom events can have any name, and can be caught through domSource.select().events().

Have a look at cyclejs-sortable for examples for custom event use and look at this issue for more info.

Clone this wiki locally