Created
June 16, 2016 08:57
-
-
Save ryardley/5b0eb6d2c11af07ab92d1b6b5600a507 to your computer and use it in GitHub Desktop.
Exploring redux alternatives
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 React, { PropTypes } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Observable, Subject } from 'rxjs/Rx'; | |
const stateEmitter = new Subject(); | |
const state$ = Observable.from(stateEmitter); | |
const sendEvent = (data) => () => { | |
stateEmitter.next({ | |
name: data | |
}); | |
}; | |
const Planner = (props) => { | |
const { name } = props; | |
return ( | |
<section> | |
<h1>{name}</h1> | |
<button onClick={sendEvent('Fred')}>Fred</button> | |
<button onClick={sendEvent('Harry')}>Harry</button> | |
<button onClick={sendEvent('Mary')}>Mary</button> | |
</section> | |
); | |
}; | |
Planner.propTypes = { | |
name: PropTypes.string | |
}; | |
export default function bootstrap(id) { | |
const container = document.getElementById(id); | |
state$.subscribe((state) => { | |
ReactDOM.render(<Planner {...state} />, container); | |
}); | |
stateEmitter.next({ | |
name: 'Fred' | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment