Created
April 15, 2016 20:25
-
-
Save griffinmichl/fd29fb8d551e2919f43a1f6cb88f6ec8 to your computer and use it in GitHub Desktop.
A saved Tricycle Program
This file contains 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
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