File tree Expand file tree Collapse file tree 2 files changed +47
-7
lines changed
packages/cycle-scripts/template Expand file tree Collapse file tree 2 files changed +47
-7
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,25 @@ module.exports = {
22 xstream : {
33 run : '@cycle/run' ,
44 import : 'import xs from \'xstream\'' ,
5- stream : 'xs'
5+ stream : 'xs' ,
6+ fold : 'fold' ,
7+ merge : 'xs.merge' ,
8+ mapTo : 'mapTo'
69 } ,
710 rxjs : {
811 run : '@cycle/rxjs-run' ,
912 import : 'import Rx from \'rxjs/Rx\'' ,
10- stream : 'Rx.Observable'
13+ stream : 'Rx.Observable' ,
14+ fold : 'scan' ,
15+ merge : 'Rx.Observable.merge' ,
16+ mapTo : 'mapTo'
1117 } ,
1218 most : {
1319 run : '@cycle/most-run' ,
1420 import : 'import * as most from \'most\'' ,
15- stream : 'most'
21+ stream : 'most' ,
22+ fold : 'scan' ,
23+ merge : 'most.merge' ,
24+ mapTo : 'constant'
1625 }
1726}
Original file line number Diff line number Diff line change 11module . exports = replacements => `${ replacements . import }
22
33export function App (sources) {
4- const vtree$ = ${ replacements . stream } .of(
5- <div>My Awesome Cycle.js app</div>
6- )
4+ const action$ = intent(sources.DOM)
5+ const model$ = model(action$)
6+ const vdom$ = view(model$)
7+
78 const sinks = {
8- DOM: vtree $
9+ DOM: vdom $
910 }
1011 return sinks
1112}
13+
14+ const initalState = { count: 0 }
15+
16+ function intent(DOM) {
17+ const add$ = DOM.select('.add').events('click')
18+ .${ replacements . mapTo } (prevState => ({ ...prevState, count: prevState.count + 1 }))
19+
20+ const subtract$ = DOM.select('.subtract').events('click')
21+ .${ replacements . mapTo } (prevState => ({ ...prevState, count: prevState.count - 1 }))
22+
23+ return ${ replacements . merge } (add$, subtract$)
24+ }
25+
26+ function model(action$) {
27+ return action$
28+ .${ replacements . fold } ((state, reducer) => reducer(state), initalState)
29+ }
30+
31+ function view(state$) {
32+ return state$
33+ .map(s => s.count)
34+ .map(count =>
35+ <div>
36+ <h2>My Awesome Cycle.js app</h2>
37+ <span>{ 'Counter: ' + count }</span>
38+ <button type='button' className='add'>Increase</button>
39+ <button type='button' className='subtract'>Decrease</button>
40+ </div>
41+ )
42+ }
1243`
You can’t perform that action at this time.
0 commit comments