as-model 0.1.23 → 0.1.25
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.js +53 -34
- package/esm/store/enhance/signal.js +19 -13
- package/esm/updater/index.js +2 -2
- package/esm/updater/notifier.js +14 -3
- package/esm/updater/tunnel.js +12 -9
- package/index.d.ts +5 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -369,8 +369,11 @@
|
|
|
369
369
|
type: null,
|
|
370
370
|
method: null
|
|
371
371
|
};
|
|
372
|
-
temporaryDispatches.forEach(function(
|
|
373
|
-
|
|
372
|
+
temporaryDispatches.forEach(function(d) {
|
|
373
|
+
if (!d.accessible) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
d.dispatch(initializedAction);
|
|
374
377
|
});
|
|
375
378
|
}
|
|
376
379
|
var dispatch = function dispatch2(action) {
|
|
@@ -392,7 +395,15 @@
|
|
|
392
395
|
}
|
|
393
396
|
var notifyAction = function notifyAction2(act) {
|
|
394
397
|
var errors = [];
|
|
395
|
-
var
|
|
398
|
+
var dispatchWrap = simpleErrorProcess(errors);
|
|
399
|
+
var dispatchCallbacks = dispatches.map(function(d) {
|
|
400
|
+
return dispatchWrap(function dispatchCallback(ac) {
|
|
401
|
+
if (!d.accessible) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
d.dispatch(ac);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
396
407
|
defaultNotifyImplement(dispatchCallbacks, act);
|
|
397
408
|
if (!errors.length) {
|
|
398
409
|
return {
|
|
@@ -511,7 +522,9 @@
|
|
|
511
522
|
function subscribe(dispatchFn) {
|
|
512
523
|
var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
|
|
513
524
|
var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
|
|
514
|
-
var exist = copied.
|
|
525
|
+
var exist = copied.some(function(d) {
|
|
526
|
+
return d.dispatch === dispatchFn;
|
|
527
|
+
});
|
|
515
528
|
if (exist) {
|
|
516
529
|
return updater.mutate(function(u) {
|
|
517
530
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -519,11 +532,15 @@
|
|
|
519
532
|
});
|
|
520
533
|
});
|
|
521
534
|
}
|
|
535
|
+
var dispatcher = {
|
|
536
|
+
dispatch: dispatchFn,
|
|
537
|
+
accessible: true
|
|
538
|
+
};
|
|
522
539
|
if (isControlled) {
|
|
523
540
|
return updater.mutate(function(u) {
|
|
524
541
|
return _object_spread_props(_object_spread({}, u), {
|
|
525
542
|
dispatches: [
|
|
526
|
-
|
|
543
|
+
dispatcher
|
|
527
544
|
],
|
|
528
545
|
isDestroyed: false
|
|
529
546
|
});
|
|
@@ -532,7 +549,7 @@
|
|
|
532
549
|
return updater.mutate(function(u, effect) {
|
|
533
550
|
var tds = u.temporaryDispatches, ds = u.dispatches;
|
|
534
551
|
var nextTds = _to_consumable_array(tds).concat([
|
|
535
|
-
|
|
552
|
+
dispatcher
|
|
536
553
|
]);
|
|
537
554
|
if (u.dispatching) {
|
|
538
555
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -550,7 +567,7 @@
|
|
|
550
567
|
method: null
|
|
551
568
|
};
|
|
552
569
|
nextTds.forEach(function(td) {
|
|
553
|
-
td(initializedAction);
|
|
570
|
+
td.dispatch(initializedAction);
|
|
554
571
|
});
|
|
555
572
|
});
|
|
556
573
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -560,19 +577,23 @@
|
|
|
560
577
|
});
|
|
561
578
|
});
|
|
562
579
|
}
|
|
563
|
-
return function tunnel(
|
|
580
|
+
return function tunnel(dispatchFn) {
|
|
564
581
|
function disconnect() {
|
|
565
582
|
updater.mutate(function(u) {
|
|
566
583
|
var ds = u.dispatches, tds = u.temporaryDispatches;
|
|
584
|
+
var found = _to_consumable_array(ds).concat(_to_consumable_array(tds)).find(function(d) {
|
|
585
|
+
return d.dispatch === dispatchFn;
|
|
586
|
+
});
|
|
587
|
+
if (!found) {
|
|
588
|
+
return u;
|
|
589
|
+
}
|
|
590
|
+
found.accessible = false;
|
|
567
591
|
var nextDs = ds.filter(function(d) {
|
|
568
|
-
return d !==
|
|
592
|
+
return d !== found;
|
|
569
593
|
});
|
|
570
594
|
var nextTds = tds.filter(function(d) {
|
|
571
|
-
return d !==
|
|
595
|
+
return d !== found;
|
|
572
596
|
});
|
|
573
|
-
if (ds.length === nextDs.length && tds.length === nextTds.length) {
|
|
574
|
-
return u;
|
|
575
|
-
}
|
|
576
597
|
return _object_spread_props(_object_spread({}, u), {
|
|
577
598
|
dispatches: nextDs,
|
|
578
599
|
temporaryDispatches: nextTds
|
|
@@ -581,7 +602,7 @@
|
|
|
581
602
|
}
|
|
582
603
|
return {
|
|
583
604
|
connect: function connect() {
|
|
584
|
-
subscribe(
|
|
605
|
+
subscribe(dispatchFn);
|
|
585
606
|
},
|
|
586
607
|
disconnect: function disconnect1() {
|
|
587
608
|
disconnect();
|
|
@@ -613,7 +634,7 @@
|
|
|
613
634
|
var controlledState = hasInitialState && !hasState ? args.initialState : state;
|
|
614
635
|
var instance = model2(controlledState);
|
|
615
636
|
return _object_spread_props(_object_spread({}, u), {
|
|
616
|
-
state,
|
|
637
|
+
state: controlledState,
|
|
617
638
|
instance,
|
|
618
639
|
model: model2
|
|
619
640
|
});
|
|
@@ -630,7 +651,7 @@
|
|
|
630
651
|
var initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
631
652
|
return _object_spread(_object_spread_props(_object_spread({}, u), {
|
|
632
653
|
model: model2,
|
|
633
|
-
state,
|
|
654
|
+
state: initialState,
|
|
634
655
|
instance: instance1,
|
|
635
656
|
initialized: true,
|
|
636
657
|
token
|
|
@@ -901,23 +922,20 @@
|
|
|
901
922
|
dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
|
|
902
923
|
return;
|
|
903
924
|
}
|
|
904
|
-
var
|
|
925
|
+
var storeInstance = extractInstance(store.updater);
|
|
905
926
|
var keys = Object.keys(collection);
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
927
|
+
if (!keys.length) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
var hasChange = keys.some(function(key) {
|
|
931
|
+
var field2 = storeInstance[key];
|
|
932
|
+
var collectedField = collection[key];
|
|
933
|
+
if (cacheIdentify.field(field2) && cacheIdentify.field(collectedField)) {
|
|
934
|
+
return field2.get() !== collectedField.get();
|
|
913
935
|
}
|
|
914
|
-
return
|
|
915
|
-
key,
|
|
916
|
-
field2
|
|
917
|
-
];
|
|
936
|
+
return field2 !== collectedField;
|
|
918
937
|
});
|
|
919
|
-
|
|
920
|
-
if (!shallowEqual(collection, currentCollection)) {
|
|
938
|
+
if (hasChange) {
|
|
921
939
|
dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
|
|
922
940
|
}
|
|
923
941
|
};
|
|
@@ -939,11 +957,12 @@
|
|
|
939
957
|
signalStore.collection = signalStore.collection || {};
|
|
940
958
|
signalStore.collection[key] = val;
|
|
941
959
|
};
|
|
942
|
-
var getInstance = function getInstance2() {
|
|
943
|
-
|
|
960
|
+
var getInstance = function getInstance2(options) {
|
|
961
|
+
var cutOff = (options !== null && options !== void 0 ? options : {}).cutOff;
|
|
962
|
+
return extractInstance(store.updater, cutOff ? void 0 : collectUsedFields);
|
|
944
963
|
};
|
|
945
|
-
var signal = function signal2() {
|
|
946
|
-
return getInstance();
|
|
964
|
+
var signal = function signal2(options) {
|
|
965
|
+
return getInstance(options);
|
|
947
966
|
};
|
|
948
967
|
signal.startStatistics = function startStatistics() {
|
|
949
968
|
signalStore.started = true;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cacheIdentify, extractInstance } from "../instance";
|
|
2
|
-
import { shallowEqual } from "../../tools";
|
|
3
2
|
function createSignal(store) {
|
|
4
3
|
const signalStore = {
|
|
5
4
|
collection: null,
|
|
@@ -17,17 +16,20 @@ function createSignal(store) {
|
|
|
17
16
|
dispatcher == null ? void 0 : dispatcher(action);
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
|
-
const
|
|
19
|
+
const storeInstance = extractInstance(store.updater);
|
|
21
20
|
const keys = Object.keys(collection);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (!keys.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const hasChange = keys.some((key) => {
|
|
25
|
+
const field = storeInstance[key];
|
|
26
|
+
const collectedField = collection[key];
|
|
27
|
+
if (cacheIdentify.field(field) && cacheIdentify.field(collectedField)) {
|
|
28
|
+
return field.get() !== collectedField.get();
|
|
26
29
|
}
|
|
27
|
-
return
|
|
30
|
+
return field !== collectedField;
|
|
28
31
|
});
|
|
29
|
-
|
|
30
|
-
if (!shallowEqual(collection, currentCollection)) {
|
|
32
|
+
if (hasChange) {
|
|
31
33
|
dispatcher == null ? void 0 : dispatcher(action);
|
|
32
34
|
}
|
|
33
35
|
};
|
|
@@ -49,11 +51,15 @@ function createSignal(store) {
|
|
|
49
51
|
signalStore.collection = signalStore.collection || {};
|
|
50
52
|
signalStore.collection[key] = val;
|
|
51
53
|
};
|
|
52
|
-
const getInstance = function getInstance2() {
|
|
53
|
-
|
|
54
|
+
const getInstance = function getInstance2(options) {
|
|
55
|
+
const { cutOff } = options != null ? options : {};
|
|
56
|
+
return extractInstance(
|
|
57
|
+
store.updater,
|
|
58
|
+
cutOff ? void 0 : collectUsedFields
|
|
59
|
+
);
|
|
54
60
|
};
|
|
55
|
-
const signal = function signal2() {
|
|
56
|
-
return getInstance();
|
|
61
|
+
const signal = function signal2(options) {
|
|
62
|
+
return getInstance(options);
|
|
57
63
|
};
|
|
58
64
|
signal.startStatistics = function startStatistics() {
|
|
59
65
|
signalStore.started = true;
|
package/esm/updater/index.js
CHANGED
|
@@ -48,7 +48,7 @@ function createUpdateFn(updater, middleWare) {
|
|
|
48
48
|
if (u.controlled) {
|
|
49
49
|
const controlledState = hasInitialState && !hasState ? args.initialState : state;
|
|
50
50
|
const instance = model(controlledState);
|
|
51
|
-
return __spreadProps(__spreadValues({}, u), { state, instance, model });
|
|
51
|
+
return __spreadProps(__spreadValues({}, u), { state: controlledState, instance, model });
|
|
52
52
|
}
|
|
53
53
|
if (u.isDestroyed) {
|
|
54
54
|
return u;
|
|
@@ -64,7 +64,7 @@ function createUpdateFn(updater, middleWare) {
|
|
|
64
64
|
const initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
65
65
|
return __spreadValues(__spreadProps(__spreadValues({}, u), {
|
|
66
66
|
model,
|
|
67
|
-
state,
|
|
67
|
+
state: initialState,
|
|
68
68
|
instance,
|
|
69
69
|
initialized: true,
|
|
70
70
|
token
|
package/esm/updater/notifier.js
CHANGED
|
@@ -76,8 +76,11 @@ function generateNotifier(updater, middleWare) {
|
|
|
76
76
|
type: null,
|
|
77
77
|
method: null
|
|
78
78
|
};
|
|
79
|
-
temporaryDispatches.forEach((
|
|
80
|
-
|
|
79
|
+
temporaryDispatches.forEach((d) => {
|
|
80
|
+
if (!d.accessible) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
d.dispatch(initializedAction);
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
86
|
const dispatch = function dispatch2(action) {
|
|
@@ -95,7 +98,15 @@ function generateNotifier(updater, middleWare) {
|
|
|
95
98
|
}
|
|
96
99
|
const notifyAction = function notifyAction2(act) {
|
|
97
100
|
const errors = [];
|
|
98
|
-
const
|
|
101
|
+
const dispatchWrap = simpleErrorProcess(errors);
|
|
102
|
+
const dispatchCallbacks = dispatches.map((d) => {
|
|
103
|
+
return dispatchWrap(function dispatchCallback(ac) {
|
|
104
|
+
if (!d.accessible) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
d.dispatch(ac);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
99
110
|
defaultNotifyImplement(dispatchCallbacks, act);
|
|
100
111
|
if (!errors.length) {
|
|
101
112
|
return { errors: void 0 };
|
package/esm/updater/tunnel.js
CHANGED
|
@@ -65,19 +65,20 @@ function generateTunnelCreator(updater) {
|
|
|
65
65
|
controlled: isControlled
|
|
66
66
|
} = updater;
|
|
67
67
|
const copied = [...dispatches, ...temporaryDispatches];
|
|
68
|
-
const exist = copied.
|
|
68
|
+
const exist = copied.some((d) => d.dispatch === dispatchFn);
|
|
69
69
|
if (exist) {
|
|
70
70
|
return updater.mutate((u) => __spreadProps(__spreadValues({}, u), { isDestroyed: false }));
|
|
71
71
|
}
|
|
72
|
+
const dispatcher = { dispatch: dispatchFn, accessible: true };
|
|
72
73
|
if (isControlled) {
|
|
73
74
|
return updater.mutate((u) => __spreadProps(__spreadValues({}, u), {
|
|
74
|
-
dispatches: [
|
|
75
|
+
dispatches: [dispatcher],
|
|
75
76
|
isDestroyed: false
|
|
76
77
|
}));
|
|
77
78
|
}
|
|
78
79
|
return updater.mutate((u, effect) => {
|
|
79
80
|
const { temporaryDispatches: tds, dispatches: ds } = u;
|
|
80
|
-
const nextTds = [...tds,
|
|
81
|
+
const nextTds = [...tds, dispatcher];
|
|
81
82
|
if (u.dispatching) {
|
|
82
83
|
return __spreadProps(__spreadValues({}, u), {
|
|
83
84
|
temporaryDispatches: nextTds,
|
|
@@ -94,7 +95,7 @@ function generateTunnelCreator(updater) {
|
|
|
94
95
|
method: null
|
|
95
96
|
};
|
|
96
97
|
nextTds.forEach((td) => {
|
|
97
|
-
td(initializedAction);
|
|
98
|
+
td.dispatch(initializedAction);
|
|
98
99
|
});
|
|
99
100
|
});
|
|
100
101
|
return __spreadProps(__spreadValues({}, u), {
|
|
@@ -104,15 +105,17 @@ function generateTunnelCreator(updater) {
|
|
|
104
105
|
});
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
return function tunnel(
|
|
108
|
+
return function tunnel(dispatchFn) {
|
|
108
109
|
function disconnect() {
|
|
109
110
|
updater.mutate((u) => {
|
|
110
111
|
const { dispatches: ds, temporaryDispatches: tds } = u;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
if (ds.length === nextDs.length && tds.length === nextTds.length) {
|
|
112
|
+
const found = [...ds, ...tds].find((d) => d.dispatch === dispatchFn);
|
|
113
|
+
if (!found) {
|
|
114
114
|
return u;
|
|
115
115
|
}
|
|
116
|
+
found.accessible = false;
|
|
117
|
+
const nextDs = ds.filter((d) => d !== found);
|
|
118
|
+
const nextTds = tds.filter((d) => d !== found);
|
|
116
119
|
return __spreadProps(__spreadValues({}, u), {
|
|
117
120
|
dispatches: nextDs,
|
|
118
121
|
temporaryDispatches: nextTds
|
|
@@ -121,7 +124,7 @@ function generateTunnelCreator(updater) {
|
|
|
121
124
|
}
|
|
122
125
|
return {
|
|
123
126
|
connect() {
|
|
124
|
-
subscribe(
|
|
127
|
+
subscribe(dispatchFn);
|
|
125
128
|
},
|
|
126
129
|
disconnect() {
|
|
127
130
|
disconnect();
|
package/index.d.ts
CHANGED
|
@@ -200,6 +200,10 @@ export declare interface model {
|
|
|
200
200
|
|
|
201
201
|
/** createSignal * */
|
|
202
202
|
|
|
203
|
+
export interface SignalOptions {
|
|
204
|
+
cutOff?: boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
203
207
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
204
208
|
declare interface SignalStore<
|
|
205
209
|
S = any,
|
|
@@ -209,7 +213,7 @@ declare interface SignalStore<
|
|
|
209
213
|
getToken: () => Token;
|
|
210
214
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
211
215
|
getSignal: () => {
|
|
212
|
-
(): T;
|
|
216
|
+
(options?: SignalOptions): T;
|
|
213
217
|
startStatistics: () => void;
|
|
214
218
|
stopStatistics: () => void;
|
|
215
219
|
subscribe: (dispatcher: Dispatch) => () => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "as-model",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.25",
|
|
5
5
|
"description": "This is a model state management tool",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Jimmy.Harding",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
},
|
|
27
27
|
"typings": "index.d.ts",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/jest": "^29.5.14",
|
|
30
29
|
"@babel/cli": "^7.27.2",
|
|
31
30
|
"@babel/core": "^7.27.4",
|
|
32
31
|
"@babel/eslint-parser": "^7.27.5",
|
|
@@ -34,6 +33,9 @@
|
|
|
34
33
|
"@babel/preset-env": "^7.27.2",
|
|
35
34
|
"@babel/preset-typescript": "^7.27.1",
|
|
36
35
|
"@babel/runtime": "^7.27.6",
|
|
36
|
+
"@pmnps/plugin-publish": "4.5.0",
|
|
37
|
+
"@types/jest": "^29.5.14",
|
|
38
|
+
"babel-jest": "29.7.0",
|
|
37
39
|
"esbuild": "^0.25.0",
|
|
38
40
|
"esbuild-plugin-es5": "2.1.1",
|
|
39
41
|
"eslint": "^8.49.0",
|
|
@@ -48,16 +50,14 @@
|
|
|
48
50
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
49
51
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
50
52
|
"eslint-webpack-plugin": "^4.0.1",
|
|
53
|
+
"jest": "29.7.0",
|
|
54
|
+
"jest-environment-jsdom": "29.7.0",
|
|
55
|
+
"pmnps": "^4.5.3",
|
|
51
56
|
"prettier": "^3.0.3",
|
|
52
57
|
"prettier-eslint": "^15.0.1",
|
|
53
58
|
"prettier-eslint-cli": "^7.1.0",
|
|
54
|
-
"typescript": "^4.9.5",
|
|
55
|
-
"babel-jest": "29.7.0",
|
|
56
|
-
"jest": "29.7.0",
|
|
57
|
-
"jest-environment-jsdom": "29.7.0",
|
|
58
59
|
"ts-node": "^10.8.1",
|
|
59
|
-
"
|
|
60
|
-
"@pmnps/plugin-publish": "4.5.0"
|
|
60
|
+
"typescript": "^4.9.5"
|
|
61
61
|
},
|
|
62
62
|
"keywords": [
|
|
63
63
|
"model",
|