git ssb

1+

Matt McKegg / mutant



Commit 8e28bf396920836c01fd56e791f641c8a34675bb

readme: tidy up examples, doc tweaks

Matt McKegg authored on 6/20/2017, 12:43:40 AM
GitHub committed on 6/20/2017, 12:43:40 AM
Parent: 4cecb64c5bfaa7e58358ce77e0af0153d7f224a2

Files changed

README.mdchanged
README.mdView
@@ -110,12 +110,14 @@
110110
111111 ``` js
112112 var Value = require('mutant/value')
113113
114-var v = Value()
115-v.set(true)
114 +var obs = Value()
115 +obs.set(true)
116116 //set listener
117-v(function (_v) { ... })
117 +obs(value => {
118 + // called with resolved value whenever the observable changes
119 +})
118120 ```
119121
120122 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)
121123
@@ -174,8 +176,10 @@
174176 ### Struct
175177
176178 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.
177179
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 +
178182 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.
179183
180184 They accept a set list of keys that specify types. For example:
181185
@@ -188,11 +192,13 @@
188192 attrs: MutantDict()
189193 })
190194 ```
191195
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.
193197
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).
194199
200 +
195201 ### MappedArray
196202
197203 ...
198204

Built with git-ssb-web