@webkrafters/react-observable-context 4.5.0-rc → 4.5.0-rc.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.
Files changed (2) hide show
  1. package/README.md +54 -34
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -484,101 +484,111 @@ To overwrite current state slices with new values, <b>7</b> tag commands have be
484
484
  <i id="clear-tag-usage"><b>@@CLEAR:</b> (takes no arguments)</i>
485
485
 
486
486
  ```jsx
487
+ import { CLEAR_TAG } from '@webkrafters/react-observable-context'; // CLEAR_TAG = "@@CLEAR"
488
+
487
489
  const state = {
488
490
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
489
491
  j: 10
490
492
  };
491
493
 
492
494
  /* empties the state; sets state = {} */
493
- store.setState( '@@CLEAR' ) // or store.setState({ '@@CLEAR': <anything> })
495
+ store.setState( CLEAR_TAG ) // or store.setState({ [ CLEAR_TAG ]: <anything> })
494
496
 
495
497
  /* empties the value at state.a.b; sets state.a.b = [] */
496
- store.setState({ a: { b: '@@CLEAR' } }) // or store.setState({ a: { b: { '@@CLEAR': <anything> } } })
498
+ store.setState({ a: { b: CLEAR_TAG } }) // or store.setState({ a: { b: { [ CLEAR_TAG ]: <anything> } } })
497
499
 
498
500
  /* empties the value at state.a.j; sets state.a.j = null */
499
- store.setState({ a: { j: '@@CLEAR' } }) // or store.setState({ a: { j: { '@@CLEAR': <anything> } } })
501
+ store.setState({ a: { j: CLEAR_TAG } }) // or store.setState({ a: { j: { [ CLEAR_TAG ]: <anything> } } })
500
502
 
501
503
  /* empties the value at state.a.b[ 0 ]; sets state.a.b = [{}] */
502
- store.setState({ a: { b: [ '@@CLEAR' ] } }) // or store.setState({ a: { b: [ { '@@CLEAR': <anything> } ] } })
504
+ store.setState({ a: { b: [ CLEAR_TAG ] } }) // or store.setState({ a: { b: [ { [ CLEAR_TAG ]: <anything> } ] } })
503
505
 
504
506
  /* empties the value at state.a.b[0]; sets state.a.b = [{}, state.a.b[1]] */
505
- store.setState({ a: { b: [ '@@CLEAR', state.a.b[1] ] } }) // or store.setState({ a: { b: [ { '@@CLEAR': <anything> }, state.a.b[1] ] } })
507
+ store.setState({ a: { b: [ CLEAR_TAG, state.a.b[1] ] } }) // or store.setState({ a: { b: [ { [ CLEAR_TAG ]: <anything> }, state.a.b[1] ] } })
506
508
 
507
509
  /* empties the value at state.a.b[0]; sets state.a.b = [{}, a.b[1]] using indexing (RECOMMENDED) */
508
- store.setState({ a: { b: { 0: '@@CLEAR' } } }) // or store.setState({ a: { b: { 0: { '@@CLEAR': <anything> } } } })
510
+ store.setState({ a: { b: { 0: CLEAR_TAG } } }) // or store.setState({ a: { b: { 0: { [ CLEAR_TAG ]: <anything> } } } })
509
511
  ```
510
512
 
511
513
  <i id="delete-tag-usage"><b>@@DELETE:</b> (takes an array argument listing property keys to delete)</i>
512
514
 
