August 2017
Beginner
374 pages
10h 41m
English
For action parsing, ES2015 syntax comes in handy. We can easily and declaratively parse an object using destructuring.
We can manually pull out properties from the action object, as follows:
case CREATE_POST: { const type = action.type ...}
Instead of that, we can use destructuring, which would make the code look like this:
case CREATE_POST: { const { type } = action ...}
It is a bit like pattern matching in other languages—you specify what the object looks like after var/let/const, and it gets parsed/destructured into that form.
In combination with destructuring, you can also use default assignments, as follows:
const { type, user = 'anon' } = action// instead ofconst ...Read now
Unlock full access