Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6793245

Browse files
committed
add various comment fixes
1 parentf9d75c1 commit6793245

File tree

5 files changed

+30
-51
lines changed

5 files changed

+30
-51
lines changed

‎src/components/TodoItem.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function model(props$, action$) {
3535
// If the list item has no data set it as empty and not completed.
3636
constsanitizedProps$=props$.startWith({title:'',completed:false});
3737
// THE EDITING STREAM
38-
// Createan editingstream thatconsists only of
39-
//actions related toediting.
38+
// Createastream thatemits booleans that represent the
39+
//"isediting" state.
4040
constediting$=Observable
4141
.merge(
4242
action$.filter(a=>a.type==='startEdit').map(()=>true),

‎src/components/Todos/index.js‎

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,28 @@ import serialize from './storage-sink';
88
importTodoItemfrom'../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.
1213
functionamendStateWithChildren(DOMSource){
13-
// For every todo item take `todosData`...
1414
returnfunction(todosData){
15-
// ...and return stream data as an object
1615
return{
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.
2420
list:todosData.list.map(data=>{
25-
//...we create an Observable forthe data item...
21+
//Turnthe data item into an Observable
2622
constprops$=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.
3124
consttodoItem=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.
3327
return{
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.
4031
todoItem:{
4132
DOM: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.
4533
action$: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`.
5845
functionTodos({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+
//supplytheapplication with initial state.
6350
constlocalStorage$=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.
7562
constactions=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.
7966
conststate$=model(actions,sourceTodosData$);
8067
// AMEND STATE WITH CHILDREN
81-
// The state is being amended with the children.
8268
constamendedState$=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

‎src/components/Todos/intent.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {ENTER_KEY, ESC_KEY} from '../../utils';
55
exportdefaultfunctionintent(DOM,hashchange,initialHash,itemAction$){
66
return{
77
// THE ROUTE STREAM
8-
//The streamoftheinitial hashis being concatenated with
9-
// thehashchange stream.
8+
//A streamthat providestheURL hashvalue whenever
9+
// theroute changes, starting with the initial hash value.
1010
changeRoute$:Observable.concat(
1111
initialHash.map(hash=>hash.replace('#','')),
1212
hashchange.map(ev=>ev.newURL.match(/\#[^\#]*$/)[0].replace('#',''))

‎src/components/Todos/model.js‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import{Observable}from'rx';
22

3-
// A helper functionto get filterfunction to filter the todo items
4-
//inthevirtual dome according to whichroutewe are on.
3+
// A helper functionthat provides filterfunctions
4+
//depending onthe routevalue.
55
functiongetFilterFn(route){
66
switch(route){
77
case'/active':return(task=>task.completed===false);
@@ -10,7 +10,9 @@ function getFilterFn(route) {
1010
}
1111
}
1212

13-
// A helper to search for the todo index.
13+
// This search function is used in the `makeModification$`
14+
// function below to retrieve the index of a todo in the todosList
15+
// in order to make a modification to the todo data.
1416
functionsearchTodoIndex(todosList,todoid){
1517
letpointerId;
1618
letindex;
@@ -31,7 +33,7 @@ function searchTodoIndex(todosList, todoid) {
3133
}
3234

3335
// MAKE MODIFICATION STREAM
34-
// A function that takes theintent on the todo list
36+
// A function that takes theactions on the todo list
3537
// and returns a stream of functions that expect todosData (the data model)
3638
// and return a modified version of the data.
3739
functionmakeModification$(actions){
@@ -111,17 +113,11 @@ function model(actions, sourceTodosData$) {
111113
constmodification$=makeModification$(actions);
112114

113115
// RETURN THE MODEL DATA
114-
// Take the initial localStorage data stream...
115116
returnsourceTodosData$
116-
// ...and concatenate it with the stream of modification
117-
// functions...
118117
.concat(modification$)
119-
// ...and apply every modification function on the
120-
// current todosData which is the "accumulater"
121-
// of this `.scan` function.
122118
.scan((todosData,modFn)=>modFn(todosData))
123-
//Always serve any subscriber the latest state that
124-
//was flowing through this Observable.
119+
//Make this a hot Observable with with
120+
//a replay buffer of one item.
125121
.shareReplay(1);
126122
}
127123

‎src/components/Todos/view.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ function renderHeader() {
1515
}
1616

1717
functionrenderMainSection(todosData){
18-
19-
console.log(todosData.filterFn.toString());
2018
letallCompleted=todosData.list.reduce((x,y)=>x&&y.completed,true);
2119
returnsection('.main',{
2220
style:{'display':todosData.list.length ?'' :'none'}
@@ -26,8 +24,7 @@ function renderMainSection(todosData) {
2624
checked:allCompleted
2725
}),
2826
ul('.todo-list',todosData.list
29-
// Apply filter function according to
30-
// route.
27+
// Apply the supplied filter function.
3128
.filter(todosData.filterFn)
3229
.map(data=>data.todoItem.DOM)
3330
)
@@ -76,7 +73,7 @@ function renderFooter(todosData) {
7673
// THE VIEW
7774
// This function expects the stream of todosData
7875
// from the model function and turns it into a
79-
// virtual DOM stream that is then ultimately returnedintot
76+
// virtual DOM stream that is then ultimately returnedinto
8077
// the DOM sink in the index.js.
8178
exportdefaultfunctionview(todos$){
8279
returntodos$.map(todos=>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp