Created
February 18, 2017 15:52
-
-
Save melbourne2991/96ce15450736f6444cec796cfed9ed8f 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
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')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
f