513
515
  ```jsx
516
+ import { DELETE_TAG } from '@webkrafters/react-observable-context'; // DELETE_TAG = "@@DELETE"
517
+
514
518
  const state = {
515
519
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
516
520
  j: 10
517
521
  };
518
522
 
519
- store.setState({ '@@DELETE': [ 'a' ] }) // removes state.a; sets state = {j: 10}
523
+ store.setState({ [ DELETE_TAG ]: [ 'a' ] }) // removes state.a; sets state = {j: 10}
520
524
 
521
- store.setState({ a: { '@@DELETE': [ 'b' ] } }) // removes state.a.b; sets state.a = {}
525
+ store.setState({ a: { [ DELETE_TAG ]: [ 'b' ] } }) // removes state.a.b; sets state.a = {}
522
526
 
523
527
  /* removes state.a.b[0]; leaving state.a.b = [{ x: 17, y: 18, z: 19 }] */
524
- store.setState({ a: { b: { '@@DELETE': [ 0 ] } } }) // or store.setState({ a: { b: { '@@DELETE': [ -2 ] } } })
528
+ store.setState({ a: { b: { [ DELETE_TAG ]: [ 0 ] } } }) // or store.setState({ a: { b: { [ DELETE_TAG ]: [ -2 ] } } })
525
529
 
526
530
  /* removes `x` and `z` properties from state.a.b[1]; sets state.a.b = [{ x: 7, y: 8, z: 9 }, {y: 18}] */
527
- store.setState({ a: { b: [ state.a.b[ 0 ], { '@@DELETE': [ 'x', 'z' ] } ] } })
531
+ store.setState({ a: { b: [ state.a.b[ 0 ], { [ DELETE_TAG ]: [ 'x', 'z' ] } ] } })
528
532
 
529
533
  /* removes `x` and `z` properties from state.a.b[1]; sets state.a.b = [{ x: 7, y: 8, z: 9 }, {y: 18}] using indexing (RECOMMENDED) */
530
- store.setState({ a: { b: { 1: { '@@DELETE': [ 'x', 'z' ] } } } })
534
+ store.setState({ a: { b: { 1: { [ DELETE_TAG ]: [ 'x', 'z' ] } } } })
531
535
  ```
532
536
 
533
537
  <i id="move-tag-usage"><b>@@MOVE:</b> (takes an array argument listing: -/+fromIndex, -/+toIndex and optional +numItems?. numItems = 1 by default)</i>
534
538
 
535
539
  ```jsx
540
+ import { MOVE_TAG } from '@webkrafters/react-observable-context'; // MOVE_TAG = "@@MOVE"
541
+
536
542
  const state = {
537
543
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
538
544
  j: 10,
539
545
  q: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
540
546
  };
541
547
 
542
- store.setState({ a: { '@@MOVE': [ 0, 1 ] } }) // assigning a '@@MOVE' command to a non-array property has no effect.
548
+ store.setState({ a: { [ MOVE_TAG ]: [ 0, 1 ] } }) // assigning a '@@MOVE' command to a non-array property has no effect.
543
549
 
544
550
  /* moves state.a.b[0] into index 1; leaving state.a.b = [{ x: 17, y: 18, z: 19 }, { x: 7, y: 8, z: 9 }] */
545
- store.setState({ a: { b: { '@@MOVE': [ 0, 1 ] } } }) // or store.setState({ a: { b: { '@@MOVE': [ -2, -1 ] } } })
551
+ store.setState({ a: { b: { [ MOVE_TAG ]: [ 0, 1 ] } } }) // or store.setState({ a: { b: { [ MOVE_TAG ]: [ -2, -1 ] } } })
546
552
 
547
553
  /* moves state.q[4] - [7] into indexes 1 - 4; leaving state.q = [ 1, 5, 6, 7, 8, 2, 3, 4, 9 ] */
548
- store.setState({ a: { q: { '@@MOVE': [ 4, 1, 4 ] } } }) // or store.setState({ a: { q: { '@@MOVE': [ -5, -8, 4 ] } } })
554
+ store.setState({ a: { q: { [ MOVE_TAG ]: [ 4, 1, 4 ] } } }) // or store.setState({ a: { q: { [ MOVE_TAG ]: [ -5, -8, 4 ] } } })
549
555
  ```
550
556
 
551
557
  <i id="push-tag-usage"><b>@@PUSH:</b> (takes an array argument listing new values to append)</i>
552
558
 
