drcmda / react-contextual

🚀 react-contextual is a small (less than 1KB) helper around React 16s new context api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having a selectors property

GonzaloRizzo opened this issue · 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()

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.

commented

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. :(