Skip to content

Instantly share code, notes, and snippets.

@khle
Last active February 3, 2016 12:03
Show Gist options
  • Select an option

  • Save khle/656c8518ea3871a0bc66 to your computer and use it in GitHub Desktop.

Select an option

Save khle/656c8518ea3871a0bc66 to your computer and use it in GitHub Desktop.
main.js
...
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