553
559
  ```jsx
560
+ import { PUSH_TAG } from '@webkrafters/react-observable-context'; // PUSH_TAG = "@@PUSH"
561
+
554
562
  const state = {
555
563
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
556
564
  j: 10
557
565
  };
558
566
 
559
- store.setState({ a: { '@@PUSH': [{ n: 5 }] } }) // assigning a '@@PUSH' command to a non-array property has no effect.
567
+ store.setState({ a: { [ PUSH_TAG ]: [{ n: 5 }] } }) // assigning a '@@PUSH' command to a non-array property has no effect.
560
568
 
561
569
  /* appends 2 new items into state.a.b; leaving state.a.b = [...state.a.b, { x: 27, y: 28, z: 29 }, { x: 37, y: 38, z: 39 }] */
562
- store.setState({ a: { b: { '@@PUSH': [{ x: 27, y: 28, z: 29 }, { x: 37, y: 38, z: 39 }] } } })
570
+ store.setState({ a: { b: { [ PUSH_TAG ]: [{ x: 27, y: 28, z: 29 }, { x: 37, y: 38, z: 39 }] } } })
563
571
  ```
564
572
 
565
573
  <i id="replace-tag-usage"><b>@@REPLACE:</b> (takes an argument holding the replacment value)</i>
566
574
 
567
575
  ```jsx
576
+ import { REPLACE_TAG } from '@webkrafters/react-observable-context'; // REPLACE_TAG = "@@REPLACE"
577
+
568
578
  const state = {
569
579
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
570
580
  j: 10
571
581
  };
572
582
 
573
- store.setState({ '@@REPLACE': { a: 'Demo', j: 17 } }) // rewrites state to { a: 'Demo', j: 17 };
583
+ store.setState({ [ REPLACE_TAG ]: { a: 'Demo', j: 17 } }) // rewrites state to { a: 'Demo', j: 17 };
574
584
 
575
- store.setState({ a: { '@@REPLACE': { message: 'Testing...' } } }) // rewrites state.a to { message: 'Testing...' }
585
+ store.setState({ a: { [ REPLACE_TAG ]: { message: 'Testing...' } } }) // rewrites state.a to { message: 'Testing...' }
576
586
 
577
587
  /* rewrites state.a.b[1] to { x: 97, y: 98, z: 99 }; leaving state.a.b = [{ x: 7, y: 8, z: 9 }, { x: 97, y: 98, z: 99 }] */
578
- store.setState({ a: { b: [ state.a.b[ 0 ], { '@@REPLACE': { x: 97, y: 98, z: 99 } } ] } })
588
+ store.setState({ a: { b: [ state.a.b[ 0 ], { [ REPLACE_TAG ]: { x: 97, y: 98, z: 99 } } ] } })
579
589
 
580
590
  /* rewrites state.a.b[1] to { x: 97, y: 98, z: 99 }; leaving state.a.b = [{ x: 7, y: 8, z: 9 }, { x: 97, y: 98, z: 99 }] using indexing (RECOMMENDED) */
581
- store.setState({ a: { b: { 1: { '@@REPLACE': { x: 97, y: 98, z: 99 } } } } })
591
+ store.setState({ a: { b: { 1: { [ REPLACE_TAG ]: { x: 97, y: 98, z: 99 } } } } })
582
592
  ```
583
593
 
584
594
  <i id="set-tag-usage"><b>@@SET:</b> (takes an argument holding either the replacment value or a compute function returning the replacement value)</i>
@@ -592,38 +602,42 @@ store.setState({ a: { b: { 1: { '@@REPLACE': { x: 97, y: 98, z: 99 } } } } })
592
602
  Be aware that the compute function argument may be `undefined` for properties which do not yet exist in the state.
593
603
  */
594
604
 
605
+ import { SET_TAG } from '@webkrafters/react-observable-context'; // SET_TAG = "@@SET"
606
+
595
607
  const state = {
596
608
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
597
609
  j: 10
598
610
  };
