A Pen by Eduardo Gonçalves on CodePen.
Created
June 29, 2017 16:39
-
-
Save anonymous/4f7f21baac7107345737b09cdccddf1d to your computer and use it in GitHub Desktop.
hyperapp todo app demo
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 {app, h} = hyperapp | |
| /** @jsx h */ | |
| const state = { | |
| in: '', | |
| components: [] | |
| } | |
| const mainView = (state, actions) => ( | |
| <main> | |
| <form onsubmit={actions.add}> | |
| <input id="in" type="text" onkeyup={actions.updateIn}></input> | |
| <input type="button" value="Add to the list" onclick={actions.add}></input> | |
| </form> | |
| {state.components.map((element, index) => ( | |
| <h1 onclick={(e) => actions.remove(index, e)}>{element}</h1> | |
| ))} | |
| </main> | |
| ) | |
| app({ | |
| state: state, | |
| view: mainView, | |
| actions: { | |
| updateIn: (state, actions, {target}) => { | |
| state.in = target.value | |
| return state | |
| }, | |
| add: (state, actions, e) => { | |
| e.preventDefault() | |
| document.getElementById('in').value = '' | |
| if (state.in != '') state.components.push(state.in.trim()) | |
| state.in = '' | |
| return state | |
| }, | |
| remove: (state, actions, index, e) => { | |
| state.components.splice(index, 1) | |
| 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
| <script src="https://unpkg.com/hyperapp"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment