Last active
April 9, 2018 12:46
-
-
Save bjoerge/d8c53d5480759a386bcfd6ee4187b176 to your computer and use it in GitHub Desktop.
stateContainer.js
This file contains 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 {Subject} from 'rx/Subject' | |
import {of} from 'rx/observable/of' | |
import {publishReplay, refCount, concat} from 'rxjs/observable' | |
function createState(initial) { | |
const onChange$ = new Subject() | |
function onChange(...args) { | |
onChange$.next(args) | |
} | |
onChange.state$ = of(initial).pipe( | |
concat(onChange$.asObservable()), | |
publishReplay(1), | |
refCount() | |
) | |
return onChange | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment