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 belong to it as well
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, n) => pos - n,
moveRight: (pos, n) => pos + n,
})
playerPosition.watch(pos => {
console.log('position', pos)
})
// => position 0
api.moveRight(10)
// => position 10
api.moveLeft(5)
// => position 5