@expressive/mvc 1.0.0-beta.36 → 1.0.0-beta.39

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/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export {
2
- Model,
3
- Model as default,
4
- Singleton
5
- } from './model';
6
-
7
- export * from './context';
8
- export * from './instructions';
@@ -1,326 +0,0 @@
1
- import Model from '.';
2
- import { Async, Class, InstanceOf } from './types';
3
-
4
- /**
5
- * Run instruction as controller sets itself up.
6
- * This will specialize the behavior of a given property.
7
- **/
8
- export function apply <T = any> (instruction: Model.Instruction<T>, name?: string): T;
9
-
10
- /**
11
- * Create a placeholder for specified Model type.
12
- */
13
- export function use <T extends Model> (): T | undefined;
14
-
15
- /**
16
- * Create a new child instance of model.
17
- */
18
- export function use <T extends Class> (Type: T, callback?: (i: InstanceOf<T>) => void): InstanceOf<T>;
19
-
20
- /**
21
- * Create a new child-instance from factory function.
22
- */
23
- export function use <T extends Model> (from: () => T, callback?: (i: T) => void): T;
24
-
25
- /**
26
- * Create child-instance relationship with provided model.
27
- *
28
- * Note: If `peer` is not already initialized before parent is
29
- * (created with `new` as opposed to create method), that model will
30
- * attach this via `parent()` instruction. It will not, if
31
- * already active.
32
- */
33
- export function use <T extends Model> (peer: T, callback?: (i: T) => void): T;
34
-
35
- /**
36
- * Generate a child controller from specified object. Object's values are be trackable, as would be for a full-model.
37
- *
38
- * Note: Child will *not* be same object as one provided.
39
- */
40
- export function use <T extends {}> (object: T): T;
41
-
42
- export namespace child {
43
- type Instruction<T> = (this: Model.Controller, key: string) => {
44
- get: () => T | undefined,
45
- set?: (value: T | undefined) => void
46
- }
47
- }
48
-
49
- /**
50
- * Generic instruction used by `use()` and `tap()` for recursive subscription.
51
- *
52
- * @param from - Instruction body is run upon parent create. Return function to fetch current value of field.
53
- */
54
- export function child <T extends Model> (from: child.Instruction<T>): T;
55
-
56
- /**
57
- * Fetches and assigns the controller which spawned this host.
58
- * When parent assigns an instance via `use()` directive, it
59
- * will be made available to child upon this request.
60
- *
61
- * @param Expects - Type of controller compatible with this class.
62
- * @param required - Throw if controller is created independantly.
63
- */
64
- export function parent <T extends typeof Model> (Expects: T, required: true): InstanceOf<T>;
65
- export function parent <T extends typeof Model> (Expects: T, required?: false): InstanceOf<T> | undefined;
66
-
67
- /**
68
- * Find and attach most applicable instance of Model via context.
69
- *
70
- * Host controller will search element-hierarchy relative to where it spawned.
71
- *
72
- * @param Type - Type of model to find from context
73
- * @param callback -
74
- * - Invoked after context is scanned, is passed result - either found or undefined.
75
- * - If argument is inadequate, but required, your implemention should simply throw.
76
- * - If inadequate and not required, conditionally return false.
77
- */
78
- export function tap <T extends typeof Model> (Type: T, callback?: (instance?: InstanceOf<T>) => void | true): InstanceOf<T>;
79
- export function tap <T extends typeof Model> (Type: T, callback?: (instance?: InstanceOf<T>) => void | false): InstanceOf<T> | undefined;
80
-
81
- /**
82
- * Find and attach most applicable instance of Model via context.
83
- *
84
- * Expects a `<Provider>` of target controller to exist.
85
- * Host controller will search element-hierarchy relative to where it spawned.
86
- *
87
- * @param Type - Type of controller to attach to property.
88
- * @param required - Throw if instance of Type cannot be found.
89
- */
90
- export function tap <T extends Class> (Type: T, required?: boolean): InstanceOf<T>;
91
-
92
- export namespace on {
93
- type Callback<T, S = any> = (this: S, argument: T) =>
94
- ((next: T) => void) | Promise<any> | void | boolean;
95
- }
96
-
97
- /**
98
- * Cause property to synchronously run effect upon update.
99
- *
100
- * Callback may return an effect callback, Promise (ignored), or a boolean.
101
- *
102
- * If a boolean is returned explicitly, new value will be dropped. Useful to override.
103
- *
104
- * - `false` will prevent update.
105
- * - `true` will emit update (unchanged).
106
- *
107
- * @param initialValue - Beginning value of host property.
108
- * @param onUpdate - Effect-callback fired upon set of host property.
109
- *
110
- * @deprecated will be removed in favor of `set`
111
- */
112
- export function on <T> (initialValue: undefined, onUpdate: on.Callback<T>): T | undefined;
113
- export function on <T> (initialValue: T, onUpdate: on.Callback<T>): T;
114
- export function on <T, S> (initialValue: undefined, onUpdate: on.Callback<T, S>): T | undefined;
115
- export function on <T, S> (initialValue: T, onUpdate: on.Callback<T, S>): T;
116
-
117
- /** Object with references to all managed values of `T`. */
118
- export type Refs <T extends Model> = { [P in Model.Fields<T>]: Model.Ref<T[P]> };
119
-
120
- export namespace ref {
121
- type Callback<T, S = any> = (this: S, argument: T) =>
122
- ((next: T) => void) | Promise<any> | void | boolean;
123
- }
124
-
125
- /**
126
- * Creates an object with references to all managed values.
127
- * Each property will set value in state when invoked.
128
- *
129
- * *Properties are simultaneously a ref-function and ref-object, use as needed.*
130
- *
131
- * @param target - Source model from which to reference values.
132
- */
133
- export function ref <T extends Model> (target: T): Refs<T>;
134
-
135
- /**
136
- * Creates a ref-compatible property.
137
- * Will persist value, and updates to this are made part of controller event-stream.
138
- *
139
- * *Output is simultaneously a ref-function and ref-object, use as needed.*
140
- *
141
- * @param callback - Optional callback to synchronously fire when reference is first set or does update.
142
- */
143
- export function ref <T = HTMLElement> (callback?: ref.Callback<T>): Model.Ref<T>;
144
- export function ref <T, S> (callback?: ref.Callback<T, S>): Model.Ref<T>;
145
-
146
- /**
147
- * Sets an exotic method with managed ready-state. Property accepts an async function.
148
- *
149
- * When an act-method is invoked, its `active` property to true for duration of call.
150
- * This is emitted as an update to property, both when called and after returns (or throws).
151
- *
152
- * **Note:** Subsequent calls will immediately throw if one is still pending.
153
- *
154
- * @param action - Action to fire when resulting property is invoked.
155
- */
156
- export function act (action: Async): typeof action & { active: boolean };
157
- export function act <S> (action: Async<S>): typeof action & { active: boolean };
158
-
159
- /**
160
- * Implement a computed value; output is returned by function from provided factory.
161
- *
162
- * @param compute - Factory function to generate a getter to subscribe dependancies.
163
- */
164
- export function from <R> (compute: (property: string) => <T>(this: T, state: T) => R | void, suspense: true): R;
165
- export function from <R, T> (compute: (property: string) => (this: T, state: T) => R | void, suspense: true): R;
166
- export function from <R> (compute: (property: string) => <T>(this: T, state: T) => R, suspense?: boolean): R;
167
- export function from <R, T> (compute: (property: string) => (this: T, state: T) => R, suspense?: boolean): R;
168
-
169
- /**
170
- * Implement a computed value; output will be generated by provided function.
171
- *
172
- * @param source - Source Model to find and subscribe to, for input.
173
- *
174
- * @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value.
175
- * Will update automatically as input values change.
176
- *
177
- * @param suspense - Compute function will suspend
178
- */
179
- export function from <T extends Class, R> (source: T, compute: (this: InstanceOf<T>, on: InstanceOf<T>) => R | void, suspense: true): R;
180
- export function from <T extends Class, R> (source: T, compute: (this: InstanceOf<T>, on: InstanceOf<T>) => R, suspense?: boolean): R;
181
-
182
- /**
183
- * Implement a computed value; output will be generated by provided function.
184
- *
185
- * @param source - Source model from which computed value will be a subscriber.
186
- *
187
- * @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value.
188
- * Will update automatically as input values change.
189
- */
190
- export function from <R, T> (source: T, compute: (this: T, on: T) => R): R;
191
-
192
- /**
193
- * Memoized value. Computes and stores a value returned by provided factory.
194
- * Equivalent to a getter, sans the automatic updates.
195
- *
196
- * @param compute - Factory for memoized value.
197
- * @param lazy - Wait until accessed to introduce value.
198
- *
199
- * @deprecated will be removed in favor of `set`
200
- */
201
- export function memo <R> (compute: () => R, lazy?: boolean): R;
202
- export function memo <R, T> (compute: (this: T) => R, lazy?: boolean): R;
203
-
204
- /**
205
- * Flag property as not to be tracked. Useful if changes often with no real-time impact.
206
- *
207
- * @param value - starting value of property.
208
- *
209
- * @deprecated will be removed in major version 1.0
210
- */
211
- export function lazy <T> (value?: T): T;
212
-
213
- /**
214
- * Pending value. Will suspend unless value is already defined,
215
- * suspense resolves when a value is then aquired.
216
- *
217
- * @deprecated will be removed in favor of `set`
218
- */
219
- export function pending <T = boolean> (): T;
220
-
221
- /**
222
- * Suspend during the execution of given function to obtain value.
223
- *
224
- * @param waitFor - Async function to suspend for.
225
- *
226
- * @deprecated will be removed in favor of `set`
227
- */
228
- export function pending (waitFor: () => Promise<void>): undefined;
229
- export function pending <T> (waitFor: (this: T) => Promise<void>): undefined;
230
- export function pending <R> (waitFor: () => Promise<R>): R;
231
- export function pending <R, T> (waitFor: (this: T) => Promise<R>): R;
232
-
233
- /**
234
- * Suspend for a computed value, returned by syncronous function.
235
- *
236
- * If accessed while computing to undefined, will throw a promise. Function is subscribed
237
- * and will re-evaluate anytime used properties change. Once function returns any value,
238
- * outstanding promises resolve and are not thrown on subsequent access of this property.
239
- *
240
- * Similar to `from`, compute function will only run when inputs change and not upon access.
241
- *
242
- * This behavior is recursive. If return value _becomes_ undefined, property
243
- * access will throw Promises again, awaiting its next value.
244
- *
245
- * @param source - Source object, from which computed value will be a subscriber.
246
- *
247
- * @param compute - Compute function returns output value. Bound to a subscriber of source.
248
- * Will re-run automatically as input values change.
249
- */
250
- export function pending <R, T> (source: T, compute: (this: T, on: T) => R): R; // ✅
251
-
252
- export namespace set {
253
- type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
254
-
255
- type Callback<T, S = any> = (this: S, argument: T) =>
256
- ((next: T) => void) | Promise<any> | void | boolean;
257
- }
258
-
259
- /**
260
- * Set property with a placeholder.
261
- *
262
- * Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
263
- * `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
264
- */
265
- export function set <T = any>(): T;
266
-
267
- /**
268
- * Set property with starting value `undefined`.
269
- *
270
- * If required and accessed while still empty, React Suspense will be thrown.
271
- * Property will reject any assignment of undefined.
272
- *
273
- * @param value - Starting value of host property (undefined).
274
- * @param required - Property will suspend callee if undefined at time of access.
275
- */
276
- export function set <T> (value: undefined, required: false): T | undefined;
277
- export function set <T> (value: undefined, required?: boolean): T;
278
-
279
- export function set <T> (value: undefined, onUpdate: set.Callback<T>): T | undefined;
280
- export function set <T, S> (value: undefined, onUpdate: set.Callback<T, S>): T | undefined;
281
-
282
- /**
283
- * Set property with an async function.
284
- *
285
- * Property cannot be accessed until factory resolves, yeilding a result.
286
- * If accessed while processing, React Suspense will be thrown.
287
- *
288
- * - `required: true` (default) -
289
- * Run factory immediately upon creation of model instance.
290
- * - `required: false` -
291
- * Run factory only if/when accessed.
292
- * Value will always throw suspense at least once - use with caution.
293
- *
294
- * @param factory - Callback run to derrive property value.
295
- * @param required - (default: true) Run factory immediately on creation, otherwise on access.
296
- */
297
- export function set <T>(factory: set.Factory<Promise<T>>, required: false): T | undefined;
298
- export function set <T, S>(factory: set.Factory<Promise<T>, S>, required: false): T | undefined;
299
-
300
- export function set <T>(factory: set.Factory<Promise<T>>, required?: boolean): T;
301
- export function set <T, S>(factory: set.Factory<Promise<T>, S>, required?: boolean): T;
302
-
303
- export function set <T> (value: set.Factory<Promise<T>>, onUpdate: set.Callback<T>): T;
304
- export function set <T, S> (value: set.Factory<Promise<T>, S>, onUpdate: set.Callback<T, S>): T;
305
-
306
- /**
307
- * Set property with a factory function.
308
- *
309
- * - `required: true` (default) -
310
- * Run factory immediately upon creation of model instance.
311
- * - `required: false` -
312
- * Run factory only if/when accessed.
313
- * Value will always throw suspense at least once - use with caution.
314
- *
315
- * @param factory - Callback run to derrive property value.
316
- * @param required - (default: true) Run factory immediately on creation, otherwise on access.
317
- */
318
- export function set <T>(factory: set.Factory<T>, required: false): T | undefined;
319
- export function set <T, S>(factory: set.Factory<T, S>, required: false): T | undefined;
320
-
321
- export function set <T>(factory: set.Factory<T>, required?: boolean): T;
322
- export function set <T, S>(factory: set.Factory<T, S>, required?: boolean): T;
323
-
324
- export function set <T> (value: set.Factory<T>, onUpdate: set.Callback<T>): T;
325
- export function set <T, S> (value: set.Factory<T, S>, onUpdate: set.Callback<T, S>): T;
326
-
@@ -1,32 +0,0 @@
1
- declare namespace Lifecycle {
2
- type Key = string | symbol | number;
3
- }
4
-
5
- /**
6
- * Model-Component Lifecycle
7
- *
8
- * Target contains available lifecycle callbacks.
9
- * A controller, when subscribed to within a component, will
10
- * call these respectively to that component's lifecycle.
11
- */
12
- interface Lifecycle {
13
- didMount?(tag?: Lifecycle.Key): void;
14
- willRender?(tag?: Lifecycle.Key): void;
15
- willUpdate?(tag?: Lifecycle.Key): void;
16
- willMount?(tag?: Lifecycle.Key): void;
17
- willUnmount?(tag?: Lifecycle.Key): void;
18
-
19
- elementDidMount?(tag: Lifecycle.Key): void;
20
- elementWillRender?(tag: Lifecycle.Key): void;
21
- elementWillUpdate?(tag: Lifecycle.Key): void;
22
- elementWillMount?(tag: Lifecycle.Key): void;
23
- elementWillUnmount?(tag: Lifecycle.Key): void;
24
-
25
- componentDidMount?(): void;
26
- componentWillRender?(): void;
27
- componentWillUpdate?(): void;
28
- componentWillMount?(): void;
29
- componentWillUnmount?(): void;
30
- }
31
-
32
- export = Lifecycle;