Created
May 15, 2016 10:06
-
-
Save mattiamanzati/cd495e720b05c553c9bdd356b8cd6799 to your computer and use it in GitHub Desktop.
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 {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