Last active
February 3, 2016 12:03
-
-
Save khle/656c8518ea3871a0bc66 to your computer and use it in GitHub Desktop.
main.js
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
| ... | |
| import {textEntryIntentWithEnterKeyPressed} from './textEntry.js'; | |
| import {textEntryIntentWithSendButtonClicked} from './textEntry.js'; | |
| function intentWithSendButtonClicked(DOMSource) { | |
| const {textStream$, buttonClick$} = textEntryIntentWithSendButtonClicked(DOMSource); | |
| return buttonClick$.withLatestFrom(textStream$, (buttonClick, textStream) => { | |
| return textStream; | |
| }); | |
| } | |
| function intentWithEnterKeyPressed(DOMSource) { | |
| const {textStream$, enterKeyPressed$} = textEntryIntentWithEnterKeyPressed(DOMSource); | |
| return enterKeyPressed$.withLatestFrom(textStream$, (enterKeyPressed, textStream) => { | |
| return textStream; | |
| }); | |
| } | |
| function intent(DOMSource) { | |
| return Observable.merge(intentWithSendButtonClicked(DOMSource), intentWithEnterKeyPressed(DOMSource)); | |
| } | |
| function model(textStream$) { | |
| return textStream$.map(t => { | |
| return { | |
| inputValue: t.value, | |
| inputTarget: t, | |
| } | |
| }); | |
| } | |
| function main(sources) { | |
| const textStream$ = intent(sources.DOM); | |
| const state$ = model(textStream$); | |
| const sink = { | |
| DOM: view(sources.DOM), | |
| EffectHttp: state$, | |
| } | |
| return sink; | |
| } | |
| function view(DOMSource) { | |
| //as shown previously | |
| } | |
| run(main, { | |
| DOM: makeDOMDriver('#app'), | |
| EffectHttp: function(state$) { | |
| state$.subscribe((state) => { | |
| console.log(state.inputValue); | |
| state.inputTarget.focus(); | |
| state.inputTarget.value = ''; | |
| }) | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment