JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.3/immutable.min.js"></script>
<script src="https://unpkg.com/staunch-store@1.0.2/dist/browser.js"></script>
<h1>Count: <span id="count">0</span></h1>
JavaScript
const elem = document.querySelector('#count');
// initial data
const initial = {count: 0};
// reducer
// using immutable.js update here to
// set next value based on previous
function reducer(state, action) {
return state.update('count', count => count + 1);
}
// create the store
const store = staunch.createStore(initial, reducer);
// subscribe to state updates
// and update the dom element with the new count
store.state$.subscribe(state => {
elem.textContent = state.get('count');
})
// dispatch an action every second
window.setInterval(function() {
store.dispatch({type: 'inc'});
}, 1000);