@@ -8,40 +8,28 @@ import serialize from './storage-sink';
88import TodoItem from '../TodoItem' ;
99
1010// AMEND STATE WITH CHILDREN
11- // This is a callback function for a map function used below.
11+ // This function creates the projection function
12+ // for the map function below.
1213function amendStateWithChildren ( DOMSource ) {
13- // For every todo item take `todosData`...
1414return function ( todosData ) {
15- // ...and return stream data as an object
1615return {
17- // Via the spread operator we copy all properties
18- // from todosData into the object we return minus
19- // the properties defined in the new object that have
20- // the same key as a property in todosData.
2116 ...todosData ,
22- // The list property is the only property we are amending.
23- // For every item in todosData...
17+ // The list property is the only one being amended.
18+ // We map over the array in the list property to
19+ // enhance them with the actual todo item data flow components.
2420list :todosData . list . map ( data => {
25- //...we create an Observable for the data item...
21+ //Turn the data item into an Observable
2622const props$ = Observable . just ( data ) ;
27- // ...and create a new todo item by passing the DOM stream and
28- // the new props stream to it. The isolate function creates a
29- // "scoped data flow component" out of every todo item.
30- // For more read the docs here: https://github.com/cyclejs/isolate.
23+ // Create scoped todo item data flow components.
3124const todoItem = isolate ( TodoItem ) ( { DOM :DOMSource , props$} ) ;
32- // Here we return the new amended array data for the list array.
25+
26+ // Return the new data item for the list property arrayj.
3327return {
34- // We copy the item data into the the returned object
35- // via the spread operator here...
3628 ...data ,
37- // ...and add a new property called todoItem which
38- // returns a todoItem DOM stream sink and a todo item
39- // action stream sink.
29+ // This is a new property containing the DOM- and action stream of
30+ // the todo item.
4031todoItem :{
4132DOM :todoItem . DOM ,
42- // The action stream for the todo item is enhanced with
43- // the id of the todo, in order to tell which item these actions
44- // are streaming from.
4533action$ :todoItem . action$ . map ( ev => ( { ...ev , id :data . id } ) )
4634}
4735} ;
@@ -50,16 +38,15 @@ function amendStateWithChildren(DOMSource) {
5038} ;
5139}
5240
53- // THE MAIN FUNCTION
54- // This is the implementation of the `main` function that gets passed to
55- // Cycle's `run` function.
41+ // THE TODOS FUNCTION
42+ // This is the Todos component which is being exported below.
5643// The sources that have been passed to `run` as well are immediately
5744// deconstructed into the variables `DOM`, `hashchange`, `initialHash` & `storage`.
5845function Todos ( { DOM , hashchange, initialHash, storage} ) {
5946// THE LOCALSTORAGE STREAM
6047// Here we create a localStorage stream that only streams
61- // the first value received from localStoragebecause we use
62- //the localStorage to "rehydrate" theapp whenever we launch or refresh it .
48+ // the first value received from localStoragein order to
49+ //supply theapplication with initial state .
6350const localStorage$ = storage . local . getItem ( 'todos-cycle' ) . take ( 1 ) ;
6451// THE INITIAL TODO DATA
6552// The `deserialize` function takes the serialized JSON stored in localStorage
@@ -74,11 +61,10 @@ function Todos({DOM, hashchange, initialHash, storage}) {
7461// streams that model the users intentions.
7562const actions = intent ( DOM , hashchange , initialHash , proxyItemAction$ ) ;
7663// THE MODEL (MVI PATTERN)
77- //Intent gets passed to the model function which transforms the data
64+ //Actions get passed to the model function which transforms the data
7865// coming through the intent streams and prepares the data for the view.
7966const state$ = model ( actions , sourceTodosData$ ) ;
8067// AMEND STATE WITH CHILDREN
81- // The state is being amended with the children.
8268const amendedState$ = state$ . map ( amendStateWithChildren ( DOM ) ) . shareReplay ( 1 ) ;
8369// A STREAM OF ALL ACTIONS ON ALL TODOS
8470// Each todo item has an action stream. All those action streams are being