Skip to content

Instantly share code, notes, and snippets.

@ryardley
Created June 16, 2016 08:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Exploring redux alternatives
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