@expressive/mvc 1.0.0-beta.9 → 1.0.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 +594 -0
- package/lib/index.esm.js +1606 -0
- package/lib/index.js +1498 -881
- package/package.json +20 -22
- package/types/context.d.ts +0 -59
- package/types/dispatch.d.ts +0 -55
- package/types/index.d.ts +0 -9
- package/types/instructions.d.ts +0 -101
- package/types/lifecycle.d.ts +0 -30
- package/types/model.d.ts +0 -421
- package/types/selector.ts +0 -29
- package/types/types.d.ts +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/mvc",
|
|
3
|
-
"version": "1.0.0-beta.9",
|
|
4
3
|
"description": "Use classes to define state in React!",
|
|
5
4
|
"author": {
|
|
6
5
|
"name": "Gabe Klein",
|
|
@@ -14,42 +13,41 @@
|
|
|
14
13
|
},
|
|
15
14
|
"keywords": [
|
|
16
15
|
"react",
|
|
17
|
-
"
|
|
16
|
+
"mvc"
|
|
18
17
|
],
|
|
19
18
|
"main": "lib/index.js",
|
|
20
|
-
"
|
|
19
|
+
"module": "lib/index.esm.js",
|
|
20
|
+
"types": "lib/index.d.ts",
|
|
21
21
|
"files": [
|
|
22
|
-
"lib"
|
|
23
|
-
"types"
|
|
22
|
+
"lib"
|
|
24
23
|
],
|
|
25
24
|
"scripts": {
|
|
26
25
|
"build": "rollup --config",
|
|
27
|
-
"watch": "
|
|
26
|
+
"watch": "jest --watchAll",
|
|
27
|
+
"test": "jest --collectCoverage",
|
|
28
28
|
"prebuild": "rm -rf lib/",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"postversion": "npm run build; npm publish",
|
|
32
|
-
"postpublish": "git push; git push --tags; rm -rf lib",
|
|
33
|
-
"coverage": "jest --collectCoverage",
|
|
34
|
-
"test": "jest --watchAll"
|
|
29
|
+
"preversion": "npm run test && npm run build",
|
|
30
|
+
"postversion": "git push & npm publish"
|
|
35
31
|
},
|
|
36
32
|
"peerDependencies": {
|
|
37
|
-
"react": ">=
|
|
33
|
+
"react": ">=16.8.0 <19.0.0"
|
|
38
34
|
},
|
|
39
35
|
"devDependencies": {
|
|
40
|
-
"@rollup/plugin-commonjs": "^
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@types/jest": "^26.0.23",
|
|
36
|
+
"@rollup/plugin-commonjs": "^22.0.0",
|
|
37
|
+
"@testing-library/react-hooks": "^8.0.0",
|
|
38
|
+
"@types/jest": "^27.4.1",
|
|
44
39
|
"@types/node": "^15.12.4",
|
|
45
40
|
"@types/react": "^17.0.11",
|
|
46
|
-
"
|
|
41
|
+
"@types/react-test-renderer": "^18.0.0",
|
|
42
|
+
"jest": "^27.5.1",
|
|
47
43
|
"react": ">=17.0.2",
|
|
48
44
|
"react-test-renderer": "^17.0.2",
|
|
49
|
-
"rollup": "^2.
|
|
50
|
-
"rollup-plugin-
|
|
45
|
+
"rollup": "^2.61.1",
|
|
46
|
+
"rollup-plugin-dts": "^4.2.1",
|
|
47
|
+
"rollup-plugin-typescript2": "^0.31.1",
|
|
51
48
|
"ts-jest": "^27.0.3",
|
|
52
49
|
"tslib": "^2.3.0",
|
|
53
|
-
"typescript": "
|
|
54
|
-
}
|
|
50
|
+
"typescript": "4.6.3"
|
|
51
|
+
},
|
|
52
|
+
"version": "1.0.0"
|
|
55
53
|
}
|
package/types/context.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Consumer, ReactElement, ReactNode, Component, ComponentType } from "react";
|
|
2
|
-
import { Model } from "./model"
|
|
3
|
-
import { Class } from "./types";
|
|
4
|
-
|
|
5
|
-
type Output = ReactElement<any, any> | null;
|
|
6
|
-
|
|
7
|
-
export namespace Provider {
|
|
8
|
-
type Item = Model | typeof Model;
|
|
9
|
-
type Collection<T extends Item> = T[] | { [key: string]: T };
|
|
10
|
-
type Existent<E> = E extends Class ? InstanceType<E> : E extends Model ? E : never;
|
|
11
|
-
|
|
12
|
-
type NormalProps<E, I = Existent<E>> =
|
|
13
|
-
& { of: E, children: ReactNode | ((instance: I) => ReactNode) }
|
|
14
|
-
& Model.Data<I>;
|
|
15
|
-
|
|
16
|
-
// FIX: This fails to exclude properties with same key but different type.
|
|
17
|
-
type MultipleProps<T extends Item> =
|
|
18
|
-
& { of: Collection<T>, children?: ReactNode | (() => ReactNode) }
|
|
19
|
-
& Model.Data<Existent<T>>;
|
|
20
|
-
|
|
21
|
-
type Props<T extends Item> = MultipleProps<T> | NormalProps<T>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Provider<T extends Provider.Item>(props: Provider.Props<T>): Output;
|
|
25
|
-
|
|
26
|
-
export namespace Consumer {
|
|
27
|
-
type HasProps<E extends Class> = {
|
|
28
|
-
/** Type of controller to fetch from context. */
|
|
29
|
-
of: E;
|
|
30
|
-
/**
|
|
31
|
-
* Getter function. Is called on every natural render of this component.
|
|
32
|
-
* Will throw if usable instance cannot be found in context.
|
|
33
|
-
*/
|
|
34
|
-
has: (value: InstanceType<E>) => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type GetProps<E extends Class> = {
|
|
38
|
-
/** Type of controller to fetch from context. */
|
|
39
|
-
of: E;
|
|
40
|
-
/** Getter function. Is called on every natural render of this component. */
|
|
41
|
-
get: (value: InstanceType<E> | undefined) => void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type RenderProps<E extends Class> = {
|
|
45
|
-
/** Type of controller to fetch from context. */
|
|
46
|
-
of: E;
|
|
47
|
-
/**
|
|
48
|
-
* Render function, will receive instance of desired controller.
|
|
49
|
-
*
|
|
50
|
-
* Similar to `tap()`, updates to properties accessed in
|
|
51
|
-
* this function will cause a refresh when they change.
|
|
52
|
-
*/
|
|
53
|
-
children: (value: InstanceType<E>) => Output;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type Props<T extends Class> = HasProps<T> | GetProps<T> | RenderProps<T>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function Consumer<T extends Class>(props: Consumer.Props<T>): Output;
|
package/types/dispatch.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Model } from './model';
|
|
2
|
-
import { Selector } from './selector';
|
|
3
|
-
import { Callback, EffectCallback, UpdateCallback } from './types';
|
|
4
|
-
|
|
5
|
-
type CallbackFor<S extends Selector.Function<any>, T> =
|
|
6
|
-
(this: T, value: Selector.Gets<S>, key: Selector.From<S>) => void;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Observable Instance
|
|
10
|
-
*
|
|
11
|
-
* Implements internal value tracking.
|
|
12
|
-
* Able to be subscribed to, per-value to know when updated.
|
|
13
|
-
*/
|
|
14
|
-
interface Dispatch {
|
|
15
|
-
// Keyed
|
|
16
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: CallbackFor<S, this>, squash?: false, once?: boolean): Callback;
|
|
17
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
|
|
18
|
-
// Squash
|
|
19
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true, once?: boolean): Callback;
|
|
20
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
21
|
-
// Unknown
|
|
22
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean, once?: boolean): Callback;
|
|
23
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
24
|
-
|
|
25
|
-
// Keyed
|
|
26
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: CallbackFor<S, this>, squash?: false): Callback;
|
|
27
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false): Callback;
|
|
28
|
-
// Squash
|
|
29
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true): Callback;
|
|
30
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
|
|
31
|
-
// Promise
|
|
32
|
-
once <S extends Model.SelectEvents<this>> (via: S): Promise<Selector.From<S>[]>;
|
|
33
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[]): Promise<P[]>;
|
|
34
|
-
// Unknown
|
|
35
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean): Callback;
|
|
36
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean): Callback;
|
|
37
|
-
|
|
38
|
-
effect(callback: EffectCallback<this>, select?: Model.SelectFields<this>): Callback;
|
|
39
|
-
effect(callback: EffectCallback<this>, select?: (keyof this)[]): Callback;
|
|
40
|
-
|
|
41
|
-
import <O extends Model.Data<this>> (via: O, select?: string[] | Model.SelectFields<this>): void;
|
|
42
|
-
|
|
43
|
-
export(): Model.State<this>;
|
|
44
|
-
export <P extends Model.Fields<this>> (select: P[]): Model.State<this, P>;
|
|
45
|
-
export <S extends Model.SelectFields<this>> (select: S): Model.State<this, Selector.From<S>>;
|
|
46
|
-
|
|
47
|
-
update(strict: true): Promise<string[]>;
|
|
48
|
-
update(strict: false): Promise<false>;
|
|
49
|
-
update(strict?: boolean): Promise<string[] | false>;
|
|
50
|
-
update(keys: Model.Fields<this>[]): Promise<string[]>;
|
|
51
|
-
update(keys: Model.Fields<this>): Promise<string[]>;
|
|
52
|
-
update(keys: Model.SelectFields<this>): Promise<string[]>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export = Dispatch;
|
package/types/index.d.ts
DELETED
package/types/instructions.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import Model from '.';
|
|
2
|
-
import { Async, Class, EffectCallback, 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 set <T = any> (
|
|
9
|
-
instruction: Model.Instruction<T>,
|
|
10
|
-
name?: string
|
|
11
|
-
): T;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new child-instance of specified controller.
|
|
15
|
-
*
|
|
16
|
-
* @param Peer - Type of Model to create and apply to host property.
|
|
17
|
-
* @param callback - Fired after controller is created and ready for use.
|
|
18
|
-
*/
|
|
19
|
-
export function use <T extends typeof Model> (Peer: T, callback: (i?: InstanceOf<T>) => void): InstanceOf<T> | undefined;
|
|
20
|
-
export function use <T extends typeof Model> (Peer: T, required: false): InstanceOf<T> | undefined;
|
|
21
|
-
export function use <T extends typeof Model> (Peer: T, required?: true): InstanceOf<T>;
|
|
22
|
-
export function use <T extends Model | undefined> (Peer: () => T, callback?: (i: T) => void): T;
|
|
23
|
-
export function use <T extends Model> (): T | undefined;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Fetches and assigns the controller which spawned this host.
|
|
27
|
-
* When parent assigns an instance via `use()` directive, it
|
|
28
|
-
* will be made available to child upon this request.
|
|
29
|
-
*
|
|
30
|
-
* @param Expects - Type of controller compatible with this class.
|
|
31
|
-
* @param required - Throw if controller is created independantly.
|
|
32
|
-
*/
|
|
33
|
-
export function parent <T extends typeof Model> (Expects: T, required: true): InstanceOf<T>;
|
|
34
|
-
export function parent <T extends typeof Model> (Expects: T, required?: false): InstanceOf<T> | undefined;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Find and attach most applicable instance of Model via context.
|
|
38
|
-
*
|
|
39
|
-
* Expects a `<Provider>` of target controller to exist.
|
|
40
|
-
* Host controller will search element-hierarchy relative to where it spawned.
|
|
41
|
-
*
|
|
42
|
-
* @param Type - Type of controller to attach to property.
|
|
43
|
-
* @param required - Throw if instance of Type cannot be found.
|
|
44
|
-
*/
|
|
45
|
-
export function tap <T extends Class> (Type: T, required?: boolean): InstanceOf<T>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Sets property to synchronously call effect upon update.
|
|
49
|
-
*
|
|
50
|
-
* @param starting - Beginning value of host property.
|
|
51
|
-
* @param callback - Effect-callback fired upon set of host property.
|
|
52
|
-
*/
|
|
53
|
-
export function on <T = any> (initial: undefined, callback: EffectCallback<T>): T | undefined;
|
|
54
|
-
export function on <T = any> (initial: T, callback: EffectCallback<T>): T;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Creates a ref-compatible property for use with components.
|
|
58
|
-
* Will persist value, and updates to this are made part of controller event-stream.
|
|
59
|
-
*
|
|
60
|
-
* *Output is simultaneously a ref-function and ref-object, use as needed.*
|
|
61
|
-
*
|
|
62
|
-
* @param callback - Optional callback to synchronously fire when reference is first set or does update.
|
|
63
|
-
*/
|
|
64
|
-
export function ref <T = HTMLElement> (callback?: EffectCallback<T>): Model.Ref<T>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Sets an exotic method with managed ready-state. Property accepts an async function.
|
|
68
|
-
*
|
|
69
|
-
* When an act-method is invoked, its `active` property to true for duration of call.
|
|
70
|
-
* This is emitted as an update to property, both when called and after returns (or throws).
|
|
71
|
-
*
|
|
72
|
-
* **Note:** Subsequent calls will immediately throw if one is still pending.
|
|
73
|
-
*
|
|
74
|
-
* @param action - Action to fire when resulting property is invoked.
|
|
75
|
-
*/
|
|
76
|
-
export function act <T extends Async>(action: T): T & { active: boolean };
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Implement a computed value; output will be generated by provided function.
|
|
80
|
-
*
|
|
81
|
-
* *Alternative to using native getters; works exactly the same!*
|
|
82
|
-
*
|
|
83
|
-
* @param fn - Factory function to generate value and subscribe dependancies.
|
|
84
|
-
*/
|
|
85
|
-
export function from <T, R>(fn: (this: T, on: T) => R): R;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Memoized value. Computes and stores a value returned by provided factory.
|
|
89
|
-
* Equivalent to a getter, sans the automatic updates.
|
|
90
|
-
*
|
|
91
|
-
* @param compute - Factory for memoized value.
|
|
92
|
-
* @param lazy - Wait until accessed to introduce value.
|
|
93
|
-
*/
|
|
94
|
-
export function memo <T> (compute: () => T, lazy?: boolean): T;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Flag property as not to be tracked. Useful if changes often with no real-time impact.
|
|
98
|
-
*
|
|
99
|
-
* @param value - starting value of property.
|
|
100
|
-
*/
|
|
101
|
-
export function lazy <T> (value?: T): T;
|
package/types/lifecycle.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Key } from "./types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Model-Component Lifecycle
|
|
5
|
-
*
|
|
6
|
-
* Target contains available lifecycle callbacks.
|
|
7
|
-
* A controller, when subscribed to within a component, will
|
|
8
|
-
* call these respectively to that component's lifecycle.
|
|
9
|
-
*/
|
|
10
|
-
interface Lifecycle {
|
|
11
|
-
didMount?(tag?: Key): void;
|
|
12
|
-
willRender?(tag?: Key): void;
|
|
13
|
-
willUpdate?(tag?: Key): void;
|
|
14
|
-
willMount?(tag?: Key): void;
|
|
15
|
-
willUnmount?(tag?: Key): void;
|
|
16
|
-
|
|
17
|
-
elementDidMount?(tag: Key): void;
|
|
18
|
-
elementWillRender?(tag: Key): void;
|
|
19
|
-
elementWillUpdate?(tag: Key): void;
|
|
20
|
-
elementWillMount?(tag: Key): void;
|
|
21
|
-
elementWillUnmount?(tag: Key): void;
|
|
22
|
-
|
|
23
|
-
componentDidMount?(): void;
|
|
24
|
-
componentWillRender?(): void;
|
|
25
|
-
componentWillUpdate?(): void;
|
|
26
|
-
componentWillMount?(): void;
|
|
27
|
-
componentWillUnmount?(): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export = Lifecycle;
|