@webkrafters/react-observable-context 4.5.0-rc.2 → 4.5.0

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 +12 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -82,7 +82,7 @@ May also see <b><a href="#changes">What's Changed?</a></b>.
82
82
 
83
83
  # Intro
84
84
 
85
- A context bearing an observable consumer [store](#store). State changes within the store's internal state are only broadcasted to components subscribed to the store (the [clients](#client)). In this way, the `React-Observable-Context` prevents repeated automatic re-renderings of entire component trees resulting from ***context*** state changes.
85
+ A context bearing an observable consumer [store](#store) whose internal state is <u><b>immutable</b></u> and <u><b>private</b></u>. State changes within the store's internal state are only broadcasted to components (the [clients](#client)) subscribed to the store. In this way, the `React-Observable-Context` prevents repeated automatic re-renderings of entire component trees resulting from ***context*** state changes.
86
86
 
87
87
  <h1 id="getting-started">Getting Started</h1>
88
88
 
@@ -148,20 +148,20 @@ const createInitialState = c = ({
148
148
 
149
149
  const ProviderDemo = ({ ageInMinutes: c = 0 }) => {
150
150
 
151
- const [ state, setState ] = useState(() => createInitialState( c ));
151
+ const [ value, setValue ] = useState(() => createInitialState( c ));
152
152
 
153
153
  useEffect(() => {
154
154
  // similar to `store.setState`, use the following to update
155
155
  // only the changed slice of the context internal state.
156
- // Please see `Set State` section
157
- setState({ a: { b: { c } } }); // OR
158
- // setState({ a: { b: { c: { '@@REPLACE': c } } } });
156
+ // Please use the `Set State` link in the TOC for more details.
157
+ setValue({ a: { b: { c } } }); // OR
158
+ // setValue({ a: { b: { c: { '@@REPLACE': c } } } });
159
159
  // Do not do the following: it will override the context internal state.
160
- // setState({ ...state, a: { ...state.a, b: { ...state.a.b, c } } });
160
+ // setValue({ ...value, a: { ...value.a, b: { ...value.a.b, c } } });
161
161
  }, [ c ]);
162
162
 
163
163
  return (
164
- <ObservableContext.Provider value={ state }>
164
+ <ObservableContext.Provider value={ value }>
165
165
  <Ui />
166
166
  </ObservableContext.Provider>
167
167
  );
@@ -189,7 +189,7 @@ export const YearInput = ({ data, resetState, setState }) => {
189
189
  data.year > 2049 && resetState([ 'a.b.c' ]);
190
190
  }, [ data.year ]);
191
191
 
192
- return ( <div>Year: <input type="number" onChange={ onChange } /> );
192
+ return ( <div>Year: <input type="number" onChange={ onChange } /></div> );
193
193
  };
194
194
 
195
195
  const withConnector = connect( ObservablContext, { year: 'a.b.x.y.z[0]' } );
@@ -231,7 +231,7 @@ const Client2 = memo(() => { // memoize to prevent 'no-change' renders from the
231
231
  data.year > 2049 && resetState([ 'a.b.c' ]);
232
232
  }, [ data.year ]);
233
233
 
234
- return ( <div>Year: <input type="number" onChange={ onChange } /> );
234
+ return ( <div>Year: <input type="number" onChange={ onChange } /></div> );
235
235
  });
236
236
 
237
237
  const Ui = () => (
@@ -436,6 +436,8 @@ The `React.Observable.Context` context `store` is the client's portal into the c
436
436
  <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.
437
437
 
438
438
  <h3 id="store-setstate" style="margin-top:10px"><code>store.setState</code> Usage</h3>
439
+ <blockquote>[This store's] internal state is <u><b>immutable</b></u> and <u><b>private</b></u>.</blockquote>
440
+ New updates are merged into state by default. To overwrite state, use the <a href="setstate-tags">tag</a> command.<br />
439
441
  :warning: <b><i>Do this:</i></b> <code>setState({stateKey0: changes0[, ...]});</code><br />
440
442
  :warning: <b><i>Not this:</i></b> <code>setState({stateKey0: {...state.stateKey0, ...changes0}[, ...]});</code>
441
443
  <h3 id="indexing"><b><i><u>Indexing</u></i></b></h3>
@@ -467,7 +469,7 @@ store.setState({ ...state, a: { ...state.a, b: [ { ...first, y: 30 }, 22, ...res
467
469
  ```
468
470
  :warning: <b id="neg-idx-tip"><i>Tip:</i></b> Negative indexing pointing at an out-of-bounds index is ignored.
469
471
 
470
- <h3 id="setstate-tags"><b><i><u>Rewriting state using tag commands</u></i></b></h3>
472
+ <h3 id="setstate-tags"><b><i><u>Overwriting state using tag commands</u></i></b></h3>
471
473
  By default, <code>store.setState</code> recursively merges new changes into current state.<br />
472
474
  To overwrite current state slices with new values, <b>7</b> tag commands have been provided:
473
475
  <ol>
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.2"
136
+ "version": "4.5.0"
137
137
  }