599
611
 
600
- store.setState({ '@@SET': currentValue => ({ ...currentValue, a: 'Demo', j: 17 }) }) // rewrites state to { ...state, a: 'Demo', j: 17 };
612
+ store.setState({ [ SET_TAG ]: currentValue => ({ ...currentValue, a: 'Demo', j: 17 }) }) // rewrites state to { ...state, a: 'Demo', j: 17 };
601
613
 
602
- store.setState({ a: { '@@SET': currentValue => ({ ...currentValue, message: 'Testing...' }) } }) // rewrites state.a to { ...state, message: 'Testing...' }
614
+ store.setState({ a: { [ SET_TAG ]: currentValue => ({ ...currentValue, message: 'Testing...' }) } }) // rewrites state.a to { ...state, message: 'Testing...' }
603
615
 
604
616
  /* rewrites state.a.b[1] to { x: 97, y: 98, z: 99 }; leaving state.a.b = [{ x: 7, y: 8, z: 9 }, { x: 97, y: 98, z: 99 }] */
605
- store.setState({ a: { b: [ state.a.b[ 0 ], { '@@SET': currentValue => ({ ...currentValue, x: 97, y: 98, z: 99 }) } ] } })
617
+ store.setState({ a: { b: [ state.a.b[ 0 ], { [ SET_TAG ]: currentValue => ({ ...currentValue, x: 97, y: 98, z: 99 }) } ] } })
606
618
 
607
619
  /* rewrites state.a.b[1] to { x: 97, y: 98, z: 99 }; leaving state.a.b = [{ x: 7, y: 8, z: 9 }, { x: 97, y: 98, z: 99 }] using indexing (RECOMMENDED) */
608
- store.setState({ a: { b: { 1: { '@@SET': currentValue => ({ ...currentValue, x: 97, y: 98, z: 99 }) } } } })
620
+ store.setState({ a: { b: { 1: { [ SET_TAG ]: currentValue => ({ ...currentValue, x: 97, y: 98, z: 99 }) } } } })
609
621
  ```
610
622
 
611
- <i id="splice-tag-usage"><b>@@SPLICE:</b> (takes an array argument listing: -/+fromIndex, +deleteCount and optional ...newItems? newItems = ...[] by default)</i>
623
+ <i id="splice-tag-usage"><b>@@SPLICE:</b> (takes an array argumenst listing: -/+fromIndex, +deleteCount and optional ...newItems? newItems = ...[] by default)</i>
612
624
 
613
625
  ```jsx
626
+ import { SPLICE_TAG } from '@webkrafters/react-observable-context'; // SPLICE_TAG = "@@SPLICE"
627
+
614
628
  const state = {
615
629
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
616
630
  j: 10,
617
631
  q: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
618
632
  };
619
633
 
620
- store.setState({ a: { '@@SPLICE': [ 0, 1 ] } }) // assigning a '@@SPLICE' command to a non-array property has no effect.
634
+ store.setState({ a: { [ SPLICE_TAG ]: [ 0, 1 ] } }) // assigning a '@@SPLICE' command to a non-array property has no effect.
621
635
 
622
636
  /* removes state.a.b[0]; leaving state.a.b = [{ x: 17, y: 18, z: 19 }] */
623
- store.setState({ a: { b: { '@@SPLICE': [ 0, 1 ] } } }) // or store.setState({ a: { b: { '@@SPLICE': [ -2, -1 ] } } })
637
+ store.setState({ a: { b: { [ SPLICE_TAG ]: [ 0, 1 ] } } }) // or store.setState({ a: { b: { [ SPLICE_TAG ]: [ -2, -1 ] } } })
624
638
 
625
639
  /* replaces state.q[4] - [7] with 2 items; leaving state.q = [ 1, 2, 3, 4, 33, 88, 9 ] */
