Skip to content

Instantly share code, notes, and snippets.

@griffinmichl
Created April 15, 2016 20:51
Show Gist options
  • Save griffinmichl/db6df261cee77be49145688869c6a684 to your computer and use it in GitHub Desktop.
Save griffinmichl/db6df261cee77be49145688869c6a684 to your computer and use it in GitHub Desktop.
A saved Tricycle Program
const Cycle = require('@cycle/core');
const {makeDOMDriver, div, button} = require('@cycle/dom');
const _ = require('lodash');
const {Observable} = require('rx');
const {restartable} = require('cycle-restart');
function main ({DOM}) {
const add$ = DOM
.select('.add')
.events('click')
.map(ev => 1);
const count$ = add$
.startWith(0)
.scan((total, change) => total + change)
return {
DOM: count$.map(count =>
div('.counter', [
'Count: ' + count,
button('.add', 'Add')
])
)
};
}
// This looks a little different than normal. It's to enable support for cycle-restart,
// which automatically plays back your actions when the code reloads.
// See https://github.com/Widdershin/cycle-restart for more info
const sources = {
DOM: restartable(makeDOMDriver('.app'), {pauseSinksWhileReplaying: false})
}
// Normally you need to call Cycle.run, but Tricycle handles that for you!
// If you want to try this out locally, just uncomment this code.
//
// Cycle.run(main, sources);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment