dphelper 1.8.8 → 1.8.9
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 +28 -4
- package/docs/index.md +28 -4
- package/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://npmjs.org/package/dphelper)
|
|
8
8
|
|
|
9
9
|
[](https://snyk.io/advisor/npm-package/dphelper)
|
|
10
|
-
[](https://socket.dev/npm/package/dphelper/overview)
|
|
11
11
|
[](https://npmjs.org/package/dphelper)
|
|
12
12
|
|
|
13
13
|

|
|
@@ -112,11 +112,16 @@ state.test = "I am ready";
|
|
|
112
112
|
state.test
|
|
113
113
|
|
|
114
114
|
// List all states
|
|
115
|
-
state
|
|
115
|
+
state.list // or just state
|
|
116
|
+
|
|
117
|
+
// Remove a state
|
|
118
|
+
state.remove("test")
|
|
116
119
|
```
|
|
117
120
|
|
|
118
121
|
## Observer 😎
|
|
119
122
|
|
|
123
|
+
**Important**: Observer works only with states.
|
|
124
|
+
|
|
120
125
|
If you want to run a function everytime a state change... you can use:
|
|
121
126
|
|
|
122
127
|
```javascript
|
|
@@ -146,13 +151,32 @@ setInterval(() => {
|
|
|
146
151
|
state.count = Date.now();
|
|
147
152
|
}, 5000);
|
|
148
153
|
|
|
154
|
+
```
|
|
155
|
+
#### another simple example:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import 'dphelper';
|
|
159
|
+
|
|
160
|
+
// Set a state
|
|
161
|
+
state.myData = 'Hello, world!';
|
|
162
|
+
|
|
163
|
+
// Retrieve the state
|
|
164
|
+
console.log(state.myData); // Output: Hello, world!
|
|
165
|
+
|
|
166
|
+
// Observe state changes
|
|
167
|
+
observer('myData', () => {
|
|
168
|
+
console.log('myData has changed to:', state.myData);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Change the state
|
|
172
|
+
state.myData = 'New value';
|
|
149
173
|
```
|
|
150
174
|
|
|
151
175
|
## State 'n Store 🎅
|
|
152
176
|
|
|
153
177
|
### Persistent Storage with dpHelper
|
|
154
178
|
|
|
155
|
-
When using dpHelper for permanent storage, you should use the store
|
|
179
|
+
When using dpHelper for permanent storage, you should use the **store** instead of **state**. This is because store utilizes localStorage, which stores data persistently across sessions.
|
|
156
180
|
|
|
157
181
|
#### Important Security Note
|
|
158
182
|
|
|
@@ -172,7 +196,7 @@ store.get("test") // Output: { test:"test" }
|
|
|
172
196
|
// Remove a store:
|
|
173
197
|
store.delete("test") // Output: "ok"
|
|
174
198
|
|
|
175
|
-
// Remove all:
|
|
199
|
+
// Remove all stores:
|
|
176
200
|
store.clearAll() // Output: "ok"
|
|
177
201
|
|
|
178
202
|
```
|
package/docs/index.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://npmjs.org/package/dphelper)
|
|
8
8
|
|
|
9
9
|
[](https://snyk.io/advisor/npm-package/dphelper)
|
|
10
|
-
[](https://socket.dev/npm/package/dphelper/overview)
|
|
11
11
|
[](https://npmjs.org/package/dphelper)
|
|
12
12
|
|
|
13
13
|

|
|
@@ -112,11 +112,16 @@ state.test = "I am ready";
|
|
|
112
112
|
state.test
|
|
113
113
|
|
|
114
114
|
// List all states
|
|
115
|
-
state
|
|
115
|
+
state.list // or just state
|
|
116
|
+
|
|
117
|
+
// Remove a state
|
|
118
|
+
state.remove("test")
|
|
116
119
|
```
|
|
117
120
|
|
|
118
121
|
## Observer 😎
|
|
119
122
|
|
|
123
|
+
**Important**: Observer works only with states.
|
|
124
|
+
|
|
120
125
|
If you want to run a function everytime a state change... you can use:
|
|
121
126
|
|
|
122
127
|
```javascript
|
|
@@ -146,13 +151,32 @@ setInterval(() => {
|
|
|
146
151
|
state.count = Date.now();
|
|
147
152
|
}, 5000);
|
|
148
153
|
|
|
154
|
+
```
|
|
155
|
+
#### another simple example:
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import 'dphelper';
|
|
159
|
+
|
|
160
|
+
// Set a state
|
|
161
|
+
state.myData = 'Hello, world!';
|
|
162
|
+
|
|
163
|
+
// Retrieve the state
|
|
164
|
+
console.log(state.myData); // Output: Hello, world!
|
|
165
|
+
|
|
166
|
+
// Observe state changes
|
|
167
|
+
observer('myData', () => {
|
|
168
|
+
console.log('myData has changed to:', state.myData);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Change the state
|
|
172
|
+
state.myData = 'New value';
|
|
149
173
|
```
|
|
150
174
|
|
|
151
175
|
## State 'n Store 🎅
|
|
152
176
|
|
|
153
177
|
### Persistent Storage with dpHelper
|
|
154
178
|
|
|
155
|
-
When using dpHelper for permanent storage, you should use the store
|
|
179
|
+
When using dpHelper for permanent storage, you should use the **store** instead of **state**. This is because store utilizes localStorage, which stores data persistently across sessions.
|
|
156
180
|
|
|
157
181
|
#### Important Security Note
|
|
158
182
|
|
|
@@ -172,7 +196,7 @@ store.get("test") // Output: { test:"test" }
|
|
|
172
196
|
// Remove a store:
|
|
173
197
|
store.delete("test") // Output: "ok"
|
|
174
198
|
|
|
175
|
-
// Remove all:
|
|
199
|
+
// Remove all stores:
|
|
176
200
|
store.clearAll() // Output: "ok"
|
|
177
201
|
|
|
178
202
|
```
|