Redux: Updating Data on the Server

Share this video with your friends

Send Tweet

We will learn how to wait until the item is updated on the server, and then update the corresponding local state.

mobility-team
mobility-team
~ 8 years ago

Great journey with Redux. Incredible work you did there! Thanks Dan!

Trace Harris
Trace Harris
~ 8 years ago

I am a little confused by the implementation of

return shouldRemove ? state.filter(id => id !== toggledId) : state

in the handleToggle function

is filter referencing filter that was params prop passed by withRouter? or is it just a method on that is being used on the state object? that you passed as an argument in the handleToggle function?

Kevin Pinny
Kevin Pinny
~ 7 years ago

Great Stuff, Dan. You started losing me around lesson 19, I'm gonna read the community notes starting from those lessons to properly understand it. Thanks!

Enoh Barbu
Enoh Barbu
~ 7 years ago

if you want your todo to be visible immediately after switching from completed to active, or vice-versa, use this:

return shouldRemove? state.filter( id => id !== toggledID ) : ( filter === 'all' ? state : [...state, toggledID] );

Enoh Barbu
Enoh Barbu
~ 7 years ago

if you want your todo to be visible immediately after switching from completed to active, or vice-versa, use this:

return shouldRemove? state.filter( id => id !== toggledID ) : ( filter === 'all' ? state : [...state, toggledID] );

Enoh Barbu
Enoh Barbu
~ 7 years ago
Enoh Barbu
Enoh Barbu
~ 7 years ago
J. Matthew
J. Matthew
~ 5 years ago

is filter referencing filter that was params prop passed by withRouter? or is it just a method on that is being used on the state object? that you passed as an argument in the handleToggle function?

@Trace It's understandable to be confused by this, given the heavy use of the term filter throughout the code. In almost every instance, filter is a variable, referring either to the param passed by withRouter, as you said, or the specific filter value passed as an argument to createList.

In this case though, filter doesn't refer to either of those, but rather is a method being called on the state object passed as an argument to handleToggle, again as you said. Note that handleToggle is called inside the ids reducer, which has this signature: const ids = (state = [], action) =>. This tells us that state in this case is an array. That same state is passed to handleToggle. So when handleToggle runs this code: state.filter(id => id !== toggledId), it's using the Array.filter method. That method returns a subset of the array, made up of all elements that pass the test provided to filter. In this case, that's all the IDs that don't match the toggled one.