Skip to content

Instantly share code, notes, and snippets.

@ihgrant
Last active November 11, 2016 01:01
Show Gist options
  • Save ihgrant/45f3fa9e89a8df721ceaf31850cc4534 to your computer and use it in GitHub Desktop.
Save ihgrant/45f3fa9e89a8df721ceaf31850cc4534 to your computer and use it in GitHub Desktop.
simple application state singleton
import App from './App';
import './index.css';
import {render} from './statemachine';
render(
App,
{},
document.getElementById('root')
);
import React from 'react';
import ReactDOM from 'react-dom';
let _App;
let _props;
let _target;
// the shape of your application state
let _state = {counter: 0};
function _render() {
ReactDOM.render(React.createElement(_App, {..._props, ..._state}), _target);
}
function add() {
_state = Object.assign({}, _state, {counter: _state.counter + 1});
_render();
};
function render(App, props, target) {
_App = App;
_props = props;
_target = target;
_render();
}
export {add, render}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment