Skip to content

Instantly share code, notes, and snippets.

@milankinen
Last active September 22, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milankinen/720d965f9c524915504e35339f0b2a13 to your computer and use it in GitHub Desktop.
Save milankinen/720d965f9c524915504e35339f0b2a13 to your computer and use it in GitHub Desktop.
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