Skip to content

Instantly share code, notes, and snippets.

View yelouafi's full-sized avatar

Yassine Elouafi yelouafi

View GitHub Profile
function view(count, handler) {
return h('div', [
h('button', {
on : { click: handler.bind(null, Action.Increment()) }
}, '+'),
h('button', {
on : { click: handler.bind(null, Action.Decrement()) }
}, '-'),
h('div', `Count : ${count}`),
]);
function update(count, action) {
return Action.case({
Increment : () => count + 1,
Decrement : () => count - 1
}, action);
}
const Action = Type({
Add : [],
Remove : [Number],
Reset : [],
Update : [Number, counter.Action],
});
function update(model, action) {
return Action.case({
Add : () => addCounter(model),
Remove : id => removeCounter(model, id),
Reset : () => resetCounters(model),
Update : (id, action) => updateCounter(model, id, action)
}, action);
}
function init() {
return 0;
}
function init() {
return { first: counter.init(), second: counter.init() };
}
function update(model, action) {
return action.type === RESET ?
{
first : counter.init(),
second: counter.init()
}
: action.type === UPDATE_FIRST ?
{...model, first : counter.update(model.first, action.data) }
main(
twoCounters.init(), // the initial state
document.getElementById('placeholder'),
twoCounters
);
function init() {
return { nextID: 1, counters: [] };
}
/** @jsx html */
import { html } from 'snabbdom-jsx';
import Type from 'union-type';
const Action = Type({
Increment : [],
Decrement : [],
});