@expressive/mvc 1.0.0-beta.23 → 1.0.0-beta.24

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.
@@ -113,8 +113,10 @@ export function tap <T extends Class> (Type: T, required?: boolean): InstanceOf<
113
113
  * @param initialValue - Beginning value of host property.
114
114
  * @param onUpdate - Effect-callback fired upon set of host property.
115
115
  */
116
- export function on <T = any> (initialValue: undefined, onUpdate: InterceptCallback<T>): T | undefined;
117
- export function on <T = any> (initialValue: T, onUpdate: InterceptCallback<T>): T;
116
+ export function on <T> (initialValue: undefined, onUpdate: InterceptCallback<T>): T | undefined;
117
+ export function on <T> (initialValue: T, onUpdate: InterceptCallback<T>): T;
118
+ export function on <T, S> (initialValue: undefined, onUpdate: InterceptCallback<T, S>): T | undefined;
119
+ export function on <T, S> (initialValue: T, onUpdate: InterceptCallback<T, S>): T;
118
120
 
119
121
  /** Object with references to all managed values of `T`. */
120
122
  export type Refs <T extends Model> = { [P in Model.Fields<T>]: Model.Ref<T[P]> };
@@ -138,6 +140,7 @@ export function ref <T extends Model> (target: T): Refs<T>;
138
140
  * @param callback - Optional callback to synchronously fire when reference is first set or does update.
139
141
  */
140
142
  export function ref <T = HTMLElement> (callback?: InterceptCallback<T>): Model.Ref<T>;
143
+ export function ref <T, S> (callback?: InterceptCallback<T, S>): Model.Ref<T>;
141
144
 
142
145
  /**
143
146
  * Sets an exotic method with managed ready-state. Property accepts an async function.
@@ -149,14 +152,16 @@ export function ref <T = HTMLElement> (callback?: InterceptCallback<T>): Model.R
149
152
  *
150
153
  * @param action - Action to fire when resulting property is invoked.
151
154
  */
152
- export function act <T extends Async> (action: T): T & { active: boolean };
155
+ export function act (action: Async): typeof action & { active: boolean };
156
+ export function act <S> (action: Async<S>): typeof action & { active: boolean };
153
157
 
154
158
  /**
155
159
  * Implement a computed value; output is returned by function from provided factory.
156
160
  *
157
161
  * @param compute - Factory function to generate a getter to subscribe dependancies.
158
162
  */
159
- export function from <R> (compute: (property: string) => (this: any, state: any) => R): R;
163
+ export function from <R> (compute: (property: string) => <T>(this: T, state: T) => R): R;
164
+ export function from <R, T> (compute: (property: string) => (this: T, state: T) => R): R;
160
165
 
161
166
  /**
162
167
  * Implement a computed value; output will be generated by provided function.
@@ -176,7 +181,7 @@ export function from <T extends Class, R> (source: T, compute: (this: InstanceOf
176
181
  * @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value.
177
182
  * Will update automatically as input values change.
178
183
  */
179
- export function from <T, R> (source: T, compute: (this: T, on: T) => R): R;
184
+ export function from <R, T> (source: T, compute: (this: T, on: T) => R): R;
180
185
 
181
186
  /**
182
187
  * Memoized value. Computes and stores a value returned by provided factory.
@@ -185,7 +190,8 @@ export function from <T, R> (source: T, compute: (this: T, on: T) => R): R;
185
190
  * @param compute - Factory for memoized value.
186
191
  * @param lazy - Wait until accessed to introduce value.
187
192
  */
188
- export function memo <T> (compute: () => T, lazy?: boolean): T;
193
+ export function memo <R> (compute: () => R, lazy?: boolean): R;
194
+ export function memo <R, T> (compute: (this: T) => R, lazy?: boolean): R;
189
195
 
190
196
  /**
191
197
  * Flag property as not to be tracked. Useful if changes often with no real-time impact.
@@ -198,7 +204,7 @@ export function lazy <T> (value?: T): T;
198
204
  * Pending value. Will suspend unless value is defined,
199
205
  * suspense resolves when a value is aquired.
200
206
  */
201
- export function pending <T = boolean> (): Exclude<T, undefined>;
207
+ export function pending <T = boolean> (): T;
202
208
 
203
209
  /**
204
210
  * Suspend during the execution of given function to obtain value.
@@ -206,7 +212,9 @@ export function pending <T = boolean> (): Exclude<T, undefined>;
206
212
  * @param waitFor - Async function to suspend for.
207
213
  */
208
214
  export function pending (waitFor: () => Promise<void>): undefined;
209
- export function pending <T> (waitFor: () => Promise<T>): T;
215
+ export function pending <T> (waitFor: (this: T) => Promise<void>): undefined;
216
+ export function pending <R> (waitFor: () => Promise<R>): R;
217
+ export function pending <R, T> (waitFor: (this: T) => Promise<R>): R;
210
218
 
211
219
  /**
212
220
  * Suspend for a computed value, returned by syncronous function.
@@ -225,4 +233,4 @@ export function pending <T> (waitFor: () => Promise<T>): T;
225
233
  * @param compute - Compute function returns output value. Bound to a subscriber of source.
226
234
  * Will re-run automatically as input values change.
227
235
  */
228
- export function pending <T, R> (source: T, compute: (this: T, on: T) => R): Exclude<R, undefined>;
236
+ export function pending <R, T> (source: T, compute: (this: T, on: T) => R): R;
package/types/model.d.ts CHANGED
@@ -309,7 +309,7 @@ export abstract class Model {
309
309
  effect(callback: (this: this, state: this) => void, select?: (keyof this)[]): Callback;
310
310
 
311
311
  /**
312
- * **React Hook** - Attach to instance of this controller within ambient component.
312
+ * **React Hook** - Attach to instance of this controller within a component.
313
313
  *
314
314
  * This method will fire lifecycle events on given controller.
315
315
  *
@@ -318,14 +318,23 @@ export abstract class Model {
318
318
  tag(id?: any): this;
319
319
 
320
320
  /**
321
- * **React Hook** - Attach to instance of this controller within ambient component.
321
+ * **React Hook** - Subscribe to instance of controller within a component.
322
322
  *
323
- * This method will fire lifecycle events on given controller.
323
+ * This method will fire lifecycle events on given controller (as element)..
324
324
  *
325
325
  * @param idFactory - Will be invoked with fetched instance. Use this to register a tag as-needed.
326
326
  */
327
327
  tag(idFactory: (idFactory: this) => any): this;
328
328
 
329
+ /**
330
+ * **React Hook** - Subscribe to instance of controller within a component.
331
+ *
332
+ * This method will fire lifecycle events on given controller (as component).
333
+ *
334
+ * @param callback - Run once before subscription begins.
335
+ */
336
+ use(callback?: (instance: this) => void): this;
337
+
329
338
  /** Use symbol to access controller of a model. */
330
339
  static CONTROL: typeof CONTROL;
331
340
 
@@ -350,20 +359,18 @@ export abstract class Model {
350
359
  * Differs from `use()` in lacking subscription and lifecycle events.
351
360
  * Much more efficient if you don't need hook-based features.
352
361
  *
353
- * @param args - Arguments passed to constructor of `this`
354
362
  * @param callback - Run after creation of instance.
355
363
  */
356
- static new <T extends Class> (this: T, args?: ConstructorParameters<T>, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
364
+ static new <T extends Class> (this: T, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
357
365
 
358
366
  /**
359
367
  * **React Hook** - Create and attach an instance of this controller a react component.
360
368
  *
361
369
  * Note: Model will be destroyed when ambient component unmounts!
362
370
  *
363
- * @param args - Arguments passed to constructor of `this`
364
371
  * @param callback - Run after creation of instance.
365
372
  */
366
- static use <T extends Class> (this: T, args?: ConstructorParameters<T>, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
373
+ static use <T extends Class> (this: T, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
367
374
 
368
375
  /**
369
376
  * **React Hook** - Similar to `use`, will instanciate a controller bound to ambient component.
package/types/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type Key = string | symbol | number;
2
- export type Async = (...args: any[]) => Promise<any>;
2
+ export type Async<T = any> = (this: T, ...args: any[]) => Promise<any>;
3
3
  export type BunchOf<T> = { [key: string]: T };
4
4
 
5
5
  export type Class = new (...args: any[]) => any;
@@ -10,7 +10,7 @@ export type Callback = () => void;
10
10
  export type RequestCallback = (keys?: string[]) => void;
11
11
  export type EffectCallback<T, A = T> = (this: T, argument: A) => Callback | Promise<any> | void;
12
12
  export type UpdateCallback<T, P> = (this: T, value: IfApplicable<T, P>, changed: P) => void;
13
- export type InterceptCallback<T> = (argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
13
+ export type InterceptCallback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
14
14
 
15
15
  export type RefFunction = (e: HTMLElement | null) => void;
16
16