@expressive/mvc 0.5.0 → 0.6.0

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
@@ -232,6 +232,7 @@ declare namespace get {
232
232
  type Function<T, O = any> = (this: O, on: O) => T;
233
233
  type Factory<T, O = any> = (key: string) => Function<T, O>;
234
234
  type Getter = (controller: Controller, key: string) => any;
235
+ type Factory2<T, S = unknown> = (this: S, key: string, thisArg: S) => T;
235
236
  }
236
237
  /**
237
238
  * Implement a computed value; output will be generated by provided function.
@@ -250,6 +251,46 @@ declare function get<R, T>(source: T, compute: (this: T, on: T) => R, suspend?:
250
251
  */
251
252
  declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend: true): Exclude<R, undefined>;
252
253
  declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend?: boolean): R;
254
+ /**
255
+ * Set property with an async function.
256
+ *
257
+ * Property cannot be accessed until factory resolves, yeilding a result.
258
+ * If accessed while processing, React Suspense will be thrown.
259
+ *
260
+ * - `required: true` (default) -
261
+ * Run factory immediately upon creation of model instance.
262
+ * - `required: false` -
263
+ * Run factory only if/when accessed.
264
+ * Value will always throw suspense at least once - use with caution.
265
+ *
266
+ * @param factory - Callback run to derrive property value.
267
+ * @param required - (default: true) Run factory immediately on creation, otherwise on access.
268
+ */
269
+ declare function get<T>(factory: get.Factory2<Promise<T>>, required: false): T | undefined;
270
+ declare function get<T, S>(factory: get.Factory2<Promise<T>, S>, required: false): T | undefined;
271
+ declare function get<T>(factory: get.Factory2<Promise<T>>, required?: boolean): T;
272
+ declare function get<T, S>(factory: get.Factory2<Promise<T>, S>, required?: boolean): T;
273
+ /**
274
+ * Set property with a factory function.
275
+ *
276
+ * - `required: true` (default) -
277
+ * Run factory immediately upon creation of model instance.
278
+ * - `required: false` -
279
+ * Run factory only if/when accessed.
280
+ * Value will always throw suspense at least once - use with caution.
281
+ *
282
+ * @param factory - Callback run to derrive property value.
283
+ * @param required - (default: true) Run factory immediately on creation, otherwise on access.
284
+ */
285
+ declare function get<T>(factory: get.Factory2<T>, required: false): T | undefined;
286
+ declare function get<T, S>(factory: get.Factory2<T, S>, required: false): T | undefined;
287
+ declare function get<T>(factory: get.Factory2<T>, required?: boolean): T;
288
+ declare function get<T, S>(factory: get.Factory2<T, S>, required?: boolean): T;
289
+ /**
290
+ * Assign a property with result of a promise.
291
+ */
292
+ declare function get<T>(factory: Promise<T>, required: false): T | undefined;
293
+ declare function get<T>(factory: Promise<T>, required?: boolean): T;
253
294
 
