September 2017
Intermediate to advanced
216 pages
6h 8m
English
When the caller attempts to call a behavior that doesn't exist by passing a key that doesn't exist in the behavior map, you should be able to recover from this. Thankfully, the get() method accepts a second argument that's returned if the requested key doesn't exist:
const myBehavior = action => Map.of( true, () => console.log('thruth'), false, () => console.log('lies')).get( action, () => console.log('default'))();myBehavior(true);// -> truthmyBehavior(false);// -> liesmyBehavior();// -> defaultmyBehavior(123);// -> default
The last two calls to myBehavior() result in the default behavior running because neither call is passed a key that exists. This means that the second value passed to get() is returned, which ...
Read now
Unlock full access