as-model 0.1.18 → 0.1.20

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 CHANGED
@@ -141,6 +141,9 @@
141
141
  function modelStoreIdentifier() {
142
142
  return true;
143
143
  }
144
+ function tokenIdentifier() {
145
+ return true;
146
+ }
144
147
 
145
148
  // src/validation/index.ts
146
149
  var noStateAModelKey = "no-state-a-model-key";
@@ -177,11 +180,18 @@
177
180
  }
178
181
  return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
179
182
  }
183
+ function isToken(data) {
184
+ if (!data) {
185
+ return false;
186
+ }
187
+ return data.tokenIdentifier === tokenIdentifier && data.tokenIdentifier();
188
+ }
180
189
  var validations = {
181
190
  isInstanceFromNoStateModel,
182
191
  isModelKey,
183
192
  isModelStore,
184
- isModelUsage
193
+ isModelUsage,
194
+ isToken
185
195
  };
186
196
 
187
197
  // src/tools/proxy.ts
@@ -274,6 +284,20 @@
274
284
  };
275
285
  }
276
286
 
287
+ // src/updater/token.ts
288
+ function createToken() {
289
+ var value = {};
290
+ return {
291
+ isDifferent: function isDifferent(token) {
292
+ if (!isToken(token)) {
293
+ return true;
294
+ }
295
+ return token.value !== value;
296
+ },
297
+ value
298
+ };
299
+ }
300
+
277
301
  // src/updater/notifier.ts
278
302
  function defaultNotifyImplement(dispatches, action) {
279
303
  dispatches.forEach(function(callback) {
@@ -361,7 +385,8 @@
361
385
  return _object_spread_props(_object_spread({}, u), {
362
386
  state,
363
387
  instance: nextInstance,
364
- version: u.version + 1
388
+ version: u.version + 1,
389
+ token: createToken()
365
390
  });
366
391
  });
367
392
  }
@@ -580,6 +605,7 @@
580
605
  var _args_model;
581
606
  var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
582
607
  var state = "state" in args ? args.state : u.state;
608
+ var token = createToken();
583
609
  if (u.controlled) {
584
610
  var instance = model2(state);
585
611
  return _object_spread_props(_object_spread({}, u), {
@@ -601,27 +627,25 @@
601
627
  model: model2,
602
628
  state,
603
629
  instance: instance1,
604
- initialized: true
630
+ initialized: true,
631
+ token
605
632
  }), initializedUpdater);
606
633
  }
607
634
  if (Object.is(u.model, model2) && Object.is(u.state, state)) {
608
635
  return u;
609
636
  }
610
- var instance2 = model2(state);
611
637
  effect(function(up) {
612
638
  up.notify({
613
639
  type: null,
614
640
  method: null,
615
641
  prevInstance: u.instance,
616
- instance: instance2,
642
+ instance: u.instance,
617
643
  prevState: u.state,
618
644
  state
619
645
  });
620
646
  });
