@creopse/react 0.0.18 → 0.0.19
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/dist/index.cjs +17 -3
- package/dist/index.mjs +17 -3
- package/package.json +1 -1
- package/types/core/props-manager.d.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -349,8 +349,8 @@ class PropsManager {
|
|
|
349
349
|
this.state = { props: initialProps };
|
|
350
350
|
this.listeners = /* @__PURE__ */ new Set();
|
|
351
351
|
}
|
|
352
|
-
update(payload) {
|
|
353
|
-
this.state.props = this.deepMerge(this.state.props, payload);
|
|
352
|
+
update(payload, strategy = "merge") {
|
|
353
|
+
this.state.props = strategy === "merge" ? this.deepMerge(this.state.props, payload) : this.deepOverride(this.state.props, payload);
|
|
354
354
|
this.notify();
|
|
355
355
|
}
|
|
356
356
|
getState() {
|
|
@@ -384,6 +384,20 @@ class PropsManager {
|
|
|
384
384
|
}
|
|
385
385
|
return output;
|
|
386
386
|
}
|
|
387
|
+
deepOverride(target, source) {
|
|
388
|
+
if (!this.isObject(source)) {
|
|
389
|
+
return source;
|
|
390
|
+
}
|
|
391
|
+
const output = { ...source };
|
|
392
|
+
if (this.isObject(target)) {
|
|
393
|
+
Object.keys(source).forEach((key) => {
|
|
394
|
+
if (this.isObject(source[key]) && this.isObject(target[key])) {
|
|
395
|
+
output[key] = this.deepOverride(target[key], source[key]);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return output;
|
|
400
|
+
}
|
|
387
401
|
isObject(item) {
|
|
388
402
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
389
403
|
}
|
|
@@ -8426,7 +8440,7 @@ function CreopseProvider({ children, options }) {
|
|
|
8426
8440
|
React.useEffect(() => {
|
|
8427
8441
|
if (options.router) {
|
|
8428
8442
|
const handleNavigate = (event) => {
|
|
8429
|
-
manager.
|
|
8443
|
+
manager.sync(event.detail.page.props);
|
|
8430
8444
|
};
|
|
8431
8445
|
options.router.on("navigate", handleNavigate);
|
|
8432
8446
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -331,8 +331,8 @@ class PropsManager {
|
|
|
331
331
|
this.state = { props: initialProps };
|
|
332
332
|
this.listeners = /* @__PURE__ */ new Set();
|
|
333
333
|
}
|
|
334
|
-
update(payload) {
|
|
335
|
-
this.state.props = this.deepMerge(this.state.props, payload);
|
|
334
|
+
update(payload, strategy = "merge") {
|
|
335
|
+
this.state.props = strategy === "merge" ? this.deepMerge(this.state.props, payload) : this.deepOverride(this.state.props, payload);
|
|
336
336
|
this.notify();
|
|
337
337
|
}
|
|
338
338
|
getState() {
|
|
@@ -366,6 +366,20 @@ class PropsManager {
|
|
|
366
366
|
}
|
|
367
367
|
return output;
|
|
368
368
|
}
|
|
369
|
+
deepOverride(target, source) {
|
|
370
|
+
if (!this.isObject(source)) {
|
|
371
|
+
return source;
|
|
372
|
+
}
|
|
373
|
+
const output = { ...source };
|
|
374
|
+
if (this.isObject(target)) {
|
|
375
|
+
Object.keys(source).forEach((key) => {
|
|
376
|
+
if (this.isObject(source[key]) && this.isObject(target[key])) {
|
|
377
|
+
output[key] = this.deepOverride(target[key], source[key]);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return output;
|
|
382
|
+
}
|
|
369
383
|
isObject(item) {
|
|
370
384
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
371
385
|
}
|
|
@@ -8408,7 +8422,7 @@ function CreopseProvider({ children, options }) {
|
|
|
8408
8422
|
useEffect(() => {
|
|
8409
8423
|
if (options.router) {
|
|
8410
8424
|
const handleNavigate = (event) => {
|
|
8411
|
-
manager.
|
|
8425
|
+
manager.sync(event.detail.page.props);
|
|
8412
8426
|
};
|
|
8413
8427
|
options.router.on("navigate", handleNavigate);
|
|
8414
8428
|
} else {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ declare class PropsManager<T extends Props = Props> {
|
|
|
3
3
|
private state;
|
|
4
4
|
private listeners;
|
|
5
5
|
constructor(initialProps: T);
|
|
6
|
-
update(payload: T): void;
|
|
6
|
+
update(payload: T, strategy?: 'merge' | 'override'): void;
|
|
7
7
|
getState(): {
|
|
8
8
|
props: T;
|
|
9
9
|
};
|
|
@@ -11,6 +11,7 @@ declare class PropsManager<T extends Props = Props> {
|
|
|
11
11
|
subscribe(callback: (props: T) => void): () => void;
|
|
12
12
|
private notify;
|
|
13
13
|
private deepMerge;
|
|
14
|
+
private deepOverride;
|
|
14
15
|
private isObject;
|
|
15
16
|
}
|
|
16
17
|
export default PropsManager;
|