How to use the effector.forward function in effector

To help you get started, we’ve selected a few effector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zerobias / effector / src / redux / index.js View on Github external
}) {
  let currentReducer = reducer

  const dispatch = createEvent<{+type: string, payload?: any, ...}>('dispatch')
  const update = createEvent('update')
  const store = createStore(defaultState)
  store.on(dispatch, (state, event) => {
    try {
      return currentReducer(state, event)
    } catch (err) {
      console.error(err)
    }
    return state
  })

  forward({
    from: store,
    to: update,
  })
  const wrapper = {}
  //$off
  wrapper[$$observable] = store[$$observable]
  wrapper.getState = store.getState
  wrapper.dispatch = dispatch
  /**
   * NOTE that's mean that symbol.observable subscribers
   * will always been called before ones which used .subscribe
   */
  wrapper.subscribe = (listener: (data: T) => any) => {
    if (typeof listener !== 'function') {
      throw new Error('Expected the listener to be a function.')
    }
github tanyaisinmybed / effector-undo / src / index.ts View on Github external
const current = history.map(({ states, head }) => states[head]);

  const shouldSave = createStore({
    next: initialState,
    prev: initialState
  })
    .on(store, ({ next: prev }, next) => ({ next, prev }))
    .map(({ next, prev }) => filter(next, prev));

  guard({
    source: sample(store, merge(events)),
    filter: shouldSave,
    target: push
  });

  forward({
    from: current,
    to: store
  });

  return { undo, redo, clear, history };
}