Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Avoiding the usage of state

With regard to the usage of the global state—both getting and setting it—the solution is well known. The key points to this are as follows:

  • Provide whatever is needed of the global state to the function as arguments.
  • If the function needs to update the state, it shouldn't do it directly, but rather produce a new version of the state and return it.
  • It should be the responsibility of the caller to take the returned state, if any, and update the global state.

This is the technique that Redux uses for its reducers. The signature for a reducer is (previousState, action) => newState, meaning that it takes a state and an action as parameters and returns a new state as the result. Most specifically, the reducer is not ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content