This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hasOwnProperty = Object.prototype.hasOwnProperty | |
| /** | |
| * Create a union of string tags. | |
| * @param {string[]} types | |
| */ | |
| function createUnion(types) { | |
| const variants = Object.create(null) | |
| let checkTag = x => x && x.type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "compilerOptions": { | |
| "checkJs": true | |
| }, | |
| "exclude": [ | |
| "node_modules", | |
| "**/node_modules/*" | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subscriptions(state, send) { | |
| return () => { | |
| document.addEventListener('keypress', function (e) { | |
| if (e.keyCode === 13) { | |
| send({ type: 'addItem' }) | |
| } | |
| }) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| udate(state, message) { | |
| // Create clone of state with destructing: | |
| const prevState = {...state} | |
| // Pass cloned state to actions: | |
| return actions(prevState, message) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // actions gets two arguments: state and the message we send | |
| function actions(state, message) { | |
| switch(message) { | |
| case 'updateInputValue': | |
| // Update state with new value: | |
| state.inputValue = message.value | |
| // Don't forget to return state: | |
| return state | |
| case 'addItem': | |
| // Add new item to array: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <li key={item.key}> | |
| <span>{item.value}</span> | |
| <button class="delete-item" onclick={() => send({type: 'deleteItem', value: item.key})}>X</button> | |
| </li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // actions gets two arguments: state and the message we send | |
| function actions(state, message) { | |
| switch(message) { | |
| case 'updateInputValue': | |
| // Update state with new value: | |
| state.inputValue = message.value | |
| // Don't forget to return state: | |
| return state | |
| case 'addItem': | |
| // Add new item to array: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <button class="add-item" onclick={() => send({type: 'addItem'})}>Add</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| update(state, message) { | |
| return actions(state, message) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // actions gets two arguments: state and the message we send | |
| function actions(state, message) { | |
| switch(message) { | |
| case 'updateInputValue': | |
| // Update state with new value: | |
| state.inputValue = message.value | |
| // Don't forget to return state: | |
| return state | |
| } | |
| } |