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

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/types/model.d.ts CHANGED
@@ -113,9 +113,15 @@ export namespace Model {
113
113
 
114
114
  type HandleValue = (value: any) => boolean | void;
115
115
 
116
+ export namespace Controller {
117
+ export type Listen = (key: string, source: Controller) =>
118
+ RequestCallback | undefined;
119
+ }
120
+
116
121
  export class Controller {
117
122
  state: BunchOf<any>;
118
123
  subject: {};
124
+ waiting: Set<RequestCallback>;
119
125
 
120
126
  /** Add property to managed state. */
121
127
  manage(key: string, initial: any, effect?: HandleValue): void;
@@ -124,11 +130,9 @@ export namespace Model {
124
130
 
125
131
  setter(key: string, effect?: HandleValue): (value: any) => boolean | void;
126
132
 
127
- addListener(batch: BunchOf<RequestCallback>): Callback;
133
+ addListener(listener: Controller.Listen): Callback;
128
134
 
129
135
  update(key: string, value?: any): void;
130
-
131
- include(cb: RequestCallback): void;
132
136
  }
133
137
 
134
138
  export class Subscriber {
@@ -136,13 +140,13 @@ export namespace Model {
136
140
  source: any;
137
141
  parent: Controller;
138
142
  active: boolean;
139
- follows: BunchOf<Callback>;
143
+ listen: Controller.Listen;
140
144
  dependant: Set<{
141
145
  commit(): void;
142
146
  release(): void;
143
147
  }>;
144
148
 
145
- follow(key: string, cb?: Callback | undefined): void;
149
+ follow(key: string, cb?: RequestCallback | undefined): void;
146
150
  commit(): Callback;
147
151
  release(): Callback;
148
152
  onUpdate(): void;
@@ -150,6 +154,7 @@ export namespace Model {
150
154
  }
151
155
 
152
156
  declare const CONTROL: unique symbol;
157
+ declare const UPDATE: unique symbol;
153
158
  declare const LOCAL: unique symbol;
154
159
  declare const STATE: unique symbol;
155
160
 
@@ -164,6 +169,14 @@ export abstract class Model {
164
169
  /** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
165
170
  [LOCAL]?: Model.Subscriber;
166
171
 
172
+ /**
173
+ * Last update causing a refresh to subscribers.
174
+ *
175
+ * If accessed directly, will contain all keys from last push.
176
+ * If within a subscribed function, will contain only keys which explicitly caused a refresh.
177
+ **/
178
+ [UPDATE]?: readonly string[];
179
+
167
180
  /**
168
181
  * Circular reference to `this` controller.
169
182
  *
@@ -229,19 +242,19 @@ export abstract class Model {
229
242
  export <P extends Model.Fields<this>> (select: P[]): Model.State<this, P>;
230
243
  export <S extends Model.SelectFields<this>> (select: S): Model.State<this, Selector.From<S>>;
231
244
 
232
- update(): PromiseLike<string[] | false>;
233
- update(strict: true): Promise<string[]>;
245
+ update(): PromiseLike<readonly string[] | false>;
246
+ update(strict: true): Promise<readonly string[]>;
234
247
  update(strict: false): Promise<false>;
235
- update(strict: boolean): Promise<string[] | false>;
248
+ update(strict: boolean): Promise<readonly string[] | false>;
236
249
 
237
- update(keys: Model.Fields<this>): Thenable<string[]>;
238
- update(keys: Model.SelectFieldKey<this>): Thenable<string[]>;
250
+ update(keys: Model.Fields<this>): Thenable<readonly string[]>;
251
+ update(keys: Model.SelectFieldKey<this>): Thenable<readonly string[]>;
239
252
 
240
- update(keys: Model.Fields<this>, callMethod: boolean): PromiseLike<string[]>;
241
- update(keys: Model.SelectFields<this>, callMethod: boolean): PromiseLike<string[]>;
253
+ update(keys: Model.Fields<this>, callMethod: boolean): PromiseLike<readonly string[]>;
254
+ update(keys: Model.SelectFields<this>, callMethod: boolean): PromiseLike<readonly string[]>;
242
255
 
243
- update<T>(keys: Model.Fields<this>, argument: T): PromiseLike<string[]>;
244
- update<T>(keys: Model.SelectFields<this>, argument: T): PromiseLike<string[]>;
256
+ update<T>(keys: Model.Fields<this>, argument: T): PromiseLike<readonly string[]>;
257
+ update<T>(keys: Model.SelectFields<this>, argument: T): PromiseLike<readonly string[]>;
245
258
 
246
259
  /*
247
260
  Issue with self-reference, using fallback.
@@ -284,28 +297,36 @@ export abstract class Model {
284
297
 
285
298
  // Keyed
286
299
  on <S extends Model.SelectEvents<this>> (via: S, cb: Selector.Callback<S, this>, squash?: false, once?: boolean): Callback;
300
+ on <P = Model.EventsCompat<this>> (keys: [], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
287
301
  on <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
288
302
  // Squash
289
303
  on <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true, once?: boolean): Callback;
304
+ on <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
290
305
  on <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
291
306
  // Unknown
292
307
  on <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean, once?: boolean): Callback;
308
+ on (keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
293
309
  on <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean, once?: boolean): Callback;
294
310
 
295
311
  // Keyed
296
312
  once <S extends Model.SelectEvents<this>> (via: S, cb: Selector.Callback<S, this>, squash?: false): Callback;
313
+ once <P = Model.EventsCompat<this>> (keys: [], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
297
314
  once <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false): Callback;
298
315
  // Squash
299
316
  once <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true): Callback;
317
+ once <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
300
318
  once <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
301
319
  // Promise
302
320
  once <S extends Model.SelectEvents<this>> (via: S): Promise<Selector.From<S>[]>;
321
+ once <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
303
322
  once <P extends Model.EventsCompat<this>> (key: P | P[]): Promise<P[]>;
304
323
  // Unknown
305
324
  once <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean): Callback;
325
+ once (keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
306
326
  once <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean): Callback;
307
327
 
308
328
  effect(callback: (this: this, state: this) => void, select?: Model.SelectFields<this>): Callback;
329
+ effect(callback: (this: this, state: this) => void, select?: []): Callback;
309
330
  effect(callback: (this: this, state: this) => void, select?: (keyof this)[]): Callback;
310
331
 
311
332
  /**
@@ -344,6 +365,9 @@ export abstract class Model {
344
365
  /** Use symbol to access current subscriber of a model in a live context (e.g. hook or effect). */
345
366
  static LOCAL: typeof LOCAL;
346
367
 
368
+ /** Use symbol to access keys affected by last update. */
369
+ static WHY: typeof UPDATE;
370
+
347
371
  /**
348
372
  * Creates a new instance of this controller.
349
373
  *
package/types/types.d.ts CHANGED
@@ -7,7 +7,7 @@ export type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
7
7
  export type IfApplicable<T extends {}, K> = K extends keyof T ? T[K] : undefined;
8
8
 
9
9
  export type Callback = () => void;
10
- export type RequestCallback = (keys?: string[]) => void;
10
+ export type RequestCallback = (keys: readonly 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
13
  export type InterceptCallback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;