621
647
  return _object_spread_props(_object_spread({}, u), {
622
- state,
623
648
  model: model2,
624
- instance: instance2,
625
649
  initialized: true,
626
650
  cacheFields: {},
627
651
  cacheMethods: {}
@@ -639,6 +663,7 @@
639
663
  var updater = _object_spread({
640
664
  sidePayload: void 0,
641
665
  version: 0,
666
+ token: createToken(),
642
667
  isDestroyed: false,
643
668
  model: model2,
644
669
  instance: defaultInstance,
@@ -895,6 +920,9 @@
895
920
  var storeKey = store.key;
896
921
  return {
897
922
  key: storeKey,
923
+ getToken: function getToken() {
924
+ return store.getToken();
925
+ },
898
926
  subscribe: function subscribe(dispatcher) {
899
927
  return store.subscribe(enhance(dispatcher));
900
928
  },
@@ -1085,6 +1113,9 @@
1085
1113
  }
1086
1114
  return {
1087
1115
  key: store.key,
1116
+ getToken: function getToken() {
1117
+ return store.getToken();
1118
+ },
1088
1119
  subscribe: function subscribe(dispatcher) {
1089
1120
  return store.subscribe(enhance(dispatcher));
1090
1121
  },
@@ -1152,6 +1183,9 @@
1152
1183
  };
1153
1184
  var store = {
1154
1185
  key,
1186
+ getToken: function getToken() {
1187
+ return updater.token;
1188
+ },
1155
1189
  subscribe: function subscribe(dispatcher) {
1156
1190
  var _updater_createTunnel = updater.createTunnel(dispatcher), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
1157
1191
  connect();
@@ -7,8 +7,12 @@ function modelUsageIdentifier() {
7
7
  function modelStoreIdentifier() {
8
8
  return true;
9
9
  }
10
+ function tokenIdentifier() {
11
+ return true;
12
+ }
10
13
  export {
11
14
  modelKeyIdentifier,
12
15
  modelStoreIdentifier,
13
- modelUsageIdentifier
16
+ modelUsageIdentifier,
17
+ tokenIdentifier
14
18
  };
@@ -150,6 +150,9 @@ function createSelector(store, opts) {
150
150
  }
151
151
  return {
152
152
  key: store.key,
153
+ getToken() {
154
+ return store.getToken();
155
+ },
153
156
  subscribe(dispatcher) {
154
157
  return store.subscribe(enhance(dispatcher));
155
158
  },
@@ -35,6 +35,9 @@ function createSignal(store) {
35
35
  const { key: storeKey } = store;
36
36
  return {
37
37
  key: storeKey,
38
+ getToken() {
39
+ return store.getToken();
40
+ },
38
41
  subscribe(dispatcher) {
39
42
  return store.subscribe(enhance(dispatcher));
40
43
  },
@@ -92,6 +92,9 @@ function createStore(modelLike, config = {}) {
92
92
  };
93
93
  const store = {
94
94
  key,
95
+ getToken() {
96
+ return updater.token;
97
+ },
95
98
  subscribe(dispatcher) {
96
99
  const { connect, disconnect } = updater.createTunnel(dispatcher);
97
100
  connect();
@@ -24,6 +24,7 @@ import {
24
24
  createUnInitializedUpdater,
25
25
  destroy
26
26
  } from "./tunnel";
27
+ import { createToken } from "./token";
27
28
  function createInitializedUpdater(updater, middleWare) {
28
29
  const createTunnel = generateTunnelCreator(updater);
29
30
  return {
@@ -37,9 +38,10 @@ function createUpdateFn(updater, middleWare) {
37
38
  var _a;
38
39
  const model = (_a = args.model) != null ? _a : u.model;
39
40
  const state = "state" in args ? args.state : u.state;
41
+ const token = createToken();
40
42
  if (u.controlled) {
41
- const instance2 = model(state);
42
- return __spreadProps(__spreadValues({}, u), { state, instance: instance2, model });
43
+ const instance = model(state);
44
+ return __spreadProps(__spreadValues({}, u), { state, instance, model });
43
45
  }
44
46
  if (u.isDestroyed) {
45
47
  return u;
@@ -50,33 +52,31 @@ function createUpdateFn(updater, middleWare) {
50
52
  );
51
53
  }
52
54
  if (!u.initialized) {
53
- const instance2 = model(state);
55
+ const instance = model(state);
54
56
  const initializedUpdater = createInitializedUpdater(u, middleWare);
55
57
  return __spreadValues(__spreadProps(__spreadValues({}, u), {
56
58
  model,
57
59
  state,
58
- instance: instance2,
59
- initialized: true
60
+ instance,
61
+ initialized: true,
62
+ token
60
63
  }), initializedUpdater);
61
64
  }
62
65
  if (Object.is(u.model, model) && Object.is(u.state, state)) {
63
66
  return u;
64
67
  }
65
- const instance = model(state);
66
68
  effect((up) => {
67
69
  up.notify({
68
70
  type: null,
69
71
  method: null,
70
72
  prevInstance: u.instance,
71
- instance,
73
+ instance: u.instance,
72
74
  prevState: u.state,
73
75
  state
74
76
  });
75
77
  });
76
78
  return __spreadProps(__spreadValues({}, u), {
77
- state,
78
79
  model,
79
- instance,
80
80
  initialized: true,
81
81
  cacheFields: {},
82
82
  cacheMethods: {}
@@ -93,6 +93,7 @@ function createUpdater(model, middleWare, config = {}) {
93
93
  const updater = __spreadValues({
94
94
  sidePayload: void 0,
95
95
  version: 0,
96
+ token: createToken(),
96
97
  isDestroyed: false,
97
98
  model,
98
99
  instance: defaultInstance,
@@ -18,6 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { simpleErrorProcess } from "../tools";
21
+ import { createToken } from "./token";
21
22
  function defaultNotifyImplement(dispatches, action) {
22
23
  dispatches.forEach((callback) => {
23
24
  callback(action);
@@ -88,7 +89,8 @@ function generateNotifier(updater, middleWare) {
88
89
  updater.mutate((u) => __spreadProps(__spreadValues({}, u), {
89
90
  state,
90
91
  instance: nextInstance,
91
- version: u.version + 1
92
+ version: u.version + 1,
93
+ token: createToken()
92
94
  }));
93
95
  }
94
96
  const notifyAction = function notifyAction2(act) {
@@ -0,0 +1,16 @@
1
+ import { isToken } from "../validation";
2
+ function createToken() {
3
+ const value = {};
4
+ return {
5
+ isDifferent(token) {
6
+ if (!isToken(token)) {
7
+ return true;
8
+ }
9
+ return token.value !== value;
10
+ },
11
+ value
12
+ };
13
+ }
14
+ export {
15
+ createToken
16
+ };
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  modelKeyIdentifier,
3
3
  modelStoreIdentifier,
4
- modelUsageIdentifier
4
+ modelUsageIdentifier,
5
+ tokenIdentifier
5
6
  } from "../identifiers";
6
7
  const noStateAModelKey = "no-state-a-model-key";
7
8
  function createNoStateModel() {
@@ -39,16 +40,24 @@ function isModelStore(data) {
39
40
  }
40
41
  return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
41
42
  }
43
+ function isToken(data) {
44
+ if (!data) {
45
+ return false;
46
+ }
47
+ return data.tokenIdentifier === tokenIdentifier && data.tokenIdentifier();
48
+ }
42
49
  const validations = {
43
50
  isInstanceFromNoStateModel,
44
51
  isModelKey,
45
52
  isModelStore,
46
- isModelUsage
53
+ isModelUsage,
54
+ isToken
47
55
  };
48
56
  export {
49
57
  createNoStateModel,
50
58
  isModelKey,
51
59
  isModelStore,
52
60
  isModelUsage,
61
+ isToken,
53
62
  validations
54
63
  };
package/index.d.ts CHANGED
@@ -41,6 +41,11 @@ export declare type Action<S = any, T extends ModelInstance = ModelInstance> = {
41
41
  prevInstance?: T;
42
42
  };
43
43
 
44
+ export interface Token {
45
+ isDifferent: (token: Token) => boolean;
46
+ value: unknown;
47
+ }
48
+
44
49
  export declare type Dispatch = (action: Action) => any;
45
50
 
46
51
  export declare interface Key<
@@ -93,8 +98,13 @@ export declare interface Store<
93
98
  R extends (instance: () => T) => any = (instance: () => T) => T
94
99
  > extends StoreIndex<S, T, R> {
95
100
  subscribe: (dispatcher: Dispatch) => () => void;
101
+ getToken: () => Token;
96
102
  getInstance: () => T;
97
- update: (args?: { model?: Model<S, T>; initialState?: S; state?: S }) => void;
103
+ update: (args?: {
104
+ model?: Model<S, T>;
105
+ key?: Key<S, T, R>;
106
+ state?: S;
107
+ }) => void;
98
108
  destroy: () => void;
99
109
  payload: <P>(
100
110
  callback?: (payload: P | undefined) => P | undefined
@@ -195,6 +205,7 @@ declare interface SignalStore<
195
205
  T extends ModelInstance = any,
196
206
  R extends (instance: () => T) => any = (instance: () => T) => any
197
207
  > extends StoreIndex<S, T, R> {
208
+ getToken: () => Token;
198
209
  subscribe: (dispatcher: Dispatch) => () => void;
199
210
  getSignal: () => {
200
211
  (): T;
@@ -230,6 +241,7 @@ declare interface SelectorStore<
230
241
  T extends ModelInstance = any,
231
242
  R extends (instance: () => T) => any = (instance: () => T) => any
232
243
  > extends StoreIndex<S, T, R> {
244
+ getToken: () => Token;
233
245
  subscribe: (dispatcher: Dispatch) => () => void;
234
246
  select: SelectMethod<T, R>;
235
247
  }
package/package.json CHANGED
@@ -1,68 +1,68 @@
1
- {
2
- "private": false,
3
- "name": "as-model",
4
- "version": "0.1.18",
5
- "description": "This is a model state management tool",
6
- "license": "MIT",
7
- "author": "Jimmy.Harding",
8
- "homepage": "https://github.com/filefoxper/a-model",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/filefoxper/a-model"
12
- },
13
- "main": "dist/index.js",
14
- "module": "esm/index.js",
15
- "files": [
16
- "dist",
17
- "esm",
18
- "index.d.ts"
19
- ],
20
- "scripts": {
21
- "build": "node ./build.js",
22
- "docs": "docsify serve ./docs",
23
- "lint": "eslint src --fix --ext .ts,.tsx ",
24
- "lint-init": "eslint --init",
25
- "test": "jest --coverage"
26
- },
27
- "typings": "index.d.ts",
28
- "devDependencies": {
29
- "@types/jest": "^29.5.14",
30
- "@babel/cli": "^7.27.2",
31
- "@babel/core": "^7.27.4",
32
- "@babel/eslint-parser": "^7.27.5",
33
- "@babel/plugin-transform-runtime": "^7.27.4",
34
- "@babel/preset-env": "^7.27.2",
35
- "@babel/preset-typescript": "^7.27.1",
36
- "@babel/runtime": "^7.27.6",
37
- "esbuild": "^0.25.0",
38
- "esbuild-plugin-es5": "2.1.1",
39
- "eslint": "^8.49.0",
40
- "eslint-config-airbnb": "^19.0.4",
41
- "eslint-config-airbnb-typescript": "^17.1.0",
42
- "eslint-config-prettier": "^9.0.0",
43
- "eslint-import-resolver-typescript": "^3.6.0",
44
- "eslint-plugin-import": "^2.28.1",
45
- "eslint-plugin-jsx-a11y": "^6.7.1",
46
- "eslint-plugin-prettier": "^5.0.0",
47
- "eslint-plugin-react": "^7.33.2",
48
- "eslint-plugin-react-hooks": "^4.6.0",
49
- "eslint-plugin-unused-imports": "^2.0.0",
50
- "eslint-webpack-plugin": "^4.0.1",
51
- "prettier": "^3.0.3",
52
- "prettier-eslint": "^15.0.1",
53
- "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
- "ts-node": "^10.8.1",
59
- "pmnps": "^4.5.3",
60
- "@pmnps/plugin-publish": "4.5.0"
61
- },
62
- "keywords": [
63
- "model",
64
- "state",
65
- "state-management",
66
- "typescript"
67
- ]
68
- }
1
+ {
2
+ "private": false,
3
+ "name": "as-model",
4
+ "version": "0.1.20",
5
+ "description": "This is a model state management tool",
6
+ "license": "MIT",
7
+ "author": "Jimmy.Harding",
8
+ "homepage": "https://github.com/filefoxper/a-model",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/filefoxper/a-model"
12
+ },
13
+ "main": "dist/index.js",
14
+ "module": "esm/index.js",
15
+ "files": [
16
+ "dist",
17
+ "esm",
18
+ "index.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "node ./build.js",
22
+ "docs": "docsify serve ./docs",
23
+ "lint": "eslint src --fix --ext .ts,.tsx ",
24
+ "lint-init": "eslint --init",
25
+ "test": "jest --coverage"
26
+ },
27
+ "typings": "index.d.ts",
28
+ "devDependencies": {
29
+ "@types/jest": "^29.5.14",
30
+ "@babel/cli": "^7.27.2",
31
+ "@babel/core": "^7.27.4",
32
+ "@babel/eslint-parser": "^7.27.5",
33
+ "@babel/plugin-transform-runtime": "^7.27.4",
34
+ "@babel/preset-env": "^7.27.2",
35
+ "@babel/preset-typescript": "^7.27.1",
36
+ "@babel/runtime": "^7.27.6",
37
+ "esbuild": "^0.25.0",
38
+ "esbuild-plugin-es5": "2.1.1",
39
+ "eslint": "^8.49.0",
40
+ "eslint-config-airbnb": "^19.0.4",
41
+ "eslint-config-airbnb-typescript": "^17.1.0",
42
+ "eslint-config-prettier": "^9.0.0",
43
+ "eslint-import-resolver-typescript": "^3.6.0",
44
+ "eslint-plugin-import": "^2.28.1",
45
+ "eslint-plugin-jsx-a11y": "^6.7.1",
46
+ "eslint-plugin-prettier": "^5.0.0",
47
+ "eslint-plugin-react": "^7.33.2",
48
+ "eslint-plugin-react-hooks": "^4.6.0",
49
+ "eslint-plugin-unused-imports": "^2.0.0",
50
+ "eslint-webpack-plugin": "^4.0.1",
51
+ "prettier": "^3.0.3",
52
+ "prettier-eslint": "^15.0.1",
53
+ "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
+ "ts-node": "^10.8.1",
59
+ "pmnps": "^4.5.3",
60
+ "@pmnps/plugin-publish": "4.5.0"
61
+ },
62
+ "keywords": [
63
+ "model",
64
+ "state",
65
+ "state-management",
66
+ "typescript"
67
+ ]
68
+ }