Last active
September 22, 2016 21:03
-
-
Save milankinen/720d965f9c524915504e35339f0b2a13 to your computer and use it in GitHub Desktop.
Reduxish Stanga
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 {Observable as O} from "rx" | |
const store = reducer => R.lens(R.identity, reducer) | |
const myStore = store((action, state) => { | |
switch (action.type) { | |
case "INC": return state + 1 | |
case "DEC": return state - 1 | |
default: return state | |
} | |
}) | |
function main({DOM, M}) { | |
const state = M.lens(myStore) | |
const actions = O.merge( | |
DOM.select(".inc").events("click").map(() => ({type: "INC"})), | |
DOM.select(".dec").events("click").map(() => ({type: "DEC"})) | |
) | |
const vdom = state.map(counter => h("div", [ | |
h("h1", `Counter value is ${counter}`), | |
h("button.inc", "++"), | |
h("button.dec", "--") | |
])) | |
return { | |
DOM: vdom, | |
M: M.set(actions) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment