k-mst-onaction
k-mst-onaction copied to clipboard
Take API : use a curryfied function with multiple filters
Refactor take :
- [ ] to be "currified":
take(filter)(reaction)
- [ ] to accept multiple params as AND:
take(filter1, andFilter2)(reaction)
- [ ] to write OR we will use as many take as OR or use filter parameter as a fonction
Add a new function takeWith
wich flips the parameters of take
: takeWhile(reaction)(filter)
// todos.js
import { takeWith } from 'k-simple-state'
export const completeWhen = takeWith(action, store) => {
const { todos } = store.data
const todo = todos.get(action.payload)
todos.set({ ...todos, completed: true })
}
// listeners.js
import { take } from 'k-simple-state'
import { completeWhen } from './todos'
export default [
completeWhen('/action/full/path'),
completeWhen('/action2/full/path'),
take('/action3/full/path/')((action, tree) => /* do something */),
take(
'/action4/full/path/',
({ args : [x, y] }) => x > y
)((action, tree) => /* do something */)
]