@expressive/mvc 1.0.0-beta.42 → 1.0.0-beta.45

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/lib/index.d.ts CHANGED
@@ -18,6 +18,8 @@ declare function act<S>(action: Async<S>): typeof action & {
18
18
  active: boolean;
19
19
  };
20
20
 
21
+ declare function array<T = any>(): T[];
22
+
21
23
  type Callback = () => void;
22
24
  type Class = new (...args: any[]) => any;
23
25
  type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
@@ -34,7 +36,7 @@ declare class Subscriber<T extends Stateful = any> {
34
36
  commit: () => () => void;
35
37
  active: boolean;
36
38
  dependant: Set<Listener>;
37
- watch: { [key in Model.Event<T, Model>]: true | Callback; };
39
+ watch: { [key in Model.Event<T, Model>]: boolean | Callback; };
38
40
  constructor(target: Controller<T> | T, onUpdate: Controller.OnEvent);
39
41
  }
40
42
 
@@ -200,41 +202,31 @@ declare class Controller<T extends Stateful = any> {
200
202
  * Property initializer, will run upon instance creation.
201
203
  * Optional returned callback will run when once upon first access.
202
204
  */
203
- type Instruction<T> = (this: Controller, key: string, thisArg: Controller) =>
204
- | Instruction.Getter<T>
205
- | Instruction.ExplicitDescriptor
206
- | Instruction.Descriptor<T>
207
- | Instruction.RecursiveDescriptor<T>
208
- | boolean
209
- | void;
210
-
205
+ declare type Instruction<T> = (this: Controller, key: string, thisArg: Controller) => Instruction.Getter<T> | Instruction.ExplicitDescriptor | Instruction.Descriptor<T> | Instruction.RecursiveDescriptor<T> | boolean | void;
211
206
  declare namespace Instruction {
212
- type Getter<T> = (state: T, within?: Subscriber) => T;
213
- type Setter<T> = (value: T, state: any) => boolean | void;
214
-
215
- type Runner<T> = (this: Controller, key: string, on: Controller) => Instruction.Descriptor<T> | boolean | undefined;
216
-
217
- interface Descriptor<T> {
218
- configurable?: boolean;
219
- enumerable?: boolean;
220
- value?: T;
221
- writable?: boolean;
222
- get?: Getter<T>;
223
- set?: Setter<T> | false | void;
224
- }
225
-
226
- interface ExplicitDescriptor extends PropertyDescriptor {
227
- explicit: true;
228
- }
229
-
230
- interface RecursiveDescriptor<T> {
231
- recursive: true;
232
- enumerable?: boolean;
233
- value?: T;
234
- set?: Setter<T> | false | void;
235
- }
207
+ type Getter<T> = (state: T, within?: Subscriber) => T;
208
+ type Setter<T> = (value: T, state: any) => boolean | void;
209
+ type Runner<T> = (this: Controller, key: string, on: Controller) => Instruction.Descriptor<T> | boolean | undefined;
210
+ interface Descriptor<T> {
211
+ configurable?: boolean;
212
+ enumerable?: boolean;
213
+ value?: T;
214
+ writable?: boolean;
215
+ get?: Getter<T>;
216
+ set?: Setter<T> | false;
217
+ suspense?: boolean;
218
+ }
219
+ interface ExplicitDescriptor extends PropertyDescriptor {
220
+ explicit: true;
221
+ }
222
+ interface RecursiveDescriptor<T> {
223
+ recursive: true;
224
+ enumerable?: boolean;
225
+ value?: T;
226
+ set?: Setter<T> | false;
227
+ suspense?: boolean;
228
+ }
236
229
  }
237
-
238
230
  /**
239
231
  * Run instruction as controller sets itself up.
240
232
  * This will specialize the behavior of a given property.
@@ -533,8 +525,23 @@ declare class Global extends MVC {
533
525
  * Returns a thenable; resolves after successful update.
534
526
  * If instance does not already exist, one will be created.
535
527
  */
536
- static set<T extends typeof Global>(this: T, updates: Partial<InstanceOf<T>>): PromiseLike<false | readonly Model.Event<Global, Model>[]>;
537
- static get(arg?: boolean | string): any;
528
+ static set<T extends typeof Global>(this: T, updates: Partial<InstanceOf<T>>): Promise<false>;
529
+ /**
530
+ * **React Hook** - Fetch most instance of this controller from context, if it exists.
531
+ *
532
+ * @param required - If false, may return undefined.
533
+ */
534
+ static get<T extends Class>(this: T, required?: true): InstanceOf<T>;
535
+ /**
536
+ * **React Hook** - Fetch most instance of this controller from context.
537
+ *
538
+ * @param required - Unless false, will throw where instance cannot be found.
539
+ */
540
+ static get<T extends Class>(this: T, required: boolean): InstanceOf<T> | undefined;
541
+ /**
542
+ * **React Hook** - Fetch specific value from instance of this controller in context.
543
+ */
544
+ static get<T extends Class, K extends Model.Field<InstanceOf<T>>>(this: T, key: K): InstanceOf<T>[K];
538
545
  /** Destroy current instance of Global, if it exists. */
539
546
  static reset(): void;
540
547
  destroy(): void;
@@ -590,4 +597,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
590
597
  declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
591
598
  declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
592
599
 
593
- export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, MVC as default, from, parent, ref, set, tap, use, useFrom, useInContext, useModel, useTap };
600
+ export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use, useFrom, useInContext, useModel, useTap };