as-model 0.1.20 → 0.1.22

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
@@ -604,10 +604,14 @@
604
604
  updater.mutate(function(u, effect) {
605
605
  var _args_model;
606
606
  var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
607
- var state = "state" in args ? args.state : u.state;
607
+ var hasState = Object.prototype.hasOwnProperty.call(args, "state");
608
+ var hasInitialState = Object.prototype.hasOwnProperty.call(args, "initialState");
609
+ var state = hasState ? args.state : u.state;
610
+ var isInitialize = !u.initialized || hasInitialState;
608
611
  var token = createToken();
609
612
  if (u.controlled) {
610
- var instance = model2(state);
613
+ var controlledState = hasInitialState && !hasState ? args.initialState : state;
614
+ var instance = model2(controlledState);
611
615
  return _object_spread_props(_object_spread({}, u), {
612
616
  state,
613
617
  instance,
@@ -620,8 +624,9 @@
620
624
  if (!u.initialized && !("state" in args)) {
621
625
  throw new Error("The updater has not been initialized, it should be updated with a state for initializing.");
622
626
  }
623
- if (!u.initialized) {
624
- var instance1 = model2(state);
627
+ if (isInitialize) {
628
+ var initialState = hasInitialState ? args.initialState : state;
629
+ var instance1 = model2(initialState);
625
630
  var initializedUpdater = createInitializedUpdater(u, middleWare);
626
631
  return _object_spread(_object_spread_props(_object_spread({}, u), {
627
632
  model: model2,
@@ -1194,7 +1199,7 @@
1194
1199
  getInstance,
1195
1200
  update: function update(args) {
1196
1201
  var updateArgs = args !== null && args !== void 0 ? args : {};
1197
- if ("key" in updateArgs && updateArgs.key) {
1202
+ if (updateArgs.key) {
1198
1203
  var updatingKey = updateArgs.key, updatingModel = updateArgs.model, rest = _object_without_properties(updateArgs, [
1199
1204
  "key",
1200
1205
  "model"
@@ -1205,7 +1210,7 @@
1205
1210
  store.key = updatingKey;
1206
1211
  return;
1207
1212
  }
1208
- if ("model" in updateArgs && updateArgs.model) {
1213
+ if (updateArgs.model) {
1209
1214
  var updatingKey1 = updateArgs.key, updatingModel1 = updateArgs.model, rest1 = _object_without_properties(updateArgs, [
1210
1215
  "key",
1211
1216
  "model"
@@ -103,13 +103,13 @@ function createStore(modelLike, config = {}) {
103
103
  getInstance,
104
104
  update(args) {
105
105
  const updateArgs = args != null ? args : {};
106
- if ("key" in updateArgs && updateArgs.key) {
106
+ if (updateArgs.key) {
107
107
  const _a = updateArgs, { key: updatingKey, model: updatingModel } = _a, rest = __objRest(_a, ["key", "model"]);
108
108
  updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingKey.source }));
109
109
  store.key = updatingKey;
110
110
  return;
111
111
  }
112
- if ("model" in updateArgs && updateArgs.model) {
112
+ if (updateArgs.model) {
113
113
  const _b = updateArgs, { key: updatingKey, model: updatingModel } = _b, rest = __objRest(_b, ["key", "model"]);
114
114
  updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingModel }));
115
115
  store.key = createPrimaryKey(updatingModel, config);
@@ -37,10 +37,17 @@ function createUpdateFn(updater, middleWare) {
37
37
  updater.mutate((u, effect) => {
38
38
  var _a;
39
39
  const model = (_a = args.model) != null ? _a : u.model;
40
- const state = "state" in args ? args.state : u.state;
40
+ const hasState = Object.prototype.hasOwnProperty.call(args, "state");
41
+ const hasInitialState = Object.prototype.hasOwnProperty.call(
42
+ args,
43
+ "initialState"
44
+ );
45
+ const state = hasState ? args.state : u.state;
46
+ const isInitialize = !u.initialized || hasInitialState;
41
47
  const token = createToken();
42
48
  if (u.controlled) {
43
- const instance = model(state);
49
+ const controlledState = hasInitialState && !hasState ? args.initialState : state;
50
+ const instance = model(controlledState);
44
51
  return __spreadProps(__spreadValues({}, u), { state, instance, model });
45
52
  }
46
53
  if (u.isDestroyed) {
@@ -51,8 +58,9 @@ function createUpdateFn(updater, middleWare) {
51
58
  "The updater has not been initialized, it should be updated with a state for initializing."
52
59
  );
53
60
  }
54
- if (!u.initialized) {
55
- const instance = model(state);
61
+ if (isInitialize) {
62
+ const initialState = hasInitialState ? args.initialState : state;
63
+ const instance = model(initialState);
56
64
  const initializedUpdater = createInitializedUpdater(u, middleWare);
57
65
  return __spreadValues(__spreadProps(__spreadValues({}, u), {
58
66
  model,
package/index.d.ts CHANGED
@@ -1,310 +1,311 @@
1
- declare interface ModelInstance {
2
- [key: string]: any;
3
- [key: number]: any;
4
- }
5
-
6
- export 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
- export 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
- export interface Token {
45
- isDifferent: (token: Token) => boolean;
46
- value: unknown;
47
- }
48
-
49
- export declare type Dispatch = (action: Action) => any;
50
-
51
- export declare interface Key<
52
- S = any,
53
- T extends ModelInstance = any,
54
- R extends (instance: () => T) => any = (instance: () => T) => T
55
- > extends Model<S, T> {
56
- (s: S): T;
57
- source: Model<S, T>;
58
- selector: R;
59
- modelKeyIdentifier: () => boolean;
60
- [k: string]: any;
61
- defaultState?: S;
62
- }
63
-
64
- declare interface UpdaterStore<
65
- S = any,
66
- T extends ModelInstance = ModelInstance
67
- > {
68
- getState: () => { state: S; instance: T };
69
- dispatch: (action: Action) => void;
70
- }
71
-
72
- export declare type MiddleWare = (
73
- store: UpdaterStore
74
- ) => (next: Dispatch) => (action: Action) => void;
75
-
76
- export declare interface Config {
77
- middleWares?: MiddleWare[];
78
- controlled?: boolean;
79
- notify?: (
80
- notifier: (action: Action) => { errors: any[] | undefined },
81
- action: Action
82
- ) => any;
83
- }
84
-
85
- /** createStore * */
86
-
87
- export declare interface StoreIndex<
88
- S = any,
89
- T extends ModelInstance = any,
90
- R extends (instance: () => T) => any = (instance: () => T) => T
91
- > {
92
- key: Key<S, T, R>;
93
- }
94
-
95
- export declare interface Store<
96
- S = any,
97
- T extends ModelInstance = any,
98
- R extends (instance: () => T) => any = (instance: () => T) => T
99
- > extends StoreIndex<S, T, R> {
100
- subscribe: (dispatcher: Dispatch) => () => void;
101
- getToken: () => Token;
102
- getInstance: () => T;
103
- update: (args?: {
104
- model?: Model<S, T>;
105
- key?: Key<S, T, R>;
106
- state?: S;
107
- }) => void;
108
- destroy: () => void;
109
- payload: <P>(
110
- callback?: (payload: P | undefined) => P | undefined
111
- ) => P | undefined;
112
- isDestroyed: () => boolean;
113
- extends: <E extends Record<string, any>>(e: E) => Store<S, T, R> & E;
114
- }
115
-
116
- export declare function createStore<
117
- S,
118
- T extends ModelInstance,
119
- D extends S,
120
- R extends (instance: () => T) => any = (instance: () => T) => T
121
- >(
122
- model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
123
- state?: D
124
- ): Store<S, T, R>;
125
-
126
- /** createKey * */
127
-
128
- export declare interface ModelKey<
129
- S = any,
130
- T extends ModelInstance = any,
131
- R extends (instance: () => T) => any = (instance: () => T) => T
132
- > extends Key<S, T, R> {
133
- (s: S): T;
134
- createStore: <D extends S>(state?: D) => Store<S, T, R>;
135
- extends: <E extends Record<string, any>>(e: E) => ModelKey<S, T, R> & E;
136
- }
137
-
138
- export declare function createKey<
139
- S,
140
- T extends ModelInstance,
141
- D extends S,
142
- R extends (instance: () => T) => any = (instance: () => T) => T
143
- >(model: Model<S, T> | ModelUsage<S, T, R>, state?: D): ModelKey<S, T, R>;
144
-
145
- /** createStores * */
146
-
147
- export declare interface StoreCollection {
148
- find: <
149
- S,
150
- T extends ModelInstance,
151
- R extends (instance: () => T) => any = (instance: () => T) => T
152
- >(
153
- key: Key<S, T, R> | StoreIndex<S, T, R>
154
- ) => Store<S, T, R> | null;
155
- update: (...keys: (ModelKey | StoreIndex)[]) => void;
156
- keys: () => Key[];
157
- destroy: () => void;
158
- }
159
-
160
- export declare function createStores(
161
- ...modelKeys: (ModelKey | StoreIndex)[]
162
- ): StoreCollection;
163
-
164
- /** model API * */
165
-
166
- export declare interface ModelUsage<
167
- S,
168
- T extends ModelInstance,
169
- R extends (instance: () => T) => any = (instance: () => T) => T
170
- > {
171
- (s: S): ValidInstance<S, T>;
172
- createKey: <D extends S>(state?: D) => ModelKey<S, T, R>;
173
- createStore: <D extends S>(state?: D) => Store<S, T, R>;
174
- select: <C extends (instance: () => T) => any = (instance: () => T) => T>(
175
- s: C
176
- ) => ModelUsage<S, T, C>;
177
- selector: R;
178
- extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
179
- }
180
-
181
- // eslint-disable-next-line @typescript-eslint/naming-convention
182
- export declare interface model {
183
- <
184
- S,
185
- T extends ModelInstance,
186
- R extends (instance: () => T) => any = (instance: () => T) => T
187
- >(
188
- modelFn: Model<S, T>,
189
- s?: R
190
- ): ModelUsage<S, T, R>;
191
- createField: <P extends () => any>(
192
- callback: P,
193
- deps?: any[]
194
- ) => FieldStructure<ReturnType<P>>;
195
- createMethod: <P extends (...args: any[]) => any = (...args: any[]) => any>(
196
- method: P
197
- ) => MethodStructure<P>;
198
- }
199
-
200
- /** createSignal * */
201
-
202
- // eslint-disable-next-line @typescript-eslint/no-redeclare
203
- declare interface SignalStore<
204
- S = any,
205
- T extends ModelInstance = any,
206
- R extends (instance: () => T) => any = (instance: () => T) => any
207
- > extends StoreIndex<S, T, R> {
208
- getToken: () => Token;
209
- subscribe: (dispatcher: Dispatch) => () => void;
210
- getSignal: () => {
211
- (): T;
212
- startStatistics: () => void;
213
- stopStatistics: () => void;
214
- subscribe: (dispatcher: Dispatch) => () => void;
215
- store: Store<S, T, R>;
216
- };
217
- }
218
-
219
- export declare function createSignal<
220
- S,
221
- T extends ModelInstance,
222
- R extends (instance: () => T) => any = (instance: () => T) => any
223
- >(store: Store<S, T, R>): SignalStore<S, T, R>;
224
-
225
- /** createSelector * */
226
-
227
- declare type SelectMethod<
228
- T extends ModelInstance = any,
229
- R extends (instance: () => T) => any = (instance: () => T) => any
230
- > = {
231
- (): ReturnType<R>;
232
- <C extends (instance: () => T) => any>(selector: C): ReturnType<C>;
233
- <C extends (instance: () => T) => any>(
234
- selector?: C
235
- ): ReturnType<R> | ReturnType<C>;
236
- };
237
-
238
- // eslint-disable-next-line @typescript-eslint/no-redeclare
239
- declare interface SelectorStore<
240
- S = any,
241
- T extends ModelInstance = any,
242
- R extends (instance: () => T) => any = (instance: () => T) => any
243
- > extends StoreIndex<S, T, R> {
244
- getToken: () => Token;
245
- subscribe: (dispatcher: Dispatch) => () => void;
246
- select: SelectMethod<T, R>;
247
- }
248
-
249
- declare interface SelectorOption<T = any> {
250
- equality?: (current: T, next: T) => boolean;
251
- }
252
-
253
- export declare function createSelector<
254
- S,
255
- T extends ModelInstance,
256
- R extends (instance: () => T) => any = (instance: () => T) => any
257
- >(store: Store<S, T, R>, opts?: SelectorOption): SelectorStore<S, T, R>;
258
-
259
- /** config * */
260
- export declare function config(configuration: Config): {
261
- createStore: <
262
- S,
263
- T extends ModelInstance,
264
- D extends S,
265
- R extends (instance: () => T) => any = (instance: () => T) => T
266
- >(
267
- model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
268
- state?: D
269
- ) => Store<S, T, R>;
270
- createKey: <
271
- S,
272
- T extends ModelInstance,
273
- D extends S,
274
- R extends (instance: () => T) => any = (instance: () => T) => T
275
- >(
276
- model: Model<S, T> | ModelUsage<S, T, R>,
277
- state?: D
278
- ) => ModelKey<S, T, R>;
279
- createStores: (...modelKeys: (ModelKey | StoreIndex)[]) => StoreCollection;
280
- model: model;
281
- };
282
-
283
- /** validations * */
284
- export declare const validations: {
285
- isInstanceFromNoStateModel: (instance: any) => boolean;
286
- isModelKey: <
287
- S,
288
- T extends ModelInstance,
289
- R extends (ins: () => T) => any = (ins: () => T) => T
290
- >(
291
- data: any
292
- ) => data is ModelKey<S, T, R>;
293
- isModelStore: <
294
- S,
295
- T extends ModelInstance,
296
- R extends (ins: () => T) => any = (ins: () => T) => T
297
- >(
298
- data: any
299
- ) => data is Store<S, T, R>;
300
- isModelUsage: <
301
- S,
302
- T extends ModelInstance,
303
- R extends (ins: () => T) => any = (ins: () => T) => T
304
- >(
305
- data: any
306
- ) => data is ModelUsage<S, T, R>;
307
- };
308
-
309
- /** tools * */
310
- export declare function shallowEqual(prev: any, current: any): boolean;
1
+ declare interface ModelInstance {
2
+ [key: string]: any;
3
+ [key: number]: any;
4
+ }
5
+
6
+ export 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
+ export 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
+ export interface Token {
45
+ isDifferent: (token: Token) => boolean;
46
+ value: unknown;
47
+ }
48
+
49
+ export declare type Dispatch = (action: Action) => any;
50
+
51
+ export declare interface Key<
52
+ S = any,
53
+ T extends ModelInstance = any,
54
+ R extends (instance: () => T) => any = (instance: () => T) => T
55
+ > extends Model<S, T> {
56
+ (s: S): T;
57
+ source: Model<S, T>;
58
+ selector: R;
59
+ modelKeyIdentifier: () => boolean;
60
+ [k: string]: any;
61
+ defaultState?: S;
62
+ }
63
+
64
+ declare interface UpdaterStore<
65
+ S = any,
66
+ T extends ModelInstance = ModelInstance
67
+ > {
68
+ getState: () => { state: S; instance: T };
69
+ dispatch: (action: Action) => void;
70
+ }
71
+
72
+ export declare type MiddleWare = (
73
+ store: UpdaterStore
74
+ ) => (next: Dispatch) => (action: Action) => void;
75
+
76
+ export declare interface Config {
77
+ middleWares?: MiddleWare[];
78
+ controlled?: boolean;
79
+ notify?: (
80
+ notifier: (action: Action) => { errors: any[] | undefined },
81
+ action: Action
82
+ ) => any;
83
+ }
84
+
85
+ /** createStore * */
86
+
87
+ export declare interface StoreIndex<
88
+ S = any,
89
+ T extends ModelInstance = any,
90
+ R extends (instance: () => T) => any = (instance: () => T) => T
91
+ > {
92
+ key: Key<S, T, R>;
93
+ }
94
+
95
+ export declare interface Store<
96
+ S = any,
97
+ T extends ModelInstance = any,
98
+ R extends (instance: () => T) => any = (instance: () => T) => T
99
+ > extends StoreIndex<S, T, R> {
100
+ subscribe: (dispatcher: Dispatch) => () => void;
101
+ getToken: () => Token;
102
+ getInstance: () => T;
103
+ update: (args?: {
104
+ model?: Model<S, T>;
105
+ key?: Key<S, T, R>;
106
+ initialState?: S;
107
+ state?: S;
108
+ }) => void;
109
+ destroy: () => void;
110
+ payload: <P>(
111
+ callback?: (payload: P | undefined) => P | undefined
112
+ ) => P | undefined;
113
+ isDestroyed: () => boolean;
114
+ extends: <E extends Record<string, any>>(e: E) => Store<S, T, R> & E;
115
+ }
116
+
117
+ export declare function createStore<
118
+ S,
119
+ T extends ModelInstance,
120
+ D extends S,
121
+ R extends (instance: () => T) => any = (instance: () => T) => T
122
+ >(
123
+ model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
124
+ state?: D
125
+ ): Store<S, T, R>;
126
+
127
+ /** createKey * */
128
+
129
+ export declare interface ModelKey<
130
+ S = any,
131
+ T extends ModelInstance = any,
132
+ R extends (instance: () => T) => any = (instance: () => T) => T
133
+ > extends Key<S, T, R> {
134
+ (s: S): T;
135
+ createStore: <D extends S>(state?: D) => Store<S, T, R>;
136
+ extends: <E extends Record<string, any>>(e: E) => ModelKey<S, T, R> & E;
137
+ }
138
+
139
+ export declare function createKey<
140
+ S,
141
+ T extends ModelInstance,
142
+ D extends S,
143
+ R extends (instance: () => T) => any = (instance: () => T) => T
144
+ >(model: Model<S, T> | ModelUsage<S, T, R>, state?: D): ModelKey<S, T, R>;
145
+
146
+ /** createStores * */
147
+
148
+ export declare interface StoreCollection {
149
+ find: <
150
+ S,
151
+ T extends ModelInstance,
152
+ R extends (instance: () => T) => any = (instance: () => T) => T
153
+ >(
154
+ key: Key<S, T, R> | StoreIndex<S, T, R>
155
+ ) => Store<S, T, R> | null;
156
+ update: (...keys: (ModelKey | StoreIndex)[]) => void;
157
+ keys: () => Key[];
158
+ destroy: () => void;
159
+ }
160
+
161
+ export declare function createStores(
162
+ ...modelKeys: (ModelKey | StoreIndex)[]
163
+ ): StoreCollection;
164
+
165
+ /** model API * */
166
+
167
+ export declare interface ModelUsage<
168
+ S,
169
+ T extends ModelInstance,
170
+ R extends (instance: () => T) => any = (instance: () => T) => T
171
+ > {
172
+ (s: S): ValidInstance<S, T>;
173
+ createKey: <D extends S>(state?: D) => ModelKey<S, T, R>;
174
+ createStore: <D extends S>(state?: D) => Store<S, T, R>;
175
+ select: <C extends (instance: () => T) => any = (instance: () => T) => T>(
176
+ s: C
177
+ ) => ModelUsage<S, T, C>;
178
+ selector: R;
179
+ extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
180
+ }
181
+
182
+ // eslint-disable-next-line @typescript-eslint/naming-convention
183
+ export declare interface model {
184
+ <
185
+ S,
186
+ T extends ModelInstance,
187
+ R extends (instance: () => T) => any = (instance: () => T) => T
188
+ >(
189
+ modelFn: Model<S, T>,
190
+ s?: R
191
+ ): ModelUsage<S, T, R>;
192
+ createField: <P extends () => any>(
193
+ callback: P,
194
+ deps?: any[]
195
+ ) => FieldStructure<ReturnType<P>>;
196
+ createMethod: <P extends (...args: any[]) => any = (...args: any[]) => any>(
197
+ method: P
198
+ ) => MethodStructure<P>;
199
+ }
200
+
201
+ /** createSignal * */
202
+
203
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
204
+ declare interface SignalStore<
205
+ S = any,
206
+ T extends ModelInstance = any,
207
+ R extends (instance: () => T) => any = (instance: () => T) => any
208
+ > extends StoreIndex<S, T, R> {
209
+ getToken: () => Token;
210
+ subscribe: (dispatcher: Dispatch) => () => void;
211
+ getSignal: () => {
212
+ (): T;
213
+ startStatistics: () => void;
214
+ stopStatistics: () => void;
215
+ subscribe: (dispatcher: Dispatch) => () => void;
216
+ store: Store<S, T, R>;
217
+ };
218
+ }
219
+
220
+ export declare function createSignal<
221
+ S,
222
+ T extends ModelInstance,
223
+ R extends (instance: () => T) => any = (instance: () => T) => any
224
+ >(store: Store<S, T, R>): SignalStore<S, T, R>;
225
+
226
+ /** createSelector * */
227
+
228
+ declare type SelectMethod<
229
+ T extends ModelInstance = any,
230
+ R extends (instance: () => T) => any = (instance: () => T) => any
231
+ > = {
232
+ (): ReturnType<R>;
233
+ <C extends (instance: () => T) => any>(selector: C): ReturnType<C>;
234
+ <C extends (instance: () => T) => any>(
235
+ selector?: C
236
+ ): ReturnType<R> | ReturnType<C>;
237
+ };
238
+
239
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
240
+ declare interface SelectorStore<
241
+ S = any,
242
+ T extends ModelInstance = any,
243
+ R extends (instance: () => T) => any = (instance: () => T) => any
244
+ > extends StoreIndex<S, T, R> {
245
+ getToken: () => Token;
246
+ subscribe: (dispatcher: Dispatch) => () => void;
247
+ select: SelectMethod<T, R>;
248
+ }
249
+
250
+ declare interface SelectorOption<T = any> {
251
+ equality?: (current: T, next: T) => boolean;
252
+ }
253
+
254
+ export declare function createSelector<
255
+ S,
256
+ T extends ModelInstance,
257
+ R extends (instance: () => T) => any = (instance: () => T) => any
258
+ >(store: Store<S, T, R>, opts?: SelectorOption): SelectorStore<S, T, R>;
259
+
260
+ /** config * */
261
+ export declare function config(configuration: Config): {
262
+ createStore: <
263
+ S,
264
+ T extends ModelInstance,
265
+ D extends S,
266
+ R extends (instance: () => T) => any = (instance: () => T) => T
267
+ >(
268
+ model: Model<S, T> | Key<S, T, R> | ModelUsage<S, T, R>,
269
+ state?: D
270
+ ) => Store<S, T, R>;
271
+ createKey: <
272
+ S,
273
+ T extends ModelInstance,
274
+ D extends S,
275
+ R extends (instance: () => T) => any = (instance: () => T) => T
276
+ >(
277
+ model: Model<S, T> | ModelUsage<S, T, R>,
278
+ state?: D
279
+ ) => ModelKey<S, T, R>;
280
+ createStores: (...modelKeys: (ModelKey | StoreIndex)[]) => StoreCollection;
281
+ model: model;
282
+ };
283
+
284
+ /** validations * */
285
+ export declare const validations: {
286
+ isInstanceFromNoStateModel: (instance: any) => boolean;
287
+ isModelKey: <
288
+ S,
289
+ T extends ModelInstance,
290
+ R extends (ins: () => T) => any = (ins: () => T) => T
291
+ >(
292
+ data: any
293
+ ) => data is ModelKey<S, T, R>;
294
+ isModelStore: <
295
+ S,
296
+ T extends ModelInstance,
297
+ R extends (ins: () => T) => any = (ins: () => T) => T
298
+ >(
299
+ data: any
300
+ ) => data is Store<S, T, R>;
301
+ isModelUsage: <
302
+ S,
303
+ T extends ModelInstance,
304
+ R extends (ins: () => T) => any = (ins: () => T) => T
305
+ >(
306
+ data: any
307
+ ) => data is ModelUsage<S, T, R>;
308
+ };
309
+
310
+ /** tools * */
311
+ export declare function shallowEqual(prev: any, current: any): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "as-model",
4
- "version": "0.1.20",
4
+ "version": "0.1.22",
5
5
  "description": "This is a model state management tool",
6
6
  "license": "MIT",
7
7
  "author": "Jimmy.Harding",