Last active
November 11, 2016 01:01
-
-
Save ihgrant/45f3fa9e89a8df721ceaf31850cc4534 to your computer and use it in GitHub Desktop.
simple application state singleton
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 App from './App'; | |
import './index.css'; | |
import {render} from './statemachine'; | |
render( | |
App, | |
{}, | |
document.getElementById('root') | |
); |
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 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