@webkrafters/react-observable-context 4.1.0-rc.7 → 4.1.0-rc.8.1
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 +22 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,9 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
# React-Observable-Context [Eagle Eye]
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
<ul>
|
|
26
|
+
<li> A context bearing an observable consumer [store](#store).</li>
|
|
27
|
+
<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>
|
|
28
|
+
<li> Only re-renders subscribing components ([clients](#client)) on context state changes.</li>
|
|
29
|
+
<li> Subscribing component decides which context state properties' changes to trigger its update.</li>
|
|
30
|
+
</ul>
|
|
28
31
|
|
|
29
32
|
**Name:** React-Observable-Context
|
|
30
33
|
|
|
@@ -272,19 +275,21 @@ A client is any component consuming the observable context. A client consumes th
|
|
|
272
275
|
|
|
273
276
|
<h2 id="property-path">Property path</h2>
|
|
274
277
|
A property path is a dot-notation string leading to a specific property within an object.<br />
|
|
275
|
-
<code>React-Observable-Context</code> recognizes any property path abiding by the <b><i><u>Lodash</u></i></b> property path specifications.<br />
|
|
278
|
+
<code>React-Observable-Context</code> recognizes any property path abiding by the <b><i><u>Lodash</u></i></b> property path specifications. Such property paths may also contain negative integers.<br /><br />
|
|
276
279
|
|
|
277
|
-
<
|
|
280
|
+
<b>Negative</b> integer (<i>-N</i>) in a property path indicates an array index derived at runtime by counting `abs(-N)` steps backward from array length.<br />
|
|
281
|
+
|
|
282
|
+
<b id="property-path-example">Ex. Given the following object:</b>
|
|
278
283
|
|
|
279
284
|
```jsx
|
|
280
285
|
{ a: { c: { e: 5, f: [ 0, 2, 4 ] } } }
|
|
281
286
|
```
|
|
282
287
|
The property path `a.c.e` accesses the `e=5` property.<br />
|
|
283
|
-
Either of the property paths `a.c.f.1` and `a.c.f[
|
|
288
|
+
Either of the property paths `a.c.f.1`, `a.c.f.-2`, `a.c.f[1]` and `a.c.f[-2]` is a valid property path to access the `[1]=2` property.<br />
|
|
284
289
|
A special property path [@@STATE](#fullstate-selectorkey) may be used to access the full given object.<br />
|
|
285
290
|
|
|
286
291
|
<strong id="fullstate-selectorkey"><u>@@STATE</u></strong> is a special property path to access the full state object as a single slice.<br />
|
|
287
|
-
|
|
292
|
+
:warning: <b><i>Caution:</i></b> When this property path exists in a <a href="#selector-map">selector map</a>, any change in the state object results in an update of its <a href="#store"><code>store.data</code></a> and a subsequent render of its client(s).
|
|
288
293
|
|
|
289
294
|
## Provider
|
|
290
295
|
The Provider component is a property of the `React-Observable-Context` context object. As a `React.context` based provider, it accepts the customary `children` and `value` props. It also accepts **2** optional props: <a href="#prehooks"><code>prehooks</code></a> and <a href="#storage"><code>storage</code></a>.
|
|
@@ -378,6 +383,7 @@ The `React.Observable.Context` context `store` is the client's portal into the c
|
|
|
378
383
|
<h3 id="indexing"><b><i><u>Indexing</u></i></b></h3>
|
|
379
384
|
Existing array state property can be overridden with a new array.<br />
|
|
380
385
|
Use the indexed object to update array content at indexes.<br />
|
|
386
|
+
Indexed object recognizes negative indexing. See additional <a href="#neg-idx-tip">tip</a> below.<br />
|
|
381
387
|
<strong>Example:</strong>
|
|
382
388
|
|
|
383
389
|
```jsx
|
|
@@ -392,11 +398,16 @@ store.setState({ a: { b: [ { y: 30 }, 22 ] } });
|
|
|
392
398
|
store.setState({ a: { b: { 0: { y: 30 }, 1: 22 } } });
|
|
393
399
|
// updates the state to: { a: { b: [ { x: 7, y: 30, z: 9 }, 22 ] }, j: 10 };
|
|
394
400
|
|
|
395
|
-
// The
|
|
401
|
+
// The followinng will update the existing array at indexes.
|
|
402
|
+
store.setState({ a: { b: { '-1': { y: 30 }, 1: 22 } } });
|
|
403
|
+
// updates the state to: { a: { b: [ { x: 7, y: 30, z: 9 }, 22 ] }, j: 10 };
|
|
404
|
+
|
|
405
|
+
// The previous 2 statements are functionally equivalent to the following:
|
|
396
406
|
const [ first, second, ...rest ] = state.a.b;
|
|
397
407
|
store.setState({ ...state, a: { ...state.a, b: [ { ...first, y: 30 }, 22, ...rest ] } });
|
|
398
408
|
// Refrain from doing this, please!
|
|
399
409
|
```
|
|
410
|
+
:warning: <b id="neg-idx-tip"><i>Tip:</i></b> Negative indexing pointing at an out-of-bounds index is ignored.
|
|
400
411
|
|
|
401
412
|
<h3 id="setstate-tags"><b><i><u>Rewriting state using tag commands</u></i></b></h3>
|
|
402
413
|
By default, <code>store.setState</code> recursively merges new changes into current state.<br />
|
|
@@ -598,8 +609,9 @@ store.setState({
|
|
|
598
609
|
<thead><tr><th>v4.1.0</th></tr></thead>
|
|
599
610
|
<tbody>
|
|
600
611
|
<tr><td><b>1.</b></td><td>Added new setState <a href="#setstate-tags">tags</a> to facilitate state update operations.</td></tr>
|
|
601
|
-
<tr><td><b>2.</b></td><td>
|
|
602
|
-
<tr><td><b>3.</b></td><td>
|
|
612
|
+
<tr><td><b>2.</b></td><td>Added negative indexing capabilities.</td></tr>
|
|
613
|
+
<tr><td><b>3.</b></td><td>Exposing the store via its Context Provider <code>ref</code> attribute.</td></tr>
|
|
614
|
+
<tr><td><b>4.</b></td><td>Exporting crucial constants such as <b>@@STATE</b> and setState <a href="#setstate-tags">tags</a> such as <b>@@CLEAR</b>, <b>@@MOVE</b> etc.</td></tr>
|
|
603
615
|
</tbody>
|
|
604
616
|
<thead><tr><th>v4.0.0</th></tr></thead>
|
|
605
617
|
<tbody>
|
package/package.json
CHANGED