Skip to content

Instantly share code, notes, and snippets.

@mattiamanzati
Created May 15, 2016 10:06
Show Gist options
  • Save mattiamanzati/cd495e720b05c553c9bdd356b8cd6799 to your computer and use it in GitHub Desktop.
Save mattiamanzati/cd495e720b05c553c9bdd356b8cd6799 to your computer and use it in GitHub Desktop.
import {Observable, Subject} from 'rxjs';
export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
interface Model{
value: number
}
interface Intent{
type: string
}
interface ISinks{
}
export function intent(resources: ISinks){
// resources.DOM.select magic to call INCREMENT and DECREMENT
}
export function model(intent$: Observable<Intent>): Observable<Model>{
const valueStream$ = intent$
.map(intent => {
if(intent.type == INCREMENT){
return 1;
}else if(intent.type == DECREMENT){
return -1
}
return 0;
})
.reduce((x, y) => x + y, 0);
return Observable.combineLatest(
valueStream$,
(valueStream$) => ({
value: valueStream$
})
);
}
export function view(model$: Observable<Model>): ISinks{
return {
DOM: model$
.map(({value}) => 'Hey! value is ' + value)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment