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
| <input type="text" oninput={ e => send({type: 'updateInputValue', value: e.target.value})} /> |
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
| { | |
| type: 'newValue', | |
| value: 'This is the new value!' | |
| } |
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
| view(state, send) { | |
| return render(<List {...{ state, send }}/>, '#app') | |
| } |
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
| function List({ state, send }) { | |
| return ( | |
| <div class="list-container"> | |
| <p> | |
| <input type="text" /> | |
| <button class="add-item">Add</button> | |
| </p> | |
| <ul class="list"> | |
| { | |
| state.fruits.map(item => <li key={item.key}> |
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
| init() { | |
| // Return state to use in program: | |
| return state | |
| } |
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
| init() { | |
| // always return state: | |
| return state | |
| } |
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 state = { | |
| newKey: 104, | |
| inputValue: '', | |
| fruits: [ | |
| { | |
| key: 101, | |
| value: 'Apples' | |
| }, | |
| { | |
| key: 102, |
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
| run(program) |
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 program = { | |
| init() { | |
| }, | |
| view(state, send) { | |
| }, | |
| update(state, msg) { | |
| }, |
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
| // Counter for view: | |
| function Counter({state, send}) { | |
| return ( | |
| <p> | |
| <button onclick={() => history.go(0)} id='reload-btn'>Restart</button> | |
| <button class='counter' onclick={() => send()}>{state}</button> | |
| </p> | |
| ) | |
| } |