The reducer function

We start with the action type INITIAL_LOAD:

export default function cards(state = [], action) {    switch (action.type) {    case INITIAL_LOAD:       return;

Here, we return the new data; notice we do not mutate our state. The second one is the ADD_CARD action:

case ADD_CARD:if (state.filter(card => card._id === > 0) {      return state; }   return [    ...state, {    _id:,    title: action.title,    task: action.task,    status: action.status   } ]

In our app, when we create a new card, we dispatch the ADD_CARD action, and at the same time, we listen for collection changes. Since we are changing the collection (adding a new card), we will dispatch the RECEIVE_CARD action. To prevent adding one item twice, we ...

Get Build Applications with Meteor now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.