@webkrafters/react-observable-context 2.1.7 → 2.1.8

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 +27 -23
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,26 +1,30 @@
1
1
  # React-Observable-Context
2
2
 
3
- A context bearing an observable consumer store. State changes within the store's internal state are only broadcasted to components 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.
3
+ A context bearing an observable consumer store.
4
4
 
5
- **React::memo** *(and PureComponents)* remain the go-to solution for the repeated automatic re-renderings of entire component trees resulting from ***component*** state changes.
5
+ **Name:** React-Observable-Context
6
6
 
7
- _**Recommendation:**_ For optimum performance, consider wrapping in **React::memo** most components using this package's ***useContext*** function either directly or through another React hook. This will protect such components and their descendants from unrelated cascading render operations.
7
+ **Usage:** Please see [Usage](#usage) section
8
8
 
9
- ***Exempt*** from the recommendation are certain components such as those wrapped in the `React-Redux::connect()` Higher Order Component (HOC). Such HOC provides similar cascade-render protections to wrapped components and their descendants.
9
+ **Install:**\
10
+ npm i -S @webkrafters/react-observable-context\
11
+ npm install --save @webkrafters/react-observable-context
10
12
 
11
- <hr />
13
+ # Intro
12
14
 
13
- <h3><u>Install</u></h3>
15
+ State changes within the store's internal state are only broadcasted to components 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.
14
16
 
15
- npm i -S @webkrafters/react-observable-context
17
+ **React::memo** *(and PureComponents)* remain the go-to solution for the repeated automatic re-renderings of entire component trees resulting from ***component*** state changes.
16
18
 
17
- npm install --save @webkrafters/react-observable-context
19
+ _**Recommendation:**_ For optimum performance, consider wrapping in **React::memo** most components using this package's ***useContext*** function either directly or through another React hook. This will protect such components and their descendants from unrelated cascading render operations.
20
+
21
+ ***Exempt*** from the recommendation are certain components such as those wrapped in the `React-Redux::connect()` Higher Order Component (HOC). Such HOC provides similar cascade-render protections to wrapped components and their descendants.
18
22
 
19
- ## API
23
+ # API
20
24
 
21
25
  The React-Observable-Context package exports **4** modules namely: the **createContext** method, the **useContext** hook, the **Provider** component and the **UsageError** class.
22
26
 
23
- * **createContext** is a zero-parameter funtion returning a store-bearing context. Pass the context to the React::useContext() parameter to obtain the context's `store`.
27
+ * **createContext** is a zero-parameter function returning a store-bearing context. Pass the context to the useContext() parameter to obtain the context's `store`.
24
28
 
25
29
  * **useContext** is analogous to React::useContext hook but returns the context store and takes a second parameter named ***watchedKeys***. The `watchedKeys` parameter is a list of state object property paths to watch. A change in any of the referenced properties automatically triggers a render of the component calling this hook.
26
30
 
@@ -30,7 +34,7 @@ The React-Observable-Context package exports **4** modules namely: the **createC
30
34
 
31
35
  ***<u>Note:</u>*** the Provider `context` prop is not updateable. Once set, all further updates to this prop are not recorded.
32
36
 
33
- ### The Store
37
+ ## The Store
34
38
 
35
39
  The context's `store` exposes **4** methods for interacting with the context's internal state namely:
36
40
 
@@ -44,7 +48,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
44
48
 
45
49
  * **subscribe**: (listener: (newValue: PartialState\<State\>, oldValue: PartialState\<State\>) => void) => ***UnsubscribeFunction***
46
50
 
47
- ### Prehooks
51
+ ## Prehooks
48
52
 
49
53
  Prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates.
50
54
 
@@ -58,9 +62,9 @@ The context's `store` exposes **4** methods for interacting with the context's i
58
62
 
59
63
  ***<u>Use case:</u>*** prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates.
60
64
 
61
- ## Usage
65
+ # Usage
62
66
 
63
- <i><u>context.js</u></i>
67
+ ### <u>*context.js*</u>
64
68
 
65
69
  import React from 'react';
66
70
 
@@ -87,14 +91,14 @@ The context's `store` exposes **4** methods for interacting with the context's i
87
91
 
88
92
  export default ObservableContext;
89
93
 
90
- <i><u>index.js</u></i>
94
+ ### <u>*index.js*</u>
91
95
 
92
96
  import React from 'react';
93
97
  import ReactDOM from 'react-dom';
94
98
  import App from './app';
95
99
  ReactDOM.render(<App />, document.getElementById('root'));
96
100
 
97
- <i><u>app.js</u></i>
101
+ ### <u>*app.js*</u>
98
102
 
99
103
  import React, { useCallback, useState } from 'react';
100
104
  import Product from './product';
@@ -128,7 +132,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
128
132
  App.displayName = 'App';
129
133
  export default App;
130
134
 
131
- <i><u>product.js</u></i>
135
+ ### <u>*product.js*</u>
132
136
 
133
137
  import React, { useCallback, useEffect, useState } from 'react';
134
138
  import { ObservableContextProvider } from './context';
@@ -173,7 +177,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
173
177
  Product.displayName = 'Product';
174
178
  export default Product;
175
179
 
176
- <i><u>editor.js</u></i>
180
+ ### <u>*editor.js*</u>
177
181
 
178
182
  import React, { memo, useCallback, useEffect, useRef } from 'react';
179
183
  import { useObservableContext } from './context';
@@ -216,7 +220,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
216
220
  Editor.displayName = 'Editor';
217
221
  export default Editor;
218
222
 
219
- <i><u>price-sticker.js</u></i>
223
+ ### <u>*price-sticker.js*</u>
220
224
 
221
225
  import React, { memo, useEffect } from 'react';
222
226
  import { useObservableContext } from './context';
@@ -233,7 +237,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
233
237
  PriceSticker.displayName = 'PriceSticker';
234
238
  export default PriceSticker;
235
239
 
236
- <i><u>product-description.js</u></i>
240
+ ### <u>*product-description.js*</u>
237
241
 
238
242
  import React, { memo, useEffect } from 'react';
239
243
  import { useObservableContext } from './context';
@@ -252,7 +256,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
252
256
  ProductDescription.displayName = 'ProductDescription';
253
257
  export default ProductDescription;
254
258
 
255
- <i><u>tally-display.js</u></i>
259
+ ### <u>*tally-display.js*</u>
256
260
 
257
261
  import React, { memo, useEffect } from 'react';
258
262
  import { useObservableContext } from './context';
@@ -279,7 +283,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
279
283
  TallyDisplay.displayName = 'TallyDisplay';
280
284
  export default TallyDisplay;
281
285
 
282
- <i><u>reset.js</u></i>
286
+ ### <u>*reset.js*</u>
283
287
 
284
288
  import React, { memo, useEffect } from 'react';
285
289
  import { useObservableContext } from './context';
@@ -292,6 +296,6 @@ The context's `store` exposes **4** methods for interacting with the context's i
292
296
  export default Reset;
293
297
 
294
298
 
295
- ## License
299
+ # License
296
300
 
297
301
  MIT
package/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
80
80
  },
81
81
  "types": "dist/index.d.ts",
82
- "version": "2.1.7"
82
+ "version": "2.1.8"
83
83
  }