254
295
  declare namespace ref {
255
296
  type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
@@ -273,62 +314,6 @@ declare namespace ref {
273
314
  declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
274
315
  declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
275
316
 
276
- declare namespace set$1 {
277
- type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
278
- type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
279
- }
280
- /**
281
- * Set property with an async function.
282
- *
283
- * Property cannot be accessed until factory resolves, yeilding a result.
284
- * If accessed while processing, React Suspense will be thrown.
285
- *
286
- * - `required: true` (default) -
287
- * Run factory immediately upon creation of model instance.
288
- * - `required: false` -
289
- * Run factory only if/when accessed.
290
- * Value will always throw suspense at least once - use with caution.
291
- *
292
- * @param factory - Callback run to derrive property value.
293
- * @param required - (default: true) Run factory immediately on creation, otherwise on access.
294
- */
295
- declare function put<T>(factory: set$1.Factory<Promise<T>>, required: false): T | undefined;
296
- declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required: false): T | undefined;
297
- declare function put<T>(factory: set$1.Factory<Promise<T>>, required?: boolean): T;
298
- declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required?: boolean): T;
299
- declare function put<T>(value: set$1.Factory<Promise<T>>, onUpdate: set$1.Callback<T>): T;
300
- declare function put<T, S>(value: set$1.Factory<Promise<T>, S>, onUpdate: set$1.Callback<T, S>): T;
301
- /**
302
- * Set property with a factory function.
303
- *
304
- * - `required: true` (default) -
305
- * Run factory immediately upon creation of model instance.
306
- * - `required: false` -
307
- * Run factory only if/when accessed.
308
- * Value will always throw suspense at least once - use with caution.
309
- *
310
- * @param factory - Callback run to derrive property value.
311
- * @param required - (default: true) Run factory immediately on creation, otherwise on access.
312
- */
313
- declare function put<T>(factory: set$1.Factory<T>, required: false): T | undefined;
314
- declare function put<T, S>(factory: set$1.Factory<T, S>, required: false): T | undefined;
315
- declare function put<T>(factory: set$1.Factory<T>, required?: boolean): T;
316
- declare function put<T, S>(factory: set$1.Factory<T, S>, required?: boolean): T;
317
- declare function put<T>(value: set$1.Factory<T>, onUpdate: set$1.Callback<T>): T;
318
- declare function put<T, S>(value: set$1.Factory<T, S>, onUpdate: set$1.Callback<T, S>): T;
319
- /**
320
- * Assign a property with result of a promise.
321
- */
322
- declare function put<T>(factory: Promise<T>, required: false): T | undefined;
323
- declare function put<T>(factory: Promise<T>, required?: boolean): T;
324
- declare function put<T>(value: Promise<T>, onUpdate: set$1.Callback<T>): T;
325
- /**
326
- * Assign a property.
327
- */
328
- declare function put<T>(factory: T, required: false): T | undefined;
329
- declare function put<T>(factory: T, required?: boolean): T;
330
- declare function put<T>(value: T, onUpdate: set$1.Callback<T>): T;
331
-
332
317
  declare namespace set {
333
318
  type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
334
319
  }
@@ -347,10 +332,11 @@ declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
347
332
  declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
348
333
 
349
334
  declare type MapFunction<T, R> = T extends Map<infer K, infer V> ? (value: V, key: K, map: T) => R | void : T extends Set<infer K> ? (value: K, key: K, set: T) => R | void : never;
350
- declare type Managed<T> = T & {
335
+ declare type Managed<T> = Exclude<T, "forEach"> & {
351
336
  from?: T;
352
337
  forEach<R>(mapFunction: MapFunction<T, R>, thisArg?: any): Exclude<R, undefined>[] | void;
353
338
  };
339
+
354
340
  declare function use<K = any>(initial: SetConstructor): Managed<Set<K>>;
355
341
  declare function use<K = any, V = any>(initial: MapConstructor): Managed<Map<K, V>>;
356
342
  declare function use(initial: Set<unknown>): Managed<Set<any>>;
@@ -363,6 +349,8 @@ declare function use<T extends Set<any> | Map<any, any>>(from: () => T): Managed
363
349
  * Create a placeholder for specified Model type.
364
350
  */
365
351
  declare function use<T extends Model>(): T | undefined;
352
+ declare function use<T extends Model>(from: () => T, required: false): T | undefined;
353
+ declare function use<T extends Model>(from: () => T, required: boolean): T;
366
354
  /**
367
355
  * Create a new child instance of model.
368
356
  */
@@ -370,6 +358,9 @@ declare function use<T extends Class>(Type: T, callback?: (i: InstanceOf<T>) =>
370
358
  /**
371
359
  * Create a managed child from factory function.
372
360
  */
361
+ declare function use<T extends {}>(from: () => Promise<T>, required: false): T | undefined;
362
+ declare function use<T extends {}>(from: () => Promise<T>, required: boolean): T;
363
+ declare function use<T extends {}>(from: () => Promise<T>, callback?: (i: T) => void): T;
373
364
  declare function use<T extends {}>(from: () => T, callback?: (i: T) => void): T;
374
365
  /**
375
366
  * Create child-instance relationship with provided model.
@@ -625,4 +616,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
625
616
  declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
626
617
  declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
627
618
 
628
- export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, MVC as default, get, has, put, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
619
+ export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, MVC as default, get, has, ref, set, tap, use, useFrom, useLocal, useModel, useTap };