Last active
December 15, 2017 17:07
-
-
Save gemmadlou/73659957dd1c943c3a9d06e12faa2f67 to your computer and use it in GitHub Desktop.
Frameworkless
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
| console.clear(); | |
| type model = { | |
| input: { | |
| type: 'text', | |
| class: 'someclass' | |
| }, | |
| output: '' | |
| } | |
| let start = (): model => { | |
| return { | |
| input: { | |
| type: 'text', | |
| class: 'someclass' | |
| }, | |
| output: '' | |
| } | |
| } | |
| let inputted = (state: model, value: string): model => { | |
| let clone = Object.assign({}, state); | |
| clone.output = value; | |
| return clone; | |
| } | |
| let view = (state: model) => { | |
| return '<input type="text" value="' + state.output + '" onkeyup="submitEvent(event, \'updateInput\')" /> ' + state.output | |
| } | |
| let resetCursor = (el, val) => { | |
| el.value = ''; | |
| el.value = val; | |
| el.focus(); | |
| } | |
| window.submitEvent = (e, action) => { | |
| if (action === 'updateInput' && !e.ctrlKey && e.key !== "Control") { | |
| app.innerHTML = view(inputted(state, e.target.value)); | |
| let input = app.querySelector('input') | |
| resetCursor(input, e.target.value) | |
| } | |
| } | |
| let app = document.querySelector('#app'); | |
| let state = start(); | |
| app.innerHTML = view(state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment