restore
restore(event, defaultState)
Creates a Store from Event.
It works like a shortcut for createStore(defaultState).on(event, (_, payload) => payload)
Arguments
event
EventdefaultState
(Payload)
Returns
Store: New store
Example
import {createEvent, restore} from 'effector'
const event = createEvent()const store = restore(event, 'default')
store.watch(state => console.log('state: ', state))// state: default
event('foo')// state: foo
restore(effect, defaultState)
Creates a Store from sucessful results of Effect.
It works like a shortcut for createStore(defaultState).on(effect.done, (_, {result}) => result)
Arguments
effect
EffectdefaultState
(Done)
Returns
Store: New store
Example
import {createEffect, restore} from 'effector'
const effect = createEffect({ handler: () => 'foo',})const store = restore(effect, 'default')
store.watch(state => console.log('state: ', state))// state: default
effect()// state: foo
restore(obj)
Creates an object with stores from object with values
Arguments
obj
(State)
Returns
Store: New store
Example
import {restore} from 'effector'
const {foo, bar} = restore({ foo: 'foo', bar: 0,})foo.watch(foo => { console.log('foo', foo)})// => foo 'foo'bar.watch(bar => { console.log('bar', bar)})// => bar 0