Skip to content

Instantly share code, notes, and snippets.

@melbourne2991
Created February 18, 2017 15:52
Show Gist options
  • Save melbourne2991/96ce15450736f6444cec796cfed9ed8f to your computer and use it in GitHub Desktop.
Save melbourne2991/96ce15450736f6444cec796cfed9ed8f to your computer and use it in GitHub Desktop.
const subject$ = new Rx.Subject();
const bindAction = (action) => (...args) => subject$.next(action(args));
const doSomething = () => ({ type: 'DO_SOMETHING' })
const doSomethingAsyncComplete = () => {
return {
type: 'DO_SOMETHING_COMPLETE'
}
}
const doSomethingAsync = bindAction(() => {
subject$.next(doSomething());
setTimeout(() => {
subject$.next(doSomethingAsyncComplete());
}, 500)
});
const App = (props) => <button onClick={doSomethingAsync}>App</button>
subject$
.startWith('boo')
.scan((state, action) => {
if(!action) return state;
return state
})
.subscribe((state) => {
console.log(state);
ReactDOM.render(<App/>, document.getElementById('mount'))
})
@abhik2415
Copy link

f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment