Actions

1.Introduction:

  1. Action Creators are collections of methods that are called within views to send actions to the Dispatcher.
  2. Actions are the actual payloads that are delivered via the dispatcher.

    Lets create some action methods so that you can understand it better,

TodoActions.js

import dispatcher from "../dispatcher";  <---imports the dispatcher object 
                                             from dispatcher.js

export function createTodo(text) {   <---this function is called in view 
   dispatcher.dispatch({                 part so dont worry for now
    type: "CREATE_TODO",
    text,
  });
}

export function deleteTodo(id) {     <---this function is called in view 
    dispatcher.dispatch({                part so dont worry for now
    type: "DELETE_TODO",
    id,
  });
}


Here createTodo() & deleteTodo() creates a new actions .
These action uses dispatch() method of dispatcher to perform operations on store.