import App from 'overmind/$VIEW'
const app = new App({
actions: action => ({
doThis: action()
.do((context, value) => {})
})
})The actions is defined with a callback receiving the applications action factory. The function is expected to return an object with actions.
Returns a new value to the chain.
export default action => ({
getEventValue: action()
.map((_, event) => event.target.value)
})export default action => ({
getPosts: action()
.map(({ api }) => api.getPosts())
})Change the state of the application. State changes are only allowed in this operator, which is why it only receives the state as the first argument, not the other providers.
export default action => ({
changeInputValue: action()
.mutation((state, value) => state.inputValue = value)
})Perform some side effect without returning a new value to the chain. Any returned value will be ignored.
export default action => ({
onClick: action()
.do(({ track }) => track.click('someClick'))
})If the action has not been called again within the number of milliseconds, continue execution.
export default action => ({
search: action()
.mutation((state, value) => state.searchInputValue = value)
.debounce(200)
.map(({ api}, value) => api.search(value)
})Fork execution into true and false actions based on an expression.
export default action => ({
openProfile: action()
.when(({ state }) => state.user.isLoggedIn, {
true: action(),
false: action()
})
})Fork execution into any number of actions. Note that fork does not return a new value to the chain.
export default action => ({
openAdmin: action()
.fork(({ state }) => state.user.role, {
admin: action(),
superuser: action(),
user: action()
})
})