Skip to content

Instantly share code, notes, and snippets.

@ryardley
Created June 16, 2016 08:57
Show Gist options
  • Save ryardley/5b0eb6d2c11af07ab92d1b6b5600a507 to your computer and use it in GitHub Desktop.
Save ryardley/5b0eb6d2c11af07ab92d1b6b5600a507 to your computer and use it in GitHub Desktop.
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