createApi
createApi
is a shorthand for creating events attached to store by providing object with reducers for them. If source store
belongs to some domain then new events will also belong to it
Formulae
createApi(store, api): objectWithEvents
Arguments
Returns
(Object
) Object with events
Example
import {createStore, createApi} from 'effector'
const $playerPosition = createStore(0)
// create events and attach them to store
const api = createApi($playerPosition, {
moveLeft: (pos, offset) => pos - offset,
moveRight: (pos, offset) => pos + offset,
})
$playerPosition.watch(pos => {
console.log('position', pos)
})
// => position 0
api.moveRight(10)
// => position 10
api.moveLeft(5)
// => position 5