as-model 0.1.14 → 0.1.16

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
@@ -677,7 +677,6 @@
677
677
  }
678
678
  return method2.apply(void 0, _to_consumable_array(args));
679
679
  };
680
- Object.assign(replace, method2());
681
680
  replace.identifier = cacheIdentify.method;
682
681
  return replace;
683
682
  }
@@ -45,7 +45,6 @@ function createMethod(method) {
45
45
  const replace = function replace2(...args) {
46
46
  return method(...args);
47
47
  };
48
- Object.assign(replace, method());
49
48
  replace.identifier = cacheIdentify.method;
50
49
  return replace;
51
50
  }
package/index.d.ts CHANGED
@@ -1,298 +1,298 @@
1
- declare interface ModelInstance {
2
- [key: string]: any;
3
- [key: number]: any;
4
- }
5
-
6
- declare type FieldStructure<R = any> = {
7
- callback: () => R;
8
- deps: any[] | undefined;
9
- identifier: (d: any) => d is FieldStructure<R>;
10
- value: R;
11
- get: () => R;
12
- };
13
-
14
- declare type MethodStructure<
15
- R extends (...args: any[]) => any = (...args: any[]) => any
16
- > = R & {
17
- identifier: (d: any) => d is MethodStructure;
18
- };
19
-
20
- declare type ValidInstance<S, T extends ModelInstance> = {
21
- [K in keyof T]: T[K] extends
22
- | ((...args: any[]) => S)
23
- | (((...args: any[]) => any) & { identifier: (d: any) => boolean })
24
- ? T[K]
25
- : T[K] extends (...args: any[]) => any
26
- ? never
27
- : T[K];
28
- };
29
-
30
- export declare type Model<S, T extends ModelInstance> = (
31
- state: S
32
- ) => ValidInstance<S, T>;
33
-
34
- export declare type Action<S = any, T extends ModelInstance = ModelInstance> = {
35
- type: null | string;
36
- method: null | ((...args: any[]) => any);
37
- params?: any[];
38
- state: S;
39
- prevState?: S;
40
- instance: T;
41
- prevInstance?: T;
42
- };
43
-
44
- declare type Dispatch = (action: Action) => any;
45
-
46
- export declare interface Key<
47
- S = any,
48
- T extends ModelInstance = any,
49
- R extends (instance: () => T) => any = (instance: () => T) => T
50
- > extends Model<S, T> {
51
- (s: S): T;
52
- source: Model<S, T>;
53
- selector: R;
54
- modelKeyIdentifier: () => boolean;
55
- [k: string]: any;
56
- defaultState?: S;
57
- }
58
-
59
- declare interface UpdaterStore<
60
- S = any,
61
- T extends ModelInstance = ModelInstance
62
- > {
63
- getState: () => { state: S; instance: T };
64
- dispatch: (action: Action) => void;
65
- }
66
-
67
- export declare type MiddleWare = (
68
- store: UpdaterStore
69
- ) => (next: Dispatch) => (action: Action) => void;
70
-
71
- export declare interface Config {
72
- middleWares?: MiddleWare[];
73
- controlled?: boolean;
74
- batchNotify?: (
75
- listeners: ((action: Action) => void)[],
76
- action: Action
77
- ) => void;
78
- }
79
-
80
- /** createStore * */
81
-
82
- export declare interface StoreIndex<
83
- S = any,
84
- T extends ModelInstance = any,
85
- R extends (instance: () => T) => any = (instance: () => T) => T
86
- > {
87
- key: Key<S, T, R>;
88
- }
89
-
90
- export declare interface Store<
91
- S = any,
92
- T extends ModelInstance = any,
93
- R extends (instance: () => T) => any = (instance: () => T) => T
94
- > extends StoreIndex<S, T, R> {
95
- subscribe: (dispatcher: Dispatch) => () => void;
96
- getInstance: () => T;
97
- update: (args?: { model?: Model<S, T>; initialState?: S; state?: S }) => void;
98
- destroy: () => void;
99
- payload: <P>(
100
- callback?: (payload: P | undefined) => P | undefined
101
- ) => P | undefined;
102
- isDestroyed: () => boolean;
103
- extends: <E extends Record<string, any>>(e: E) => Store<S, T, R> & E;
104
- }
105
-
106
- export declare function createStore<
107
- S,
108
- T extends ModelInstance,
109
- D extends S,
110
- R extends (instance: () => T) => any = (instance: () => T) => T
111
- >(
112
- model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
113
- state?: D
114
- ): Store<S, T, R>;
115
-
116
- /** createKey * */
117
-
118
- export declare interface ModelKey<
119
- S = any,
120
- T extends ModelInstance = any,
121
- R extends (instance: () => T) => any = (instance: () => T) => T
122
- > extends Key<S, T, R> {
123
- (s: S): T;
124
- createStore: <D extends S>(state?: D) => Store<S, T, R>;
125
- extends: <E extends Record<string, any>>(e: E) => ModelKey<S, T, R> & E;
126
- }
127
-
128
- export declare function createKey<
129
- S,
130
- T extends ModelInstance,
131
- D extends S,
132
- R extends (instance: () => T) => any = (instance: () => T) => T
133
- >(model: Model<S, T> | ModelUsage<S, T, R>, state?: D): ModelKey<S, T, R>;
134
-
135
- /** createStores * */
136
-
137
- export declare interface StoreCollection {
138
- find: <
139
- S,
140
- T extends ModelInstance,
141
- R extends (instance: () => T) => any = (instance: () => T) => T
142
- >(
143
- key: Key<S, T, R> | StoreIndex<S, T, R>
144
- ) => Store<S, T, R> | null;
145
- update: (...keys: (ModelKey | StoreIndex)[]) => void;
146
- keys: () => Key[];
147
- destroy: () => void;
148
- }
149
-
150
- export declare function createStores(
151
- ...modelKeys: (ModelKey | StoreIndex)[]
152
- ): StoreCollection;
153
-
154
- /** model API * */
155
-
156
- export declare interface ModelUsage<
157
- S,
158
- T extends ModelInstance,
159
- R extends (instance: () => T) => any = (instance: () => T) => T
160
- > {
161
- (s: S): ValidInstance<S, T>;
162
- createKey: <D extends S>(state?: D) => ModelKey<S, T, R>;
163
- createStore: <D extends S>(state?: D) => Store<S, T, R>;
164
- select: <C extends (instance: () => T) => any = (instance: () => T) => T>(
165
- s: C
166
- ) => ModelUsage<S, T, C>;
167
- selector: R;
168
- extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
169
- }
170
-
171
- // eslint-disable-next-line @typescript-eslint/naming-convention
172
- export declare interface model {
173
- <
174
- S,
175
- T extends ModelInstance,
176
- R extends (instance: () => T) => any = (instance: () => T) => T
177
- >(
178
- modelFn: Model<S, T>,
179
- s?: R
180
- ): ModelUsage<S, T, R>;
181
- createField: <P extends () => any>(
182
- callback: P,
183
- deps?: any[]
184
- ) => FieldStructure<ReturnType<P>>;
185
- createMethod: <P extends (...args: any[]) => any = (...args: any[]) => any>(
186
- method: P
187
- ) => MethodStructure<P>;
188
- }
189
-
190
- /** createSignal * */
191
-
192
- // eslint-disable-next-line @typescript-eslint/no-redeclare
193
- declare interface SignalStore<
194
- S = any,
195
- T extends ModelInstance = any,
196
- R extends (instance: () => T) => any = (instance: () => T) => any
197
- > extends StoreIndex<S, T, R> {
198
- subscribe: (dispatcher: Dispatch) => () => void;
199
- getSignal: () => {
200
- (): T;
201
- startStatistics: () => void;
202
- stopStatistics: () => void;
203
- subscribe: (dispatcher: Dispatch) => () => void;
204
- store: Store<S, T, R>;
205
- };
206
- }
207
-
208
- export declare function createSignal<
209
- S,
210
- T extends ModelInstance,
211
- R extends (instance: () => T) => any = (instance: () => T) => any
212
- >(store: Store<S, T, R>): SignalStore<S, T, R>;
213
-
214
- /** createSelector * */
215
-
216
- declare type SelectMethod<
217
- T extends ModelInstance = any,
218
- R extends (instance: () => T) => any = (instance: () => T) => any
219
- > = {
220
- (): ReturnType<R>;
221
- <C extends (instance: () => T) => any>(selector: C): ReturnType<C>;
222
- <C extends (instance: () => T) => any>(
223
- selector?: C
224
- ): ReturnType<R> | ReturnType<C>;
225
- };
226
-
227
- // eslint-disable-next-line @typescript-eslint/no-redeclare
228
- declare interface SelectorStore<
229
- S = any,
230
- T extends ModelInstance = any,
231
- R extends (instance: () => T) => any = (instance: () => T) => any
232
- > extends StoreIndex<S, T, R> {
233
- subscribe: (dispatcher: Dispatch) => () => void;
234
- select: SelectMethod<T, R>;
235
- }
236
-
237
- declare interface SelectorOption<T = any> {
238
- equality?: (current: T, next: T) => boolean;
239
- }
240
-
241
- export declare function createSelector<
242
- S,
243
- T extends ModelInstance,
244
- R extends (instance: () => T) => any = (instance: () => T) => any
245
- >(store: Store<S, T, R>, opts?: SelectorOption): SelectorStore<S, T, R>;
246
-
247
- /** config * */
248
- export declare function config(configuration: Config): {
249
- createStore: <
250
- S,
251
- T extends ModelInstance,
252
- D extends S,
253
- R extends (instance: () => T) => any = (instance: () => T) => T
254
- >(
255
- model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
256
- state?: D
257
- ) => Store<S, T, R>;
258
- createKey: <
259
- S,
260
- T extends ModelInstance,
261
- D extends S,
262
- R extends (instance: () => T) => any = (instance: () => T) => T
263
- >(
264
- model: Model<S, T> | ModelUsage<S, T, R>,
265
- state?: D
266
- ) => ModelKey<S, T, R>;
267
- createStores: (...modelKeys: (ModelKey | StoreIndex)[]) => StoreCollection;
268
- model: model;
269
- };
270
-
271
- /** validations * */
272
- export declare const validations: {
273
- isInstanceFromNoStateModel: (instance: any) => boolean;
274
- isModelKey: <
275
- S,
276
- T extends ModelInstance,
277
- R extends (ins: () => T) => any = (ins: () => T) => T
278
- >(
279
- data: any
280
- ) => data is ModelKey<S, T, R>;
281
- isModelStore: <
282
- S,
283
- T extends ModelInstance,
284
- R extends (ins: () => T) => any = (ins: () => T) => T
285
- >(
286
- data: any
287
- ) => data is Store<S, T, R>;
288
- isModelUsage: <
289
- S,
290
- T extends ModelInstance,
291
- R extends (ins: () => T) => any = (ins: () => T) => T
292
- >(
293
- data: any
294
- ) => data is ModelUsage<S, T, R>;
295
- };
296
-
297
- /** tools * */
298
- export declare function shallowEqual(prev: any, current: any): boolean;
1
+ declare interface ModelInstance {
2
+ [key: string]: any;
3
+ [key: number]: any;
4
+ }
5
+
6
+ declare type FieldStructure<R = any> = {
7
+ callback: () => R;
8
+ deps: any[] | undefined;
9
+ identifier: (d: any) => d is FieldStructure<R>;
10
+ value: R;
11
+ get: () => R;
12
+ };
13
+
14
+ declare type MethodStructure<
15
+ R extends (...args: any[]) => any = (...args: any[]) => any
16
+ > = R & {
17
+ identifier: (d: any) => d is MethodStructure;
18
+ };
19
+
20
+ declare type ValidInstance<S, T extends ModelInstance> = {
21
+ [K in keyof T]: T[K] extends
22
+ | ((...args: any[]) => S)
23
+ | (((...args: any[]) => any) & { identifier: (d: any) => boolean })
24
+ ? T[K]
25
+ : T[K] extends (...args: any[]) => any
26
+ ? never
27
+ : T[K];
28
+ };
29
+
30
+ export declare type Model<S, T extends ModelInstance> = (
31
+ state: S
32
+ ) => ValidInstance<S, T>;
33
+
34
+ export declare type Action<S = any, T extends ModelInstance = ModelInstance> = {
35
+ type: null | string;
36
+ method: null | ((...args: any[]) => any);
37
+ params?: any[];
38
+ state: S;
39
+ prevState?: S;
40
+ instance: T;
41
+ prevInstance?: T;
42
+ };
43
+
44
+ declare type Dispatch = (action: Action) => any;
45
+
46
+ export declare interface Key<
47
+ S = any,
48
+ T extends ModelInstance = any,
49
+ R extends (instance: () => T) => any = (instance: () => T) => T
50
+ > extends Model<S, T> {
51
+ (s: S): T;
52
+ source: Model<S, T>;
53
+ selector: R;
54
+ modelKeyIdentifier: () => boolean;
55
+ [k: string]: any;
56
+ defaultState?: S;
57
+ }
58
+
59
+ declare interface UpdaterStore<
60
+ S = any,
61
+ T extends ModelInstance = ModelInstance
62
+ > {
63
+ getState: () => { state: S; instance: T };
64
+ dispatch: (action: Action) => void;
65
+ }
66
+
67
+ export declare type MiddleWare = (
68
+ store: UpdaterStore
69
+ ) => (next: Dispatch) => (action: Action) => void;
70
+
71
+ export declare interface Config {
72
+ middleWares?: MiddleWare[];
73
+ controlled?: boolean;
74
+ batchNotify?: (
75
+ listeners: ((action: Action) => void)[],
76
+ action: Action
77
+ ) => void;
78
+ }
79
+
80
+ /** createStore * */
81
+
82
+ export declare interface StoreIndex<
83
+ S = any,
84
+ T extends ModelInstance = any,
85
+ R extends (instance: () => T) => any = (instance: () => T) => T
86
+ > {
87
+ key: Key<S, T, R>;
88
+ }
89
+
90
+ export declare interface Store<
91
+ S = any,
92
+ T extends ModelInstance = any,
93
+ R extends (instance: () => T) => any = (instance: () => T) => T
94
+ > extends StoreIndex<S, T, R> {
95
+ subscribe: (dispatcher: Dispatch) => () => void;
96
+ getInstance: () => T;
97
+ update: (args?: { model?: Model<S, T>; initialState?: S; state?: S }) => void;
98
+ destroy: () => void;
99
+ payload: <P>(
100
+ callback?: (payload: P | undefined) => P | undefined
101
+ ) => P | undefined;
102
+ isDestroyed: () => boolean;
103
+ extends: <E extends Record<string, any>>(e: E) => Store<S, T, R> & E;
104
+ }
105
+
106
+ export declare function createStore<
107
+ S,
108
+ T extends ModelInstance,
109
+ D extends S,
110
+ R extends (instance: () => T) => any = (instance: () => T) => T
111
+ >(
112
+ model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
113
+ state?: D
114
+ ): Store<S, T, R>;
115
+
116
+ /** createKey * */
117
+
118
+ export declare interface ModelKey<
119
+ S = any,
120
+ T extends ModelInstance = any,
121
+ R extends (instance: () => T) => any = (instance: () => T) => T
122
+ > extends Key<S, T, R> {
123
+ (s: S): T;
124
+ createStore: <D extends S>(state?: D) => Store<S, T, R>;
125
+ extends: <E extends Record<string, any>>(e: E) => ModelKey<S, T, R> & E;
126
+ }
127
+
128
+ export declare function createKey<
129
+ S,
130
+ T extends ModelInstance,
131
+ D extends S,
132
+ R extends (instance: () => T) => any = (instance: () => T) => T
133
+ >(model: Model<S, T> | ModelUsage<S, T, R>, state?: D): ModelKey<S, T, R>;
134
+
135
+ /** createStores * */
136
+
137
+ export declare interface StoreCollection {
138
+ find: <
139
+ S,
140
+ T extends ModelInstance,
141
+ R extends (instance: () => T) => any = (instance: () => T) => T
142
+ >(
143
+ key: Key<S, T, R> | StoreIndex<S, T, R>
144
+ ) => Store<S, T, R> | null;
145
+ update: (...keys: (ModelKey | StoreIndex)[]) => void;
146
+ keys: () => Key[];
147
+ destroy: () => void;
148
+ }
149
+
150
+ export declare function createStores(
151
+ ...modelKeys: (ModelKey | StoreIndex)[]
152
+ ): StoreCollection;
153
+
154
+ /** model API * */
155
+
156
+ export declare interface ModelUsage<
157
+ S,
158
+ T extends ModelInstance,
159
+ R extends (instance: () => T) => any = (instance: () => T) => T
160
+ > {
161
+ (s: S): ValidInstance<S, T>;
162
+ createKey: <D extends S>(state?: D) => ModelKey<S, T, R>;
163
+ createStore: <D extends S>(state?: D) => Store<S, T, R>;
164
+ select: <C extends (instance: () => T) => any = (instance: () => T) => T>(
165
+ s: C
166
+ ) => ModelUsage<S, T, C>;
167
+ selector: R;
168
+ extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
169
+ }
170
+
171
+ // eslint-disable-next-line @typescript-eslint/naming-convention
172
+ export declare interface model {
173
+ <
174
+ S,
175
+ T extends ModelInstance,
176
+ R extends (instance: () => T) => any = (instance: () => T) => T
177
+ >(
178
+ modelFn: Model<S, T>,
179
+ s?: R
180
+ ): ModelUsage<S, T, R>;
181
+ createField: <P extends () => any>(
182
+ callback: P,
183
+ deps?: any[]
184
+ ) => FieldStructure<ReturnType<P>>;
185
+ createMethod: <P extends (...args: any[]) => any = (...args: any[]) => any>(
186
+ method: P
187
+ ) => MethodStructure<P>;
188
+ }
189
+
190
+ /** createSignal * */
191
+
192
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
193
+ declare interface SignalStore<
194
+ S = any,
195
+ T extends ModelInstance = any,
196
+ R extends (instance: () => T) => any = (instance: () => T) => any
197
+ > extends StoreIndex<S, T, R> {
198
+ subscribe: (dispatcher: Dispatch) => () => void;
199
+ getSignal: () => {
200
+ (): T;
201
+ startStatistics: () => void;
202
+ stopStatistics: () => void;
203
+ subscribe: (dispatcher: Dispatch) => () => void;
204
+ store: Store<S, T, R>;
205
+ };
206
+ }
207
+
208
+ export declare function createSignal<
209
+ S,
210
+ T extends ModelInstance,
211
+ R extends (instance: () => T) => any = (instance: () => T) => any
212
+ >(store: Store<S, T, R>): SignalStore<S, T, R>;
213
+
214
+ /** createSelector * */
215
+
216
+ declare type SelectMethod<
217
+ T extends ModelInstance = any,
218
+ R extends (instance: () => T) => any = (instance: () => T) => any
219
+ > = {
220
+ (): ReturnType<R>;
221
+ <C extends (instance: () => T) => any>(selector: C): ReturnType<C>;
222
+ <C extends (instance: () => T) => any>(
223
+ selector?: C
224
+ ): ReturnType<R> | ReturnType<C>;
225
+ };
226
+
227
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
228
+ declare interface SelectorStore<
229
+ S = any,
230
+ T extends ModelInstance = any,
231
+ R extends (instance: () => T) => any = (instance: () => T) => any
232
+ > extends StoreIndex<S, T, R> {
233
+ subscribe: (dispatcher: Dispatch) => () => void;
234
+ select: SelectMethod<T, R>;
235
+ }
236
+
237
+ declare interface SelectorOption<T = any> {
238
+ equality?: (current: T, next: T) => boolean;
239
+ }
240
+
241
+ export declare function createSelector<
242
+ S,
243
+ T extends ModelInstance,
244
+ R extends (instance: () => T) => any = (instance: () => T) => any
245
+ >(store: Store<S, T, R>, opts?: SelectorOption): SelectorStore<S, T, R>;
246
+
247
+ /** config * */
248
+ export declare function config(configuration: Config): {
249
+ createStore: <
250
+ S,
251
+ T extends ModelInstance,
252
+ D extends S,
253
+ R extends (instance: () => T) => any = (instance: () => T) => T
254
+ >(
255
+ model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
256
+ state?: D
257
+ ) => Store<S, T, R>;
258
+ createKey: <
259
+ S,
260
+ T extends ModelInstance,
261
+ D extends S,
262
+ R extends (instance: () => T) => any = (instance: () => T) => T
263
+ >(
264
+ model: Model<S, T> | ModelUsage<S, T, R>,
265
+ state?: D
266
+ ) => ModelKey<S, T, R>;
267
+ createStores: (...modelKeys: (ModelKey | StoreIndex)[]) => StoreCollection;
268
+ model: model;
269
+ };
270
+
271
+ /** validations * */
272
+ export declare const validations: {
273
+ isInstanceFromNoStateModel: (instance: any) => boolean;
274
+ isModelKey: <
275
+ S,
276
+ T extends ModelInstance,
277
+ R extends (ins: () => T) => any = (ins: () => T) => T
278
+ >(
279
+ data: any
280
+ ) => data is ModelKey<S, T, R>;
281
+ isModelStore: <
282
+ S,
283
+ T extends ModelInstance,
284
+ R extends (ins: () => T) => any = (ins: () => T) => T
285
+ >(
286
+ data: any
287
+ ) => data is Store<S, T, R>;
288
+ isModelUsage: <
289
+ S,
290
+ T extends ModelInstance,
291
+ R extends (ins: () => T) => any = (ins: () => T) => T
292
+ >(
293
+ data: any
294
+ ) => data is ModelUsage<S, T, R>;
295
+ };
296
+
297
+ /** tools * */
298
+ export declare function shallowEqual(prev: any, current: any): boolean;