Creating new episodes

When we create a new episode and add it to the list of episode maps, we're actually updating two pieces of state. We're updating the results state because this is where the episodes list is located. We're also updating the create state to reset the form field values back to empty strings:

document
.querySelector('form[name="create-episode"]')
.addEventListener('submit', (e) => {
e.preventDefault();
app(state => state
.updateIn(
['results', 'episodes'],
episodes => episodes.push(
Map(state.get('create').toJS())
)
)
.setIn(['create', 'title'], '')
.setIn(['create', 'director'], '')
.setIn(['create', 'date'], '')
);
});

Here we're chaining together several mutative methods that change the state of the application. First, we're adding the new episode based on the current create state. Then we can reset the create state so that the new episode values are removed from the form. As a result, the user sees an updated form and the new episode in the results list, assuming that it meets the current filter criteria.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.0.192