Skip to content

Instantly share code, notes, and snippets.

@bjoerge
Last active April 9, 2018 12:46
Show Gist options
  • Save bjoerge/d8c53d5480759a386bcfd6ee4187b176 to your computer and use it in GitHub Desktop.
Save bjoerge/d8c53d5480759a386bcfd6ee4187b176 to your computer and use it in GitHub Desktop.
stateContainer.js
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