Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take API : use a curryfied function with multiple filters #17

Open
3 tasks
EmrysMyrddin opened this issue Jan 24, 2018 · 2 comments
Open
3 tasks

Take API : use a curryfied function with multiple filters #17

EmrysMyrddin opened this issue Jan 24, 2018 · 2 comments

Comments

@EmrysMyrddin
Copy link
Collaborator

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 */) 
]
@EmrysMyrddin
Copy link
Collaborator Author

Inspired from unirakun/k-ramel#26

@fabienjuif
Copy link
Member

and unirakun/k-ramel#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants