Managing Asynchronicity in Redux
Why do I need a state management library?
Redux: What, Why, and How?
Asynchronicity in Javascript using Promises and Generators
Popular libraries for managing side effects
Redux-thunk
Redux-saga
in a single object tree. The store acts a single source of truth for the application. Actions The state is read-only and any mutation to the state can only be done by emitting actions. These objects define what happened and are used to send data from user interactions, API calls, etc. to the Redux store. • Action Creators: Functions that return action objects. Reducers These are pure functions that specify state of an application changes in response to an action sent to the store.
re-entered. Their context (variable bindings) will be saved across re-entrances. When combined with promises, provides a very powerful paradigm for asynchronous code. Async functions are based on top of this. - MDN Docs // Generator function function* checkInNotifier(name) { yield `Hello ${name}, Welcome to Delhi!` ; yield `Hey ${name}, Welcome to Mumbai!` ; yield `${name}, Welcome to Pune!` ; } // Usage const notifier = checkInNotifier("React"); console.log(notifier.next().value); // Hello React, Welcome to Delhi! console.log(notifier.next().value); // Hey React, Welcome to Mumbai! console.log(notifier.next().value); // React, Welcome to Pune! console.log(notifier.next().value); // undefined
function setMessage(message) { return { type: SET_MESSAGE, payload: message }; } store.dispatch(setMessage("This is an sync message ")); // With thunk middleware, you can do following function setMessageAsync (message) { return dispatch => { setTimeout(() => { dispatch(setMessage(message)); }, 1000); }; } store.dispatch(setMessageAsync ("This is an async message "));