@expressive/mvc 0.87.0 → 0.89.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/README.md +19 -19
- package/dist/component.d.ts +28 -16
- package/dist/component.js +53 -72
- package/dist/component.js.map +1 -1
- package/dist/context.d.ts +28 -26
- package/dist/context.js +45 -27
- package/dist/context.js.map +1 -1
- package/dist/dispatch.d.ts +6 -1
- package/dist/dispatch.js +14 -6
- package/dist/dispatch.js.map +1 -1
- package/dist/field/def.d.ts +3 -3
- package/dist/field/def.js +7 -7
- package/dist/field/def.js.map +1 -1
- package/dist/field/get.d.ts +16 -16
- package/dist/field/get.js +21 -5
- package/dist/field/get.js.map +1 -1
- package/dist/field/has.d.ts +8 -8
- package/dist/field/has.js +3 -3
- package/dist/field/has.js.map +1 -1
- package/dist/field/map.d.ts +2 -2
- package/dist/field/map.js +2 -2
- package/dist/field/map.js.map +1 -1
- package/dist/field/ref.d.ts +8 -8
- package/dist/field/ref.js +3 -3
- package/dist/field/ref.js.map +1 -1
- package/dist/field/set.js +1 -1
- package/dist/field/set.js.map +1 -1
- package/dist/hot.d.ts +5 -8
- package/dist/hot.js +126 -18
- package/dist/hot.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -2
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.d.ts +77 -4
- package/dist/jsx-runtime.js +67 -2
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/observable.d.ts +7 -4
- package/dist/observable.js +94 -27
- package/dist/observable.js.map +1 -1
- package/dist/state.d.ts +154 -112
- package/dist/state.js +115 -192
- package/dist/state.js.map +1 -1
- package/package.json +7 -5
- package/dist/_virtual/_rolldown/runtime.js +0 -18
- package/dist/caught.d.ts +0 -5237
- package/dist/caught.js +0 -64
- package/dist/caught.js.map +0 -1
- package/dist/runtime.d.ts +0 -72
- package/dist/runtime.js +0 -70
- package/dist/runtime.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,24 +11,24 @@
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
The core of [Expressive MVC](https://github.com/gabeklein/expressive-mvc): reactive primitives built around plain classes, with no framework dependency. Provides the `
|
|
14
|
+
The core of [Expressive MVC](https://github.com/gabeklein/expressive-mvc): reactive primitives built around plain classes, with no framework dependency. Provides the `Model` class, instructions, context, and the renderer-agnostic `Component` that adapters like [`@expressive/react`](https://www.npmjs.com/package/@expressive/react) build on.
|
|
15
15
|
|
|
16
|
-
> **Building a React app?** Install [`@expressive/react`](https://www.npmjs.com/package/@expressive/react)
|
|
16
|
+
> **Building a React app?** Install [`@expressive/react`](https://www.npmjs.com/package/@expressive/react) alongside this package - the adapter declares `@expressive/mvc` as a peer dependency, so both belong in your `package.json`. Import `Model`, `Component`, and every instruction from this package, and import the adapter once from your entry so the host registers. The same holds for [`@expressive/dom`](https://www.npmjs.com/package/@expressive/dom), the renderer without React.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Installed alone, it serves host-agnostic code - a shared domain package, a Node service, or a new adapter:
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
npm install @expressive/mvc
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Model
|
|
25
25
|
|
|
26
|
-
A `
|
|
26
|
+
A `Model` is a class whose fields are reactive - read to subscribe, assign to update. Getters are cached computed values.
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
import {
|
|
29
|
+
import { Model } from '@expressive/mvc';
|
|
30
30
|
|
|
31
|
-
class Counter extends
|
|
31
|
+
class Counter extends Model {
|
|
32
32
|
count = 0;
|
|
33
33
|
increment = () => this.count++;
|
|
34
34
|
|
|
@@ -47,7 +47,7 @@ counter.get(({ count }) => {
|
|
|
47
47
|
counter.increment(); // -> "count is 1"
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Instances run and test anywhere - no renderer required.
|
|
51
51
|
|
|
52
52
|
## Instructions
|
|
53
53
|
|
|
@@ -57,14 +57,14 @@ Field initializers that change how a property behaves:
|
|
|
57
57
|
|---|---|
|
|
58
58
|
| `ref()` | a mutable reference (e.g. a DOM node) that's still reactive |
|
|
59
59
|
| `set()` | computed values, smart setters, side-effects on assignment |
|
|
60
|
-
| `get()` | dependency injection - pull another `
|
|
60
|
+
| `get()` | dependency injection - pull another `Model` from context |
|
|
61
61
|
| `map()` | a shallow-reactive Map |
|
|
62
62
|
| `has()` | an owned reactive collection - an ordered list or a spawned pool |
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
import {
|
|
65
|
+
import { Model, set, has, map } from '@expressive/mvc';
|
|
66
66
|
|
|
67
|
-
class Cart extends
|
|
67
|
+
class Cart extends Model {
|
|
68
68
|
items = has<Item>(); // reactive collection
|
|
69
69
|
products = map<string, Product>(); // reactive keyed collection
|
|
70
70
|
coupon = set('', code => apply(code)); // side-effect on assignment
|
|
@@ -74,7 +74,7 @@ class Cart extends State {
|
|
|
74
74
|
## Lifecycle
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
-
class Timer extends
|
|
77
|
+
class Timer extends Model {
|
|
78
78
|
seconds = 0;
|
|
79
79
|
|
|
80
80
|
new() { // runs once on activation
|
|
@@ -89,22 +89,22 @@ timer.set(null); // destroy - runs cleanup, freezes state
|
|
|
89
89
|
|
|
90
90
|
## Context & composition
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
Instances find each other through context, and compose by holding one another:
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
import {
|
|
95
|
+
import { Model, get } from '@expressive/mvc';
|
|
96
96
|
|
|
97
|
-
class Session extends
|
|
97
|
+
class Session extends Model {
|
|
98
98
|
user = 'guest';
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
class Profile extends
|
|
101
|
+
class Profile extends Model {
|
|
102
102
|
session = get(Session); // injected from the nearest provider
|
|
103
|
-
address = new Address(); // nested
|
|
103
|
+
address = new Address(); // nested instance - its changes bubble up
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
An adapter (e.g. [`@expressive/react`](https://www.npmjs.com/package/@expressive/react)) supplies the provider that places a `
|
|
107
|
+
An adapter (e.g. [`@expressive/react`](https://www.npmjs.com/package/@expressive/react)) supplies the provider that places a `Model` in a tree; `get()` pulls it back out.
|
|
108
108
|
|
|
109
109
|
## Events
|
|
110
110
|
|
|
@@ -130,7 +130,7 @@ off(); // stop listening
|
|
|
130
130
|
}
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
`Component` - a `
|
|
133
|
+
`Component` - a `Model` usable in JSX - lives here as the agnostic base. For using it in an app (rendering, props, subcomponents, suspense), see **[`@expressive/react`](https://www.npmjs.com/package/@expressive/react)**.
|
|
134
134
|
|
|
135
135
|
---
|
|
136
136
|
|
package/dist/component.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Host } from "./runtime.js";
|
|
1
|
+
import { Model } from "./state.js";
|
|
2
|
+
import { Host } from "./jsx-runtime.js";
|
|
3
3
|
|
|
4
4
|
//#region src/component.d.ts
|
|
5
5
|
type IfEquals<X, Y, A, B> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B;
|
|
6
6
|
/** Keys of T which are settable (excludes get-only accessors and `readonly`). */
|
|
7
7
|
type Acceptable<T> = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P, never> }[keyof T];
|
|
8
|
+
type ForProps<T extends Model> = {
|
|
9
|
+
children?: Component.Node;
|
|
10
|
+
fallback?: Component.Node | false;
|
|
11
|
+
catch?: (error: Error, instance: Component) => Promise<void> | void;
|
|
12
|
+
} & ({
|
|
13
|
+
for: Model.Extends<T>;
|
|
14
|
+
is?: (instance: T) => void;
|
|
15
|
+
} | {
|
|
16
|
+
for: T | undefined;
|
|
17
|
+
is?: never;
|
|
18
|
+
}) & { [K in Exclude<keyof T, keyof Model> & Acceptable<T>]?: T[K] };
|
|
8
19
|
declare namespace Component {
|
|
9
20
|
/**
|
|
10
21
|
* Host element type produced by `Component.render`. Delegates to the
|
|
@@ -17,7 +28,7 @@ declare namespace Component {
|
|
|
17
28
|
type Node = Host extends {
|
|
18
29
|
node: infer T;
|
|
19
30
|
} ? T : any;
|
|
20
|
-
interface BaseProps<T extends Component
|
|
31
|
+
interface BaseProps<T extends Component<any>> {
|
|
21
32
|
/**
|
|
22
33
|
* Callback for newly created instance. Only called once.
|
|
23
34
|
*
|
|
@@ -25,30 +36,37 @@ declare namespace Component {
|
|
|
25
36
|
* may configure state that `new()` then observes. To react to a fully
|
|
26
37
|
* initialized instance instead, use `watch` or an effect.
|
|
27
38
|
*/
|
|
28
|
-
is
|
|
39
|
+
is?(instance: T): void;
|
|
29
40
|
/**
|
|
30
41
|
* Fallback to show when suspended or in error recovery.
|
|
31
42
|
* Pass `false` to opt out of the component's own suspense boundary,
|
|
32
43
|
* letting suspension bubble to an ancestor.
|
|
33
44
|
*/
|
|
34
45
|
fallback?: Component.Node;
|
|
46
|
+
/**
|
|
47
|
+
* Called when this element's content throws, in place of the class's own
|
|
48
|
+
* `catch`. A returned promise retries once settled.
|
|
49
|
+
*/
|
|
50
|
+
catch?(error: Error, instance: T): Promise<void> | void;
|
|
35
51
|
}
|
|
36
|
-
type
|
|
52
|
+
type ModelProps<T extends Model> = { [K in Exclude<keyof T, keyof Component> & Acceptable<T>]?: T[K] };
|
|
53
|
+
/** @deprecated Renamed to `ModelProps`. */
|
|
54
|
+
type StateProps<T extends Model> = ModelProps<T>;
|
|
37
55
|
type RenderProps<T> = [T] extends [(props: infer P) => any] ? [keyof NonNullable<P>] extends [never] ? {
|
|
38
56
|
children?: Component.Node;
|
|
39
57
|
} : NonNullable<P> : {
|
|
40
58
|
children?: Component.Node;
|
|
41
59
|
};
|
|
42
|
-
type Props<T extends Component
|
|
60
|
+
type Props<T extends Component<any>> = ModelProps<T> & BaseProps<T> & RenderProps<T['render']>;
|
|
43
61
|
}
|
|
44
|
-
declare class Component extends
|
|
62
|
+
declare class Component<P = unknown> extends Model {
|
|
45
63
|
/**
|
|
46
64
|
* All JSX attributes passed to this component.
|
|
47
65
|
* Includes state-derived props, render props, and built-in props like `is` and `fallback`.
|
|
48
66
|
*
|
|
49
67
|
* Will incorperate extra props you declare as props parameter in `render` method.
|
|
50
68
|
*/
|
|
51
|
-
readonly props: Component.Props<this>;
|
|
69
|
+
readonly props: [P] extends [Model] ? ForProps<P> : Component.Props<this>;
|
|
52
70
|
/** Stable identity used when this instance is rendered in a collection. */
|
|
53
71
|
readonly key: string;
|
|
54
72
|
/**
|
|
@@ -70,10 +88,6 @@ declare class Component extends State {
|
|
|
70
88
|
* props from JSX, beyond those merged to state properties; declare its shape
|
|
71
89
|
* via `props = {} as { ... }`. Without a parameter (the default below),
|
|
72
90
|
* children pass through.
|
|
73
|
-
*
|
|
74
|
-
* The constructor installs a composed `render` per instance; the bootstrap
|
|
75
|
-
* `type` pass seals this and any override non-configurable, keeping it the
|
|
76
|
-
* content-render seam the chain reads.
|
|
77
91
|
*/
|
|
78
92
|
render(props?: {}): Component.Node;
|
|
79
93
|
/**
|
|
@@ -85,10 +99,8 @@ declare class Component extends State {
|
|
|
85
99
|
* await async recovery, or await user interaction before retrying. If you
|
|
86
100
|
* assign a fallback within catch, it will be reverted after resolved.
|
|
87
101
|
*/
|
|
88
|
-
catch?(error: Error): Promise<void> | void;
|
|
102
|
+
catch?(error: Error, instance: this): Promise<void> | void;
|
|
89
103
|
}
|
|
90
|
-
/** Drop composed renders, so each is rebuilt from current prototypes. */
|
|
91
|
-
declare function rechain(): void;
|
|
92
104
|
//#endregion
|
|
93
|
-
export { Component
|
|
105
|
+
export { Component };
|
|
94
106
|
//# sourceMappingURL=component.d.ts.map
|
package/dist/component.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Model, adopt, trailing } from "./state.js";
|
|
2
2
|
import { Context } from "./context.js";
|
|
3
3
|
import { set } from "./field/set.js";
|
|
4
4
|
|
|
5
5
|
//#region src/component.ts
|
|
6
6
|
const PENDING = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
|
|
8
|
-
let CHAIN = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
var Component = class extends State {
|
|
7
|
+
var Component = class Component extends Model {
|
|
10
8
|
/**
|
|
11
9
|
* Content to display while this component or its children are suspended.
|
|
12
10
|
* Will cover suspense by pending properties in `this.render` as well.
|
|
@@ -21,6 +19,7 @@ var Component = class extends State {
|
|
|
21
19
|
if (props == null) props = {};
|
|
22
20
|
const seen = {};
|
|
23
21
|
const twin = PENDING.get(props);
|
|
22
|
+
const provider = new.target === Component && "for" in props;
|
|
24
23
|
if (typeof props == "object") merge(props);
|
|
25
24
|
function merge(props) {
|
|
26
25
|
for (const k in props) seen[k] = void 0;
|
|
@@ -38,7 +37,8 @@ var Component = class extends State {
|
|
|
38
37
|
trailing(other).forEach((orphan) => orphan.set(null));
|
|
39
38
|
other.set(null);
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
if (provider) provide(this);
|
|
41
|
+
else props.is?.(this);
|
|
42
42
|
Object.defineProperty(this, "props", { enumerable: false });
|
|
43
43
|
PENDING.delete(props);
|
|
44
44
|
}
|
|
@@ -48,14 +48,6 @@ var Component = class extends State {
|
|
|
48
48
|
this.set("props", () => {
|
|
49
49
|
this.set(merge(this.props));
|
|
50
50
|
});
|
|
51
|
-
const self = this;
|
|
52
|
-
Object.defineProperty(this, "render", {
|
|
53
|
-
writable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
value(props) {
|
|
56
|
-
return render(self).call(this, props);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
51
|
}
|
|
60
52
|
/**
|
|
61
53
|
* Output for this component. Override to define custom JSX.
|
|
@@ -65,10 +57,6 @@ var Component = class extends State {
|
|
|
65
57
|
* props from JSX, beyond those merged to state properties; declare its shape
|
|
66
58
|
* via `props = {} as { ... }`. Without a parameter (the default below),
|
|
67
59
|
* children pass through.
|
|
68
|
-
*
|
|
69
|
-
* The constructor installs a composed `render` per instance; the bootstrap
|
|
70
|
-
* `type` pass seals this and any override non-configurable, keeping it the
|
|
71
|
-
* content-render seam the chain reads.
|
|
72
60
|
*/
|
|
73
61
|
render(props) {
|
|
74
62
|
const { children } = props || this.props;
|
|
@@ -87,65 +75,58 @@ Object.defineProperty(Component.prototype, "key", {
|
|
|
87
75
|
Object.defineProperty(this, "key", { value });
|
|
88
76
|
}
|
|
89
77
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
...desc,
|
|
106
|
-
configurable: false
|
|
107
|
-
});
|
|
78
|
+
Component.on({ setup(self) {
|
|
79
|
+
if (Object.getOwnPropertyDescriptor(self, "key")?.configurable) Object.defineProperty(self, "key", {
|
|
80
|
+
enumerable: false,
|
|
81
|
+
writable: false
|
|
82
|
+
});
|
|
83
|
+
} });
|
|
84
|
+
function provide(self) {
|
|
85
|
+
let input;
|
|
86
|
+
let target;
|
|
87
|
+
let owned;
|
|
88
|
+
let mounted = false;
|
|
89
|
+
let release;
|
|
90
|
+
function unmount() {
|
|
91
|
+
if (typeof release == "function") release();
|
|
92
|
+
release = void 0;
|
|
108
93
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
while ((proto = Object.getPrototypeOf(proto)) !== Component.prototype) {
|
|
122
|
-
const desc = Object.getOwnPropertyDescriptor(proto, "render");
|
|
123
|
-
if (desc) {
|
|
124
|
-
const layer = unbind(desc.get || desc.value);
|
|
125
|
-
render = render ? compose(layer, render) : layer;
|
|
94
|
+
const inherited = self.mount;
|
|
95
|
+
Object.defineProperty(self, "mount", {
|
|
96
|
+
configurable: true,
|
|
97
|
+
value() {
|
|
98
|
+
const done = inherited?.call(self);
|
|
99
|
+
mounted = true;
|
|
100
|
+
release = owned?.mount?.();
|
|
101
|
+
return () => {
|
|
102
|
+
mounted = false;
|
|
103
|
+
unmount();
|
|
104
|
+
if (typeof done == "function") done();
|
|
105
|
+
};
|
|
126
106
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return
|
|
107
|
+
});
|
|
108
|
+
function sync() {
|
|
109
|
+
const { for: next, is, children, fallback, catch: _catch, ...rest } = self.props;
|
|
110
|
+
if (fallback === void 0) self.fallback = false;
|
|
111
|
+
if (next !== input) {
|
|
112
|
+
input = next;
|
|
113
|
+
unmount();
|
|
114
|
+
if (Model.is(next)) {
|
|
115
|
+
adopt(self, "for", target = new next(rest));
|
|
116
|
+
owned = target;
|
|
117
|
+
is?.(target);
|
|
118
|
+
if (mounted) release = owned.mount?.();
|
|
119
|
+
return;
|
|
140
120
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
121
|
+
owned = void 0;
|
|
122
|
+
adopt(self, "for", target = next instanceof Model ? next : void 0);
|
|
123
|
+
}
|
|
124
|
+
target?.set(rest);
|
|
125
|
+
}
|
|
126
|
+
sync();
|
|
127
|
+
self.set("props", sync);
|
|
147
128
|
}
|
|
148
129
|
|
|
149
130
|
//#endregion
|
|
150
|
-
export { Component
|
|
131
|
+
export { Component };
|
|
151
132
|
//# sourceMappingURL=component.js.map
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","names":[],"sources":["../src/component.ts"],"sourcesContent":["import { Context } from './context';\nimport { set } from './field/set';\nimport { State, trailing, unbind } from './state';\n\nimport type { Host } from './runtime';\n\nconst PENDING = new WeakMap<object, Component>();\n\n/** Per-class composed content render. */\nlet CHAIN = new WeakMap<Function, Function>();\n\ntype IfEquals<X, Y, A, B> =\n (<T>() => T extends X ? 1 : 2) extends\n (<T>() => T extends Y ? 1 : 2) ? A : B;\n\n/** Keys of T which are settable (excludes get-only accessors and `readonly`). */\ntype Acceptable<T> = {\n [P in keyof T]-?: IfEquals<\n { [Q in P]: T[P] },\n { -readonly [Q in P]: T[P] },\n P, never\n >;\n}[keyof T];\n\ndeclare namespace Component {\n /**\n * Host element type produced by `Component.render`. Delegates to the\n * {@link Host} manifest on the jsx-runtime entry; falls back to `any`\n * until an adapter augments it with `node`. `any` (not `unknown`) so an\n * un-annotated `render` override in a host-agnostic package still emits a\n * JSX-valid return - `any` is assignable to every host's node type, where\n * `unknown` is assignable to none.\n */\n type Node = Host extends { node: infer T } ? T : any;\n\n interface BaseProps<T extends Component> {\n /**\n * Callback for newly created instance. Only called once.\n *\n * Runs after props apply but **before** the `new()` lifecycle hook - so it\n * may configure state that `new()` then observes. To react to a fully\n * initialized instance instead, use `watch` or an effect.\n */\n is?: (instance: T) => void;\n\n /**\n * Fallback to show when suspended or in error recovery.\n * Pass `false` to opt out of the component's own suspense boundary,\n * letting suspension bubble to an ancestor.\n */\n fallback?: Component.Node;\n }\n\n type StateProps<T extends State> = {\n [K in Exclude<keyof T, keyof Component> & Acceptable<T>]?: T[K];\n };\n\n type RenderProps<T> = [T] extends [(props: infer P) => any]\n ? [keyof NonNullable<P>] extends [never]\n ? { children?: Component.Node }\n : NonNullable<P>\n : { children?: Component.Node };\n\n type Props<T extends Component> =\n & StateProps<T>\n & BaseProps<T>\n & RenderProps<T['render']>;\n}\n\nclass Component extends State {\n /**\n * All JSX attributes passed to this component.\n * Includes state-derived props, render props, and built-in props like `is` and `fallback`.\n *\n * Will incorperate extra props you declare as props parameter in `render` method.\n */\n declare readonly props: Component.Props<this>;\n\n /** Stable identity used when this instance is rendered in a collection. */\n declare readonly key: string;\n\n /**\n * Content to display while this component or its children are suspended.\n * Will cover suspense by pending properties in `this.render` as well.\n * Can be set as a class property or overridden via the `fallback` JSX prop.\n *\n * Defaults to null - nothing will be rendered.\n * Set `false` to opt out of having a boundary at all - suspension then\n * bubbles to the nearest ancestor boundary.\n */\n fallback: Component.Node = set(null);\n\n constructor(props?: any, ...rest: any[]) {\n if (props == null) props = {};\n\n const seen = {} as Record<string, undefined>;\n const twin = PENDING.get(props);\n\n if (typeof props == 'object') merge(props);\n\n function merge(props: {}) {\n for (const k in props) seen[k] = undefined;\n return { ...seen, ...props };\n }\n\n super([\n props,\n rest.filter((x) => !(x instanceof Context)),\n () => {\n const other = twin || PENDING.get(props)!;\n\n if (other !== this) {\n trailing(other).forEach((orphan) => orphan.set(null));\n other.set(null);\n }\n\n props.is?.(this);\n Object.defineProperty(this, 'props', { enumerable: false });\n PENDING.delete(props);\n }\n ]);\n\n PENDING.set(props, this);\n\n this.props = props;\n this.set('props', () => {\n this.set(merge(this.props));\n });\n\n const self = this;\n\n Object.defineProperty(this, 'render', {\n writable: true,\n configurable: true,\n value(this: Component, props?: {}) {\n return render(self).call(this, props);\n }\n });\n }\n\n /**\n * Output for this component. Override to define custom JSX.\n *\n * Properties accessed via `this` are reactive and trigger a render when they\n * change, in addition to props. Accepts an optional parameter to receive extra\n * props from JSX, beyond those merged to state properties; declare its shape\n * via `props = {} as { ... }`. Without a parameter (the default below),\n * children pass through.\n *\n * The constructor installs a composed `render` per instance; the bootstrap\n * `type` pass seals this and any override non-configurable, keeping it the\n * content-render seam the chain reads.\n */\n render(props?: {}): Component.Node {\n const { children } = (props || this.props) as { children?: Component.Node };\n return children || null;\n }\n\n /**\n * Called when a child component throws during render.\n * While this is pending, `fallback` is displayed.\n * When resolved, the error boundary resets and `render` is called again.\n *\n * Override to handle errors - set `this.fallback` for error-specific UI,\n * await async recovery, or await user interaction before retrying. If you\n * assign a fallback within catch, it will be reverted after resolved.\n */\n catch?(error: Error): Promise<void> | void;\n}\n\n/**\n * Default `key` accessor. The get/set pair keeps it off observed state.\n */\nObject.defineProperty(Component.prototype, 'key', {\n configurable: true,\n get() {\n return String(this);\n },\n set(value) {\n Object.defineProperty(this, 'key', { value });\n }\n});\n\n/**\n * Seal each class's own `render` non-configurable at bootstrap so member\n * classification leaves it unbound - it stays the content-render seam the chain\n * reads (and which adapters like preact detect as the class-component marker).\n */\nComponent.on({\n before(self) {\n const key = Object.getOwnPropertyDescriptor(self, 'key');\n\n if (key?.configurable)\n Object.defineProperty(self, 'key', {\n enumerable: false,\n writable: false\n });\n },\n type(type) {\n const desc = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (desc && typeof desc.value == 'function')\n Object.defineProperty(type.prototype, 'render', {\n ...desc,\n configurable: false\n });\n }\n});\n\n/**\n * Build (or fetch the cached) composed content render for an instance's class.\n * Walks the prototype chain for content renders strictly below Component - the\n * default render on Component.prototype is excluded and serves as the fallback\n * when a class authors none.\n */\nfunction render(target: Component) {\n const cached = CHAIN.get(target.constructor);\n\n if (cached) return cached;\n\n let render: Function | undefined;\n let proto = target;\n\n while ((proto = Object.getPrototypeOf(proto)) !== Component.prototype) {\n const desc = Object.getOwnPropertyDescriptor(proto, 'render');\n\n if (desc) {\n const layer = unbind(desc.get || desc.value);\n render = render ? compose(layer, render) : layer;\n }\n }\n\n if (!render)\n render = Component.prototype.render;\n\n CHAIN.set(target.constructor, render);\n\n return render;\n}\n\n/** Wrap an outer render so it receives `inner` as a lazy `children` getter. */\nfunction compose(outer: Function, inner: Function): Function {\n return function (this: Component, props?: {}) {\n const self = this;\n return outer.call(self, {\n ...props,\n get children() {\n return inner.call(self, props);\n }\n });\n };\n}\n\n/** Drop composed renders, so each is rebuilt from current protot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Context } from './context';\nimport { set } from './field/set';\nimport { Model, adopt, trailing } from './state';\n\nimport type { Host } from './jsx-runtime';\n\nconst PENDING = new WeakMap<object, Component<any>>();\n\ntype IfEquals<X, Y, A, B> =\n (<T>() => T extends X ? 1 : 2) extends\n (<T>() => T extends Y ? 1 : 2) ? A : B;\n\n/** Keys of T which are settable (excludes get-only accessors and `readonly`). */\ntype Acceptable<T> = {\n [P in keyof T]-?: IfEquals<\n { [Q in P]: T[P] },\n { -readonly [Q in P]: T[P] },\n P, never\n >;\n}[keyof T];\n\ntype ForProps<T extends Model> = {\n children?: Component.Node;\n fallback?: Component.Node | false;\n catch?: (error: Error, instance: Component) => Promise<void> | void;\n} & (\n | { for: Model.Extends<T>; is?: (instance: T) => void }\n | { for: T | undefined; is?: never }\n) & { [K in Exclude<keyof T, keyof Model> & Acceptable<T>]?: T[K] };\n\ndeclare namespace Component {\n /**\n * Host element type produced by `Component.render`. Delegates to the\n * {@link Host} manifest on the jsx-runtime entry; falls back to `any`\n * until an adapter augments it with `node`. `any` (not `unknown`) so an\n * un-annotated `render` override in a host-agnostic package still emits a\n * JSX-valid return - `any` is assignable to every host's node type, where\n * `unknown` is assignable to none.\n */\n type Node = Host extends { node: infer T } ? T : any;\n\n interface BaseProps<T extends Component<any>> {\n /**\n * Callback for newly created instance. Only called once.\n *\n * Runs after props apply but **before** the `new()` lifecycle hook - so it\n * may configure state that `new()` then observes. To react to a fully\n * initialized instance instead, use `watch` or an effect.\n */\n is?(instance: T): void;\n\n /**\n * Fallback to show when suspended or in error recovery.\n * Pass `false` to opt out of the component's own suspense boundary,\n * letting suspension bubble to an ancestor.\n */\n fallback?: Component.Node;\n\n /**\n * Called when this element's content throws, in place of the class's own\n * `catch`. A returned promise retries once settled.\n */\n catch?(error: Error, instance: T): Promise<void> | void;\n }\n\n type ModelProps<T extends Model> = {\n [K in Exclude<keyof T, keyof Component> & Acceptable<T>]?: T[K];\n };\n\n /** @deprecated Renamed to `ModelProps`. */\n type StateProps<T extends Model> = ModelProps<T>;\n\n type RenderProps<T> = [T] extends [(props: infer P) => any]\n ? [keyof NonNullable<P>] extends [never]\n ? { children?: Component.Node }\n : NonNullable<P>\n : { children?: Component.Node };\n\n type Props<T extends Component<any>> =\n & ModelProps<T>\n & BaseProps<T>\n & RenderProps<T['render']>;\n}\n\nclass Component<P = unknown> extends Model {\n /**\n * All JSX attributes passed to this component.\n * Includes state-derived props, render props, and built-in props like `is` and `fallback`.\n *\n * Will incorperate extra props you declare as props parameter in `render` method.\n */\n declare readonly props: [P] extends [Model] ? ForProps<P> : Component.Props<this>;\n\n /** Stable identity used when this instance is rendered in a collection. */\n declare readonly key: string;\n\n /**\n * Content to display while this component or its children are suspended.\n * Will cover suspense by pending properties in `this.render` as well.\n * Can be set as a class property or overridden via the `fallback` JSX prop.\n *\n * Defaults to null - nothing will be rendered.\n * Set `false` to opt out of having a boundary at all - suspension then\n * bubbles to the nearest ancestor boundary.\n */\n fallback: Component.Node = set(null);\n\n constructor(props?: any, ...rest: any[]) {\n if (props == null) props = {};\n\n const seen = {} as Record<string, undefined>;\n const twin = PENDING.get(props);\n const provider = new.target === Component && 'for' in props;\n\n if (typeof props == 'object') merge(props);\n\n function merge(props: {}) {\n for (const k in props) seen[k] = undefined;\n return { ...seen, ...props };\n }\n\n super([\n props,\n rest.filter((x) => !(x instanceof Context)),\n () => {\n const other = twin || PENDING.get(props)!;\n\n if (other !== this) {\n trailing(other).forEach((orphan) => orphan.set(null));\n other.set(null);\n }\n\n if (provider) provide(this);\n else props.is?.(this);\n\n Object.defineProperty(this, 'props', { enumerable: false });\n PENDING.delete(props);\n }\n ]);\n\n PENDING.set(props, this);\n\n this.props = props;\n this.set('props', () => {\n this.set(merge(this.props));\n });\n }\n\n /**\n * Output for this component. Override to define custom JSX.\n *\n * Properties accessed via `this` are reactive and trigger a render when they\n * change, in addition to props. Accepts an optional parameter to receive extra\n * props from JSX, beyond those merged to state properties; declare its shape\n * via `props = {} as { ... }`. Without a parameter (the default below),\n * children pass through.\n */\n render(props?: {}): Component.Node {\n const { children } = (props || this.props) as { children?: Component.Node };\n return children || null;\n }\n\n /**\n * Called when a child component throws during render.\n * While this is pending, `fallback` is displayed.\n * When resolved, the error boundary resets and `render` is called again.\n *\n * Override to handle errors - set `this.fallback` for error-specific UI,\n * await async recovery, or await user interaction before retrying. If you\n * assign a fallback within catch, it will be reverted after resolved.\n */\n catch?(error: Error, instance: this): Promise<void> | void;\n}\n\n/**\n * Default `key` accessor. The get/set pair keeps it off observed state.\n */\nObject.defineProperty(Component.prototype, 'key', {\n configurable: true,\n get() {\n return String(this);\n },\n set(value) {\n Object.defineProperty(this, 'key', { value });\n }\n});\n\nComponent.on({\n setup(self) {\n const key = Object.getOwnPropertyDescriptor(self, 'key');\n\n if (key?.configurable)\n Object.defineProperty(self, 'key', {\n enumerable: false,\n writable: false\n });\n }\n});\n\nfunction provide(self: Component<any>) {\n let input: unknown;\n let target: Model | undefined;\n let owned: { mount?(): unknown } | undefined;\n let mounted = false;\n let release: unknown;\n\n function unmount() {\n if (typeof release == 'function') release();\n release = undefined;\n }\n\n const inherited = (self as { mount?(): unknown }).mount;\n\n Object.defineProperty(self, 'mount', {\n configurable: true,\n value() {\n const done = inherited?.call(self);\n\n mounted = true;\n release = owned?.mount?.();\n\n return () => {\n mounted = false;\n unmount();\n if (typeof done == 'function') done();\n };\n }\n });\n\n function sync() {\n const { for: next, is, children, fallback, catch: _catch, ...rest } = self.props as Record<string, any>;\n\n if (fallback === undefined) self.fallback = false;\n\n if (next !== input) {\n input = next;\n unmount();\n\n if (Model.is(next)) {\n adopt(self, 'for', (target = new (next as Model.Type)(rest)));\n owned = target as typeof owned;\n is?.(target);\n if (mounted) release = owned!.mount?.();\n return;\n }\n\n owned = undefined;\n adopt(self, 'for', (target = next instanceof Model ? next : undefined));\n }\n\n target?.set(rest);\n }\n\n sync();\n self.set('props', sync);\n}\n\nexport { Component };\n"],"mappings":";;;;;AAMA,MAAM,0BAAU,IAAI,SAAiC;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M,EAE/C,aACP,QAAO,eAAe,MAAM,OAAO;EACjC,YAAY;EACZ,UAAU;EACX,CAAC;GAEP,CAAC;AAEF,SAAS,QAAQ,MAAsB;CACrC,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,UAAU;CACd,IAAI;CAEJ,SAAS,UAAU;AACjB,MAAI,OAAO,WAAW,WAAY,UAAS;AAC3C,YAAU;;CAGZ,MAAM,YAAa,KAA+B;AAElD,QAAO,eAAe,MAAM,SAAS;EACnC,cAAc;EACd,QAAQ;GACN,MAAM,OAAO,WAAW,KAAK,KAAK;AAElC,aAAU;AACV,aAAU,OAAO,SAAS;AAE1B,gBAAa;AACX,cAAU;AACV,aAAS;AACT,QAAI,OAAO,QAAQ,WAAY,OAAM;;;EAG1C,CAAC;CAEF,SAAS,OAAO;EACd,MAAM,EAAE,KAAK,MAAM,IAAI,UAAU,UAAU,OAAO,QAAQ,GAAG,SAAS,KAAK;AAE3E,MAAI,aAAa,OAAW,MAAK,WAAW;AAE5C,MAAI,SAAS,OAAO;AAClB,WAAQ;AACR,YAAS;AAET,OAAI,MAAM,GAAG,KAAK,EAAE;AAClB,UAAM,MAAM,OAAQ,SAAS,IAAK,KAAoB,KAAK,CAAE;AAC7D,YAAQ;AACR,SAAK,OAAO;AACZ,QAAI,QAAS,WAAU,MAAO,SAAS;AACvC;;AAGF,WAAQ;AACR,SAAM,MAAM,OAAQ,SAAS,gBAAgB,QAAQ,OAAO,OAAW;;AAGzE,UAAQ,IAAI,KAAK;;AAGnB,OAAM;AACN,MAAK,IAAI,SAAS,KAAK"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Model } from "./state.js";
|
|
2
2
|
|
|
3
3
|
//#region src/context.d.ts
|
|
4
|
-
type Accept<T extends
|
|
5
|
-
type Expect<T extends
|
|
4
|
+
type Accept<T extends Model = Model> = T | Model.Type<T> | Record<string | number, T | Model.Type<T>>;
|
|
5
|
+
type Expect<T extends Model = Model> = (state: T, downstream: boolean) => (() => void) | void;
|
|
6
6
|
declare namespace Context {
|
|
7
7
|
export { Accept, Expect };
|
|
8
8
|
}
|
|
9
9
|
declare class Context {
|
|
10
10
|
static get root(): Context;
|
|
11
|
-
/** Get the context for a
|
|
12
|
-
static get(state?:
|
|
11
|
+
/** Get the context for a Model. Adapters may override to provide framework context. */
|
|
12
|
+
static get(state?: Model): Context;
|
|
13
13
|
id: string;
|
|
14
14
|
parent?: Context;
|
|
15
15
|
scope: Set<Context>;
|
|
16
|
-
consume: Map<
|
|
17
|
-
provide: Map<
|
|
18
|
-
protected inputs: Record<string | number,
|
|
16
|
+
consume: Map<Model.Extends<Model>, Set<[Expect<Model>, boolean | undefined]> | null>;
|
|
17
|
+
provide: Map<Model.Extends<Model>, Set<[Model, boolean]> | null>;
|
|
18
|
+
protected inputs: Record<string | number, Model | Model.Extends>;
|
|
19
19
|
private cleanup;
|
|
20
20
|
constructor(arg?: Context | Accept);
|
|
21
21
|
private traverse;
|
|
22
22
|
private register;
|
|
23
23
|
/** Find specified type upstream. Throws if not found. */
|
|
24
|
-
get<T extends
|
|
24
|
+
get<T extends Model>(Type: Model.Extends<T>, required?: true): T;
|
|
25
25
|
/** Find specified type upstream. Returns undefined if not found. */
|
|
26
|
-
get<T extends
|
|
26
|
+
get<T extends Model>(Type: Model.Extends<T>, required?: boolean): T | undefined;
|
|
27
27
|
/** Subscribe to a type becoming available in context. */
|
|
28
|
-
get<T extends
|
|
29
|
-
/** Lookup excluding a specific instance (used by
|
|
30
|
-
get<T extends
|
|
28
|
+
get<T extends Model>(Type: Model.Extends<T>, callback: Expect<T>, downstream?: boolean): () => void;
|
|
29
|
+
/** Lookup excluding a specific instance (used by Model.prototype.get for upstream-of-self semantics). */
|
|
30
|
+
get<T extends Model>(Type: Model.Extends<T>, arg: boolean | Expect<T> | undefined, downstream: boolean | undefined, skip: Model): T | undefined | (() => void);
|
|
31
31
|
/**
|
|
32
|
-
* Register one or more
|
|
32
|
+
* Register one or more Models to this context.
|
|
33
33
|
*
|
|
34
|
-
* Context will add or remove
|
|
34
|
+
* Context will add or remove Models as needed to keep with provided input.
|
|
35
35
|
*
|
|
36
|
-
* @param inputs
|
|
37
|
-
* @param forEach Optional callback to run for each
|
|
38
|
-
* whether this context created the
|
|
36
|
+
* @param inputs Model, Model class, or map of Models / Model classes to register.
|
|
37
|
+
* @param forEach Optional callback to run for each Model registered. Receives
|
|
38
|
+
* whether this context created the Model - and so will destroy it - as
|
|
39
39
|
* opposed to it having been provided already active. May return a callback
|
|
40
40
|
* to run before that entry is dropped.
|
|
41
41
|
*/
|
|
42
|
-
set<T extends
|
|
43
|
-
add(I:
|
|
42
|
+
set<T extends Model>(inputs: Accept<T>, forEach?: (state: T, owned: boolean) => (() => void) | void): this;
|
|
43
|
+
add(I: Model, explicit?: boolean): () => void;
|
|
44
44
|
/**
|
|
45
|
-
* Create a child context, optionally registering one or more
|
|
45
|
+
* Create a child context, optionally registering one or more Models to it.
|
|
46
46
|
*
|
|
47
|
-
* @param inputs
|
|
47
|
+
* @param inputs Model, Model class, or map of Models / Model classes to register.
|
|
48
48
|
*/
|
|
49
49
|
push(inputs?: Accept): Context;
|
|
50
50
|
/**
|
|
51
|
-
* Remove all
|
|
51
|
+
* Remove all Models from this context.
|
|
52
52
|
*
|
|
53
|
-
* Will also run any cleanup callbacks registered when
|
|
53
|
+
* Will also run any cleanup callbacks registered when Models were added.
|
|
54
54
|
*/
|
|
55
55
|
pop(): void;
|
|
56
56
|
}
|
|
@@ -58,7 +58,9 @@ declare class Context {
|
|
|
58
58
|
* Add `value` to the context `state` was added to. A context-less `state` holds
|
|
59
59
|
* it instead - every context adding `state` later adds its held children too.
|
|
60
60
|
*/
|
|
61
|
-
declare function join(state:
|
|
61
|
+
declare function join(state: Model, value: Model): () => void;
|
|
62
|
+
/** The Model a host mounted `state` under - the one its nearest enclosing context was set up for. */
|
|
63
|
+
declare function host(state: Model): Model | undefined;
|
|
62
64
|
//#endregion
|
|
63
|
-
export { Context, join };
|
|
65
|
+
export { Context, host, join };
|
|
64
66
|
//# sourceMappingURL=context.d.ts.map
|