626
- store.setState({ a: { q: { '@@SPLICE': [ 4, 4, 33, 88 ] } } }) // or store.setState({ a: { q: { '@@SPLICE': [ -5, 4, 33, 88 ] } } })
640
+ store.setState({ a: { q: { [ SPLICE_TAG ]: [ 4, 4, 33, 88 ] } } }) // or store.setState({ a: { q: { [ SPLICE_TAG ]: [ -5, 4, 33, 88 ] } } })
627
641
  ```
628
642
 
629
643
  <h3 id="set-state-with-tags"><b><i>Combination Usage:</i></b></h3>
@@ -633,6 +647,8 @@ These tags may be used in combination with the default usage where all top-level
633
647
  <strong>Example:</strong>
634
648
 
635
649
  ```jsx
650
+ import * as ctx from '@webkrafters/react-observable-context';
651
+
636
652
  const state = {
637
653
  a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
638
654
  j: 10,
@@ -642,15 +658,15 @@ const state = {
642
658
  store.setState({
643
659
  a: {
644
660
  b: {
645
- /* evaluated 1st */ '@@DELETE': [ 0 ], // upon deleting state.a.b[0] -> state.a.b[1] becomes the new state.a.b[0]
646
- /* evaluated 3rd */ 0: '@@CLEAR', // clear the new state.a.b[0]
661
+ /* evaluated 1st */ [ ctx.DELETE_TAG ]: [ 0 ], // upon deleting state.a.b[0] -> state.a.b[1] becomes the new state.a.b[0]
662
+ /* evaluated 3rd */ 0: ctx.CLEAR_TAG, // clear the new state.a.b[0]
647
663
  /* evaluated 4th */ 2: { x: 47, y: 48, z: 49 }, // add new item at state.a.b[2],
648
- /* evaluated 2md */ '@@PUSH': [{ x: 107, y: 108, z: 109 }] // appends state.a.b[1]
664
+ /* evaluated 2md */ [ ctx.PUSH_TAG ]: [{ x: 107, y: 108, z: 109 }] // appends state.a.b[1]
649
665
  }
650
666
  },
651
- j: { '@@SET': currentValue => currentValue < 10 ? currentValue : 0 },
667
+ j: { [ ctx.SET_TAG ]: currentValue => currentValue < 10 ? currentValue : 0 },
652
668
  q: {
653
- /* evaluated 1st */ '@@MOVE': [ 5, 3, 2 ],
669
+ /* evaluated 1st */ [ ctx.MOVE_TAG ]: [ 5, 3, 2 ],
654
670
  /* evaluated 2md */ 12: 11
655
671
  }
656
672
  })
@@ -664,9 +680,13 @@ store.setState({
664
680
  <h1 id="changes">What's Changed?</h1>
665
681
 
666
682
  <table>
683
+ <thead><tr><th>v4.5.0</th></tr></thead>
684
+ <tbody>
685
+ <tr><td><b>1.</b></td><td><a href="#setstate-tags">Tags</a> to update non-existent state slices are now recognized. <b>Previously,</b> they had resulted in no-ops. <b>From now on,</b> they will result in new default slices matching the result of the given tag operation.</td></tr>
686
+ </tbody>
667
687
  <thead><tr><th>v4.4.0</th></tr></thead>
668
688
  <tbody>
669
- <tr><td><b>1.</b></td><td>Returns <code>undefined</code> for selector map pointing at a non-existent state slice. <i>(Previously returned <code>null</code>)</i></td></tr>
689
+ <tr><td><b>1.</b></td><td>Returns <code>undefined</code> for selector map pointing at a non-existent state slice. <i>(Previously returned <code>null</code>)</i>.</td></tr>
670
690
  </tbody>
671
691
  <thead><tr><th>v4.3.0</th></tr></thead>
672
692
  <tbody>
package/package.json CHANGED
@@ -133,5 +133,5 @@
133
133
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
134
134
  },
135
135
  "types": "dist/main/index.d.ts",
136
- "version": "4.5.0-rc"
136
+ "version": "4.5.0-rc.2"
137
137
  }