You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/todomvc/readme.md
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,16 +61,32 @@ By comparing object's versions. For _immutable_ data, reference to the data itse
61
61
62
62
Every NestedTypes model and collection has `_changeToken` property, which contains empty object `{}` reassigned every time object is updated (and {} !== {}, they are separate objects allocated on heap). Inside of `shouldComponentUpdate`, we compare these version tokens for every model and collection listed in `props` with tokens used at last render. Thus, we're able to efficiently check whenever model or collection was changed since the last render.
63
63
64
-
It's works faster than any generic PureRenderMixin because we dynamically compile `shouldComponentUpdate` functions with _loops unrolled_, taking props list from component's `propTypes` (loops through hashes are very expensive, as well as `Object.keys` call).
64
+
It works faster than any generic PureRenderMixin because we dynamically compile `shouldComponentUpdate` functions with _loops unrolled_, taking props list from component's `propTypes` (loops through hashes are very expensive, as well as `Object.keys` call).
65
65
66
66
Why it's better than just deal with immutable data? Because we can have circular references, and premanent references to objects in data layer with no problems. Thus, you may safely pass nested models and collection around. As you most likely used to.
67
67
68
-
### But how unidirectional data flow can work?
68
+
### How unidirectional data flow can work?
69
69
70
70
Because our models and collections can be nested, and parents detects nested changes. So, when you put something complex to the top-level component state, the state (which itself is the model in our case) will notice any changes happend deep inside, and triggers UI update.
71
71
72
72
There's another example illustrating that, which is a bit simpler - [flux-comparison](https://github.com/Volicon/NestedReact/tree/master/examples/flux-comparison).
73
73
74
+
### What are that `props` and `state` in component definitions?
75
+
76
+
It's type specs. In its simplest form, it describe object's shape with pairs `name : Constructor`, or `name : <primitive value>`. Like this:
77
+
78
+
```javascript
79
+
state : {
80
+
s1 :String,
81
+
s2 :'asasa', // same as String.value( 'asasa' )
82
+
m : Model
83
+
}
84
+
```
85
+
86
+
`props` spec is being compiled to `propTypes`, while `state` spec is used to create [NestedTypes model](http://volicon.github.io/NestedTypes/#nested.model) which will serve instead of standard `this.state`.
87
+
88
+
Refer to [NestedTypes API Reference](http://volicon.github.io/NestedTypes/#attribute-types) for complete type annotation syntax.
89
+
74
90
### What does `editing : ToDo.from( '^props.todos' )` from `todolist.jsx` mean?
75
91
76
92
This is NestedTypes type annotation, which literally means "`editing` is the model of `ToDo` type which is taken from
0 commit comments