react-contextual icon indicating copy to clipboard operation
react-contextual copied to clipboard

Having a selectors property

Open GonzaloRizzo opened this issue 7 years ago • 2 comments

Maybe it would be good to declare selectors inside the definition of the store and pass them the store automatically, so we don't have to pass the store back when we call the selectors.

Something like this

createStore({
    list: [...],
    search: '',
    selectors: {
        getFilteredList: ({list, search}) => list.filter(e => e.includes(search))
    }
})

And then we could call it with

store.selectors.getFilteredList()

GonzaloRizzo avatar Jul 02 '18 04:07 GonzaloRizzo

And how about actions as well?

Currently we can define methods in the state, like:

const state = {
  count: 0,
  up: value => state => ({ ...state, count: state.count + value }),
}

But it's unfortunate that we cannot nest the methods in under an actions property, and the order of arguments value -> state is unfortunate, as it's the opposite of recompose withStateHandlers (state -> value).

Adding a special actions property could improve this.

smeijer avatar Aug 11 '18 16:08 smeijer

Would you be open to take over authorship? I got so swamped with professional work and personal work (on react-spring) that i couldn't find time any longer for proper maintenance. :(

drcmda avatar Aug 11 '18 19:08 drcmda