September 2017
Intermediate to advanced
216 pages
6h 8m
English
Calling get() directly on a map in order to run the appropriate behaviors is unlikely. Instead, you can wrap the Map declaration and the get() function together into a function. Then you can call the function with the key that determines which behavior will run, as shown here:
const myBehavior = action => Map.of( 'first', () => console.log('first'), 'second', () => console.log('second'), 'third', () => console.log('third')).get(action)();
Now you can pass an action to myBehavior(), and the corresponding path is followed through the map:
myBehavior('first');// -> firstmyBehavior('second');// -> second
By calling myBehavior(), you're also calling the corresponding function from the map that's looked up by ...
Read now
Unlock full access