dphelper 1.9.69 → 1.9.71

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 CHANGED
@@ -33,6 +33,7 @@
33
33
  2. [Store](#store)
34
34
  3. [Session](#session)
35
35
  4. [Observer](#observer)
36
+ 5. [useObserver](#useobserver)
36
37
  5. [Extension](#extension)
37
38
  6. [Security](#security)
38
39
  7. [License](#license)
@@ -126,6 +127,7 @@ You can see:
126
127
  * [State](https://a51.gitbook.io/dphelper/general/state)
127
128
  * [Store](https://a51.gitbook.io/dphelper/general/store)
128
129
  * [Observer](https://a51.gitbook.io/dphelper/general/observer)
130
+ * [useObserver](https://a51.gitbook.io/dphelper/general/useobserver)
129
131
  * [List of functions](https://a51.gitbook.io/dphelper/general/tools)
130
132
 
131
133
  You can see more tutorials, information, and examples about **dpHelper** [clicking here](https://a51.gitbook.io/dphelper).
@@ -224,6 +226,21 @@ observer('myData', () => {
224
226
  state.myData = 'New value';
225
227
  ```
226
228
 
229
+ ## useObserver
230
+
231
+ ```js
232
+ import 'dphelper';
233
+
234
+ // Use the useObserver to log the changing state value
235
+ useObserver(
236
+ () => console.log("State changed: ", state.count)
237
+ , 'state.count'
238
+ );
239
+
240
+ // Store a value in the state that changes every 5 seconds
241
+ setInterval(() => state.count = Date.now(), 5000);
242
+ ```
243
+
227
244
  ## Store
228
245
 
229
246
  ### Persistent Storage with dpHelper
package/docs/index.md CHANGED
@@ -33,6 +33,7 @@
33
33
  2. [Store](#store)
34
34
  3. [Session](#session)
35
35
  4. [Observer](#observer)
36
+ 5. [useObserver](#useobserver)
36
37
  5. [Extension](#extension)
37
38
  6. [Security](#security)
38
39
  7. [License](#license)
@@ -126,6 +127,7 @@ You can see:
126
127
  * [State](https://a51.gitbook.io/dphelper/general/state)
127
128
  * [Store](https://a51.gitbook.io/dphelper/general/store)
128
129
  * [Observer](https://a51.gitbook.io/dphelper/general/observer)
130
+ * [useObserver](https://a51.gitbook.io/dphelper/general/useobserver)
129
131
  * [List of functions](https://a51.gitbook.io/dphelper/general/tools)
130
132
 
131
133
  You can see more tutorials, information, and examples about **dpHelper** [clicking here](https://a51.gitbook.io/dphelper).
@@ -224,6 +226,21 @@ observer('myData', () => {
224
226
  state.myData = 'New value';
225
227
  ```
226
228
 
229
+ ## useObserver
230
+
231
+ ```js
232
+ import 'dphelper';
233
+
234
+ // Use the useObserver to log the changing state value
235
+ useObserver(
236
+ () => console.log("State changed: ", state.count)
237
+ , 'state.count'
238
+ );
239
+
240
+ // Store a value in the state that changes every 5 seconds
241
+ setInterval(() => state.count = Date.now(), 5000);
242
+ ```
243
+
227
244
  ## Store
228
245
 
229
246
  ### Persistent Storage with dpHelper
@@ -0,0 +1,30 @@
1
+ # useObserver
2
+
3
+ ## Overview
4
+
5
+ This document provides a comprehensive list of all available useObserver functions in the `dpHelper` library along with their descriptions and examples.
6
+
7
+ ## Functions
8
+
9
+ ### useObserver(()=>{ YOUR CODE }, "state.name")
10
+
11
+ - **Description:** Sets up an useObserver to monitor state changes and trigger a callback.
12
+ - **Parameters:**
13
+ - `stateName` (string): The name of the state to monitor.
14
+ - `callBack` (Function): The callback function to run when the state changes.
15
+ - `option` (object): Additional options for the useObserver.
16
+
17
+ - **Example:**
18
+ > The format is really similar to React useEffect
19
+
20
+ ```javascript
21
+ useObserver(
22
+ () => {
23
+ console.log('State changed:', newValue);
24
+ }, 'state.test'
25
+ );
26
+ ```
27
+
28
+ ## License
29
+
30
+ This project is licensed under the Private License.
package/index.d.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  /// <reference path="./types/dphelper.d.ts" />
14
14
  /// <reference path="./types/memorio.d.ts" />
15
15
  /// <reference path="./types/observer.d.ts" />
16
+ /// <reference path="./types/useObserver.d.ts" />
16
17
  /// <reference path="./types/state.d.ts" />
17
18
  /// <reference path="./types/session.d.ts" />
18
19
  /// <reference path="./types/store.d.ts" />