@webkrafters/react-observable-context 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
|
|
25
25
|
<ul>
|
|
26
26
|
<li> Update-friendly context.</li>
|
|
27
|
-
<li> A context bearing an observable consumer
|
|
27
|
+
<li> A context bearing an observable consumer <a href="#store">store</a>.</li>
|
|
28
28
|
<li> Recognizes <b>negative array indexing</b>. Please see <a href="#property-path">Property Path</a> and <code>store.setState</code> <a href="#indexing">Indexing</a>.</li>
|
|
29
|
-
<li> Only re-renders subscribing components (
|
|
29
|
+
<li> Only re-renders subscribing components (<a href="#client">clients</a>) on context state changes.</li>
|
|
30
30
|
<li> Subscribing component decides which context state properties' changes to trigger its update.</li>
|
|
31
31
|
</ul>
|
|
32
32
|
|
|
@@ -437,25 +437,29 @@ The `React.Observable.Context` context `store` is the client's portal into the c
|
|
|
437
437
|
<span style="margin: 5px 10px 0 0">-</span>Performs no state reset when a client with no selector map invokes this method with 0 arguments.
|
|
438
438
|
|
|
439
439
|
<h3 id="store-setstate" style="margin-top:10px"><code>store.setState</code> Usage</h3>
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
:warning: <b><i>
|
|
444
|
-
:warning: <b><i>
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
440
|
+
|
|
441
|
+
<blockquote>[This store's] internal state is <u><b>immutable</b></u> and <u><b>private</b></u>.<br />Direct mutation attempts on its properties have no effect.</blockquote>
|
|
442
|
+
New updates are merged into state by default. So only supply the exact changes to be merged <b><i>(i.e. do not spread the new state changes into the current state as is commonly done in React development)</i></b>. And to overwrite a slice of state, use the <a href="#setstate-tags">tag</a> command.<br />
|
|
443
|
+
:warning: <b><i>Do this:</i></b> <code>setState({stateKey0: changes0});</code><br />
|
|
444
|
+
:warning: <b><i>Not this:</i></b> <code>setState({...state, stateKey0: {...state.stateKey0, ...changes0}});</code><br />
|
|
445
|
+
|
|
446
|
+
<h3 id="batched-update"><i><u>Batched update</u></i></h3>
|
|
447
|
+
provides a way to update the state as a transaction of several state changes. This can be achieved by collecting a series of state changes in an array and passing that array as an argument to the <code>store.setState</code> method. The state changes are resolved sequentially from <code>index 0</code> to the <code>last index</code>. <a href="#client">Clients</a> are only notified at batched update completion.<br />
|
|
448
|
+
:warning: <b><i>Do this:</i></b> <code>setState([<br />
|
|
449
|
+
{stateKey0: changes0},<br />
|
|
450
|
+
{stateKey1: changes1},<br />
|
|
451
|
+
// et cetera ... et cetera<br />
|
|
448
452
|
]);</code><br />
|
|
449
453
|
:warning: <b><i>Not this:</i></b> <code>setState([<br />
|
|
450
|
-
{stateKey0: {...state.stateKey0, ...changes0}
|
|
451
|
-
{stateKey1: {...state.stateKey1, ...changes1}
|
|
452
|
-
 
|
|
454
|
+
{...state, stateKey0: {...state.stateKey0, ...changes0}},<br />
|
|
455
|
+
{...state, stateKey1: {...state.stateKey1, ...changes1}},<br />
|
|
456
|
+
// et cetera ... et cetera<br />
|
|
453
457
|
]);</code>
|
|
454
458
|
|
|
455
|
-
<h3 id="indexing"><
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
+
<h3 id="indexing"><i><u>Indexing</u></i></h3>
|
|
460
|
+
Traditionally, array state properties are updated by a new array replacement. This overwrites the existing state property.<br />
|
|
461
|
+
Hence the need for <code>indexing</code>. Indexing provides a mechanism for updating array state properties at specific indexes using an indexed state change object.<br />
|
|
462
|
+
The store also recognizes and resolves negative indexes when present in the indexed state change object. See additional <a href="#neg-idx-tip">tip</a> below.<br />
|
|
459
463
|
<strong>Example:</strong>
|
|
460
464
|
|
|
461
465
|
```jsx
|
package/package.json
CHANGED