Skip to content

Instantly share code, notes, and snippets.

@milankinen milankinen/main.js
Last active Sep 22, 2016

Embed
What would you like to do?
Reduxish Stanga
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
You can’t perform that action at this time.