Created
September 20, 2016 04:14
-
-
Save TheSeamau5/3e17160aa63ed122c55bdcb6f7ece01c to your computer and use it in GitHub Desktop.
Runner that takes an update and a render function and runs an app (optionally takes an observable)
This file contains hidden or 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, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { createStore } from 'redux'; | |
import Rx from 'rx'; | |
// run : (update: s -> a -> s, render: s -> Dispatcher a -> Html, observable: Observable a, root: String) | |
export const run = (update, render, observable, root='root') => { | |
const store = createStore(update); | |
const renderApp = () => { | |
ReactDOM.render( | |
render(store.getState(), store.dispatch), | |
document.getElementById(root) | |
); | |
}; | |
renderApp(); | |
if (observable) { | |
observable.subscribe(store.dispatch) | |
} | |
store.subscribe(renderApp); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment