Redux Todo List example - how todos state get updated depends on visibility filter -
first of patient i'm new @ redux stuff.
i'm reading http://rackt.org/redux/docs/basics/exampletodolist.html
and in i've got gist don't understand
how todos state updated depends on visibility filter.
i mean, if click on ie show_completed,
the spa shows todo completed: true why ? , logic ? don't see :(
usually in normal script should sort of
if state.visibiltyfilter === show_completed filter state ...
thanks in advance.
if check under smart components, @ bottom of containers/app.js you'll see:
// filtering happens function selecttodos(todos, filter) { switch (filter) { case visibilityfilters.show_all: return todos case visibilityfilters.show_completed: return todos.filter(todo => todo.completed) case visibilityfilters.show_active: return todos.filter(todo => !todo.completed) } } // props want inject, given global state? // note: use https://github.com/faassen/reselect better performance. function select(state) { return { visibletodos: selecttodos(state.todos, state.visibilityfilter), visibilityfilter: state.visibilityfilter } } // wrap component inject dispatch , state export default connect(select)(app)
the filtering happens when connect component store. instead of storing filtered list in state specify particular component should filter todos store before pass them component props.
Comments
Post a Comment