as-model 0.3.2 → 0.3.4
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 +558 -558
- package/dist/index.js +2 -2
- package/esm/key/index.js +2 -2
- package/index.d.ts +12 -15
- package/package.json +68 -68
package/dist/index.js
CHANGED
|
@@ -1362,10 +1362,10 @@ function createStores(modelKeys) {
|
|
|
1362
1362
|
destroyed: false
|
|
1363
1363
|
};
|
|
1364
1364
|
var storeUnits = modelKeys.map(function(modelKey) {
|
|
1365
|
-
if (typeof modelKey === "function") {
|
|
1365
|
+
if (typeof modelKey === "function" && typeof modelKey.createStore === "function") {
|
|
1366
1366
|
return modelKey.createStore();
|
|
1367
1367
|
}
|
|
1368
|
-
var k = modelKey.key;
|
|
1368
|
+
var k = typeof modelKey === "function" ? modelKey : modelKey.key;
|
|
1369
1369
|
return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config2), {
|
|
1370
1370
|
state: k.defaultState
|
|
1371
1371
|
}) : config2);
|
package/esm/key/index.js
CHANGED
|
@@ -33,10 +33,10 @@ createKey.isModelKey = isModelKey;
|
|
|
33
33
|
function createStores(modelKeys, config = {}) {
|
|
34
34
|
const state = { destroyed: false };
|
|
35
35
|
const storeUnits = modelKeys.map((modelKey) => {
|
|
36
|
-
if (typeof modelKey === "function") {
|
|
36
|
+
if (typeof modelKey === "function" && typeof modelKey.createStore === "function") {
|
|
37
37
|
return modelKey.createStore();
|
|
38
38
|
}
|
|
39
|
-
const k = modelKey.key;
|
|
39
|
+
const k = typeof modelKey === "function" ? modelKey : modelKey.key;
|
|
40
40
|
return createStore(
|
|
41
41
|
k,
|
|
42
42
|
"defaultState" in k ? __spreadProps(__spreadValues({}, config), { state: k.defaultState }) : config
|
package/index.d.ts
CHANGED
|
@@ -27,9 +27,7 @@ declare type ValidInstance<S, T extends ModelInstance> = {
|
|
|
27
27
|
: T[K];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export declare type Model
|
|
31
|
-
state: S
|
|
32
|
-
) => ValidInstance<S, T>;
|
|
30
|
+
export declare type Model = (state: any) => any;
|
|
33
31
|
|
|
34
32
|
export type PickState<R extends Model> = R extends (state: infer S) => any
|
|
35
33
|
? S
|
|
@@ -57,7 +55,7 @@ export interface Token {
|
|
|
57
55
|
export declare type Dispatch = (action: Action) => any;
|
|
58
56
|
|
|
59
57
|
export declare interface Key<
|
|
60
|
-
M extends Model =
|
|
58
|
+
M extends Model = Model,
|
|
61
59
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
62
60
|
> extends M {
|
|
63
61
|
(s: PickState<M>): Instance<M>;
|
|
@@ -68,7 +66,7 @@ export declare interface Key<
|
|
|
68
66
|
defaultState?: PickState<M>;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
declare interface UpdaterStore<S = any, T
|
|
69
|
+
declare interface UpdaterStore<S = any, T = any> {
|
|
72
70
|
getState: () => { state: S; instance: T };
|
|
73
71
|
dispatch: (action: Action) => void;
|
|
74
72
|
}
|
|
@@ -89,14 +87,14 @@ export declare interface Config {
|
|
|
89
87
|
/** createStore * */
|
|
90
88
|
|
|
91
89
|
export declare interface StoreIndex<
|
|
92
|
-
M extends Model =
|
|
90
|
+
M extends Model = Model,
|
|
93
91
|
R extends undefined | ((instance: () => Instance<M>) => any) = any
|
|
94
92
|
> {
|
|
95
93
|
key: Key<M, R>;
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
export declare interface Store<
|
|
99
|
-
M extends Model =
|
|
97
|
+
M extends Model = Model,
|
|
100
98
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
101
99
|
> extends StoreIndex<M, R> {
|
|
102
100
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
@@ -128,16 +126,15 @@ export declare function createStore<
|
|
|
128
126
|
/** createKey * */
|
|
129
127
|
|
|
130
128
|
export declare interface ModelKey<
|
|
131
|
-
M extends Model =
|
|
129
|
+
M extends Model = Model,
|
|
132
130
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
133
131
|
> extends Key<M, R> {
|
|
134
|
-
(s: PickState<M>): Instance<M>;
|
|
135
132
|
createStore: <D extends PickState<M>>(initialState?: D) => Store<M, R>;
|
|
136
133
|
extends: <E extends Record<string, any>>(e: E) => ModelKey<M, R> & E;
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
export declare function createKey<
|
|
140
|
-
M extends Model =
|
|
137
|
+
M extends Model = Model,
|
|
141
138
|
D extends PickState<M>,
|
|
142
139
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
143
140
|
>(model: M | ModelUsage<M, R>, initialState?: D): ModelKey<M, R>;
|
|
@@ -146,7 +143,7 @@ export declare function createKey<
|
|
|
146
143
|
|
|
147
144
|
export declare interface StoreCollection {
|
|
148
145
|
find: <
|
|
149
|
-
M extends Model =
|
|
146
|
+
M extends Model = Model,
|
|
150
147
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
151
148
|
>(
|
|
152
149
|
key: Key<M, R> | StoreIndex<M, R>
|
|
@@ -210,7 +207,7 @@ export interface SignalOptions {
|
|
|
210
207
|
|
|
211
208
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
212
209
|
declare interface SignalStore<
|
|
213
|
-
M extends Model =
|
|
210
|
+
M extends Model = Model,
|
|
214
211
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
215
212
|
> extends StoreIndex<M, R> {
|
|
216
213
|
getToken: () => Token;
|
|
@@ -229,7 +226,7 @@ declare interface SignalStore<
|
|
|
229
226
|
}
|
|
230
227
|
|
|
231
228
|
export declare function createSignal<
|
|
232
|
-
M extends Model =
|
|
229
|
+
M extends Model = Model,
|
|
233
230
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
234
231
|
>(store: Store<M, R>): SignalStore<M, R>;
|
|
235
232
|
|
|
@@ -264,7 +261,7 @@ declare type SelectMethod<
|
|
|
264
261
|
|
|
265
262
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
266
263
|
declare interface SelectorStore<
|
|
267
|
-
M extends Model =
|
|
264
|
+
M extends Model = Model,
|
|
268
265
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
269
266
|
> extends StoreIndex<M, R> {
|
|
270
267
|
getToken: () => Token;
|
|
@@ -277,7 +274,7 @@ declare interface SelectorOption<T = any> {
|
|
|
277
274
|
}
|
|
278
275
|
|
|
279
276
|
export declare function createSelector<
|
|
280
|
-
M extends Model =
|
|
277
|
+
M extends Model = Model,
|
|
281
278
|
R extends undefined | ((instance: () => Instance<M>) => any) = undefined
|
|
282
279
|
>(store: Store<M, R>, opts?: SelectorOption): SelectorStore<M, R>;
|
|
283
280
|
|
package/package.json
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"private": false,
|
|
3
|
-
"name": "as-model",
|
|
4
|
-
"version": "0.3.
|
|
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
|
-
"@babel/cli": "^7.27.2",
|
|
30
|
-
"@babel/core": "^7.27.4",
|
|
31
|
-
"@babel/eslint-parser": "^7.27.5",
|
|
32
|
-
"@babel/plugin-transform-runtime": "^7.27.4",
|
|
33
|
-
"@babel/preset-env": "^7.27.2",
|
|
34
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
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",
|
|
39
|
-
"esbuild": "^0.25.0",
|
|
40
|
-
"esbuild-plugin-es5": "2.1.1",
|
|
41
|
-
"eslint": "^8.49.0",
|
|
42
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
43
|
-
"eslint-config-airbnb-typescript": "^17.1.0",
|
|
44
|
-
"eslint-config-prettier": "^9.0.0",
|
|
45
|
-
"eslint-import-resolver-typescript": "^3.6.0",
|
|
46
|
-
"eslint-plugin-import": "^2.28.1",
|
|
47
|
-
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
48
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
49
|
-
"eslint-plugin-react": "^7.33.2",
|
|
50
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
|
-
"eslint-plugin-unused-imports": "^2.0.0",
|
|
52
|
-
"eslint-webpack-plugin": "^4.0.1",
|
|
53
|
-
"jest": "29.7.0",
|
|
54
|
-
"jest-environment-jsdom": "29.7.0",
|
|
55
|
-
"pmnps": "^4.5.3",
|
|
56
|
-
"prettier": "^3.0.3",
|
|
57
|
-
"prettier-eslint": "^15.0.1",
|
|
58
|
-
"prettier-eslint-cli": "^7.1.0",
|
|
59
|
-
"ts-node": "^10.8.1",
|
|
60
|
-
"typescript": "^4.9.5"
|
|
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.3.4",
|
|
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
|
+
"@babel/cli": "^7.27.2",
|
|
30
|
+
"@babel/core": "^7.27.4",
|
|
31
|
+
"@babel/eslint-parser": "^7.27.5",
|
|
32
|
+
"@babel/plugin-transform-runtime": "^7.27.4",
|
|
33
|
+
"@babel/preset-env": "^7.27.2",
|
|
34
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
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",
|
|
39
|
+
"esbuild": "^0.25.0",
|
|
40
|
+
"esbuild-plugin-es5": "2.1.1",
|
|
41
|
+
"eslint": "^8.49.0",
|
|
42
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
43
|
+
"eslint-config-airbnb-typescript": "^17.1.0",
|
|
44
|
+
"eslint-config-prettier": "^9.0.0",
|
|
45
|
+
"eslint-import-resolver-typescript": "^3.6.0",
|
|
46
|
+
"eslint-plugin-import": "^2.28.1",
|
|
47
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
48
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
49
|
+
"eslint-plugin-react": "^7.33.2",
|
|
50
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
|
+
"eslint-plugin-unused-imports": "^2.0.0",
|
|
52
|
+
"eslint-webpack-plugin": "^4.0.1",
|
|
53
|
+
"jest": "29.7.0",
|
|
54
|
+
"jest-environment-jsdom": "29.7.0",
|
|
55
|
+
"pmnps": "^4.5.3",
|
|
56
|
+
"prettier": "^3.0.3",
|
|
57
|
+
"prettier-eslint": "^15.0.1",
|
|
58
|
+
"prettier-eslint-cli": "^7.1.0",
|
|
59
|
+
"ts-node": "^10.8.1",
|
|
60
|
+
"typescript": "^4.9.5"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"model",
|
|
64
|
+
"state",
|
|
65
|
+
"state-management",
|
|
66
|
+
"typescript"
|
|
67
|
+
]
|
|
68
|
+
}
|