Commit 8e28bf396920836c01fd56e791f641c8a34675bb
readme: tidy up examples, doc tweaks
Matt McKegg authored on 6/20/2017, 12:43:40 AMGitHub committed on 6/20/2017, 12:43:40 AM
Parent: 4cecb64c5bfaa7e58358ce77e0af0153d7f224a2
Files changed
README.md | changed |
README.md | ||
---|---|---|
@@ -110,12 +110,14 @@ | ||
110 | 110 … | |
111 | 111 … | ``` js |
112 | 112 … | var Value = require('mutant/value') |
113 | 113 … | |
114 | -var v = Value() | |
115 | -v.set(true) | |
114 … | +var obs = Value() | |
115 … | +obs.set(true) | |
116 | 116 … | //set listener |
117 | -v(function (_v) { ... }) | |
117 … | +obs(value => { | |
118 … | + // called with resolved value whenever the observable changes | |
119 … | +}) | |
118 | 120 … | ``` |
119 | 121 … | |
120 | 122 … | This is almost the same as [observable](https://github.com/dominictarr/observable) and [observ](https://github.com/raynos/observ). There's only a couple of small differences: you can specify a default value (fallback when null) and it will throw if you try and add a non-function as a listener (this one always got me) |
121 | 123 … | |
@@ -174,8 +176,10 @@ | ||
174 | 176 … | ### Struct |
175 | 177 … | |
176 | 178 … | Take a fixed set of observables (or values) and return a single observable of the observed values, which updates whenever the inner values update. Subobservables can by any observable type. |
177 | 179 … | |
180 … | +They also have a `set` function which can be used to push a json object into the nested observables. Any additional set keys will be preserved if you resolve it. | |
181 … | + | |
178 | 182 … | Mostly the same as [observ-struct](https://github.com/raynos/observ-struct) except that it always emits the same object (with the properties changed). This means it violates immutability, but the trade-off is less garbage collection. The rest of the mutant helpers can handle this case pretty well. |
179 | 183 … | |
180 | 184 … | They accept a set list of keys that specify types. For example: |
181 | 185 … | |
@@ -188,11 +192,13 @@ | ||
188 | 192 … | attrs: MutantDict() |
189 | 193 … | }) |
190 | 194 … | ``` |
191 | 195 … | |
192 | -You can use these as your primary state atoms. I often use them like classes, extending them with additional methods to help with a given role. Another nice side effect is they work great for serializing/deserializing state. You can call them with `JSON.stringify(struct())` to get their entire tree state, then call them again later with `struct.set(JSON.parse(data))` to put it back. This is how state and file persistence works in [Loop Drop](https://github.com/mmckegg/loop-drop-app). | |
196 … | +You can use these as your primary state atoms. I often use them like classes, extending them with additional methods to help with a given role. | |
193 | 197 … | |
198 … | +Another nice side effect is they work great for serializing/deserializing state. You can call them with `JSON.stringify(struct())` to get their entire tree state, then call them again later with `struct.set(JSON.parse(data))` to put it back. This is how state and file persistence works in [Loop Drop](https://github.com/mmckegg/loop-drop-app). | |
194 | 199 … | |
200 … | + | |
195 | 201 … | ### MappedArray |
196 | 202 … | |
197 | 203 … | ... |
198 | 204 … |
Built with git-ssb-web