Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahmutov/draw-cycle
Simple Cycle.js application visualized: streams, events, DOM
https://github.com/bahmutov/draw-cycle
Last synced: about 1 month ago
JSON representation
Simple Cycle.js application visualized: streams, events, DOM
- Host: GitHub
- URL: https://github.com/bahmutov/draw-cycle
- Owner: bahmutov
- Created: 2016-01-24T22:55:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-09T13:32:08.000Z (about 8 years ago)
- Last Synced: 2024-08-03T10:22:14.035Z (3 months ago)
- Language: HTML
- Homepage: https://glebbahmutov.com/draw-cycle/
- Size: 1.02 MB
- Stars: 147
- Watchers: 4
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-reactive-programming - Draw Cycle
README
# draw-cycle
> Simple Cycle.js application visualized: streams, events, DOMTry yourself at [glebbahmutov.com/draw-cycle](https://glebbahmutov.com/draw-cycle/)
![demo.gif](demo.gif)
Full video in original resolution at [https://youtu.be/-5-xyhd5fbQ](https://youtu.be/-5-xyhd5fbQ)
Simple Cycle.js taken from "Explicit dataflow" section at
[http://cycle.js.org/](http://cycle.js.org/) - here is the application's code```js
function main(sources) {
const decrement$ = sources.DOM
.select('.decrement').events('click').map(ev => -1);const increment$ = sources.DOM
.select('.increment').events('click').map(ev => +1);const action$ = Observable.merge(decrement$, increment$);
const count$ = action$.startWith(0).scan((x,y) => x+y);const vtree$ = count$.map(count =>
div([
button('.decrement', 'Decrement'),
button('.increment', 'Increment'),
p('Counter: ' + count)
])
);
return { DOM: vtree$ };
}
```Visualization drawn using [Raphael.js](http://raphaeljs.com/)
### Small print
Author: Gleb Bahmutov © 2016
* [@bahmutov](https://twitter.com/bahmutov)
* [glebbahmutov.com](http://glebbahmutov.com)
* [blog](http://glebbahmutov.com/blog/)License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, etc.
Support: if you find any problems with this module, email / tweet /
[open issue](https://github.com/bahmutov/draw-cycle/issues) on Github## MIT License
Copyright (c) 2016 Gleb Bahmutov
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.