Skip to content

Commit

Permalink
feat(formula): add getStateBySelector
Browse files Browse the repository at this point in the history
making it able to pass param to the selector
  • Loading branch information
nampdn committed Nov 29, 2019
1 parent 8715929 commit a913390
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/formula/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ export const getState = withStore(
return formula(store.getState(), ...rest)
},
)

export const getStateBySelector = withStore(
(paramFormula: Formula, selector: (state: any) => any) => async (
_: any,
store: Store,
...rest: any[]
) => {
const param = await Promise.resolve(paramFormula(_, ...rest))
const state = store.getState()
return selector(param)(state)
},
)

0 comments on commit a913390

Please sign in to comment.