@expressive/react 0.71.0 → 0.73.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/dist/chunk-kSYXY2_d.js +34 -0
- package/dist/context-DpbK9_2_.js +62 -0
- package/dist/context-DpbK9_2_.js.map +1 -0
- package/dist/esm/component.js +67 -0
- package/dist/esm/component.js.map +1 -0
- package/dist/esm/context.js +30 -32
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/index.js +16 -39
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx-dev-runtime.js +8 -8
- package/dist/esm/jsx-dev-runtime.js.map +1 -1
- package/dist/esm/jsx-runtime.js +15 -32
- package/dist/esm/jsx-runtime.js.map +1 -1
- package/dist/esm/state.js +145 -0
- package/dist/esm/state.js.map +1 -0
- package/dist/index-zVvhW0uD.d.ts +130 -0
- package/dist/index.d.ts +2 -46
- package/dist/index.js +125 -105
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +9 -7
- package/dist/jsx-dev-runtime.js +15 -43
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +21 -54
- package/dist/jsx-runtime.js +23 -87
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/state.d.ts +88 -0
- package/dist/state.js +148 -0
- package/dist/state.js.map +1 -0
- package/package.json +15 -12
- package/dist/adapter.d.ts +0 -105
- package/dist/adapter.js +0 -191
- package/dist/adapter.js.map +0 -1
- package/dist/esm/adapter.js +0 -134
- package/dist/esm/adapter.js.map +0 -1
package/dist/adapter.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/adapter.ts
|
|
31
|
-
var adapter_exports = {};
|
|
32
|
-
__export(adapter_exports, {
|
|
33
|
-
Pragma: () => Pragma3
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(adapter_exports);
|
|
36
|
-
|
|
37
|
-
// src/model.as.ts
|
|
38
|
-
var import_mvc2 = require("@expressive/mvc");
|
|
39
|
-
|
|
40
|
-
// src/context.ts
|
|
41
|
-
var import_mvc = __toESM(require("@expressive/mvc"));
|
|
42
|
-
var import_react = require("react");
|
|
43
|
-
var Lookup = (0, import_react.createContext)(new import_mvc.Context());
|
|
44
|
-
import_mvc.Context.use = (create) => {
|
|
45
|
-
const ambient = (0, import_react.useContext)(Lookup);
|
|
46
|
-
return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
|
|
47
|
-
};
|
|
48
|
-
function createProvider(context, children, fallback, name) {
|
|
49
|
-
if (context instanceof import_mvc.default)
|
|
50
|
-
context = import_mvc.Context.get(context);
|
|
51
|
-
const element = (0, import_react.createElement)(Lookup.Provider, {
|
|
52
|
-
key: context.id,
|
|
53
|
-
value: context,
|
|
54
|
-
children
|
|
55
|
-
});
|
|
56
|
-
return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/model.as.ts
|
|
60
|
-
import_mvc2.Model.as = function(render) {
|
|
61
|
-
if (this === import_mvc2.Model)
|
|
62
|
-
throw new Error("Cannot create component from base Model.");
|
|
63
|
-
const Component = (props) => {
|
|
64
|
-
const local = this.use((self) => {
|
|
65
|
-
self.set(props);
|
|
66
|
-
if (props.is)
|
|
67
|
-
return props.is(self);
|
|
68
|
-
});
|
|
69
|
-
local.set(props);
|
|
70
|
-
return createProvider(
|
|
71
|
-
local,
|
|
72
|
-
render(props, local),
|
|
73
|
-
props.fallback || local.fallback,
|
|
74
|
-
String(local)
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
Component.Model = this;
|
|
78
|
-
Component.displayName = this.name;
|
|
79
|
-
return Component;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/model.use.ts
|
|
83
|
-
var import_mvc3 = require("@expressive/mvc");
|
|
84
|
-
var import_adapter = require("./adapter");
|
|
85
|
-
import_mvc3.Model.use = function(argument, repeat) {
|
|
86
|
-
const context = import_mvc3.Context.use(true);
|
|
87
|
-
const render = import_adapter.Pragma.useFactory((refresh) => {
|
|
88
|
-
let ready;
|
|
89
|
-
let local;
|
|
90
|
-
const instance = new this(argument);
|
|
91
|
-
context.include(instance);
|
|
92
|
-
const unwatch = (0, import_mvc3.createEffect)(instance, (current) => {
|
|
93
|
-
local = current;
|
|
94
|
-
if (ready)
|
|
95
|
-
refresh();
|
|
96
|
-
});
|
|
97
|
-
function didMount() {
|
|
98
|
-
ready = true;
|
|
99
|
-
return () => {
|
|
100
|
-
unwatch();
|
|
101
|
-
context.pop();
|
|
102
|
-
instance.set(null);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return (props) => {
|
|
106
|
-
import_adapter.Pragma.useLifecycle(didMount);
|
|
107
|
-
if (ready && repeat && props) {
|
|
108
|
-
ready = false;
|
|
109
|
-
if (typeof props == "function") {
|
|
110
|
-
props.call(instance, instance);
|
|
111
|
-
props = void 0;
|
|
112
|
-
}
|
|
113
|
-
const update = instance.set(props);
|
|
114
|
-
if (update)
|
|
115
|
-
update.then(() => ready = true);
|
|
116
|
-
else
|
|
117
|
-
ready = true;
|
|
118
|
-
}
|
|
119
|
-
return local;
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
return render(argument);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// src/model.get.ts
|
|
126
|
-
var import_mvc4 = require("@expressive/mvc");
|
|
127
|
-
var import_adapter2 = require("./adapter");
|
|
128
|
-
import_mvc4.Model.get = function(argument) {
|
|
129
|
-
const context = import_adapter2.Pragma.useContext();
|
|
130
|
-
const render = import_adapter2.Pragma.useFactory((refresh) => {
|
|
131
|
-
const instance = context.get(this);
|
|
132
|
-
if (!instance)
|
|
133
|
-
if (argument === false)
|
|
134
|
-
return () => void 0;
|
|
135
|
-
else
|
|
136
|
-
throw new Error(`Could not find ${this} in context.`);
|
|
137
|
-
let ready;
|
|
138
|
-
let value;
|
|
139
|
-
const unwatch = (0, import_mvc4.createEffect)(instance, (current) => {
|
|
140
|
-
if (typeof argument === "function") {
|
|
141
|
-
const next = argument.call(current, current, update);
|
|
142
|
-
if (next === value)
|
|
143
|
-
return;
|
|
144
|
-
value = next;
|
|
145
|
-
} else
|
|
146
|
-
value = current;
|
|
147
|
-
if (ready)
|
|
148
|
-
refresh();
|
|
149
|
-
}, argument === true);
|
|
150
|
-
if (value instanceof Promise) {
|
|
151
|
-
let error;
|
|
152
|
-
unwatch();
|
|
153
|
-
value.then((x) => value = x, (e) => error = e).finally(refresh);
|
|
154
|
-
value = null;
|
|
155
|
-
return () => {
|
|
156
|
-
if (error)
|
|
157
|
-
throw error;
|
|
158
|
-
return value === void 0 ? null : value;
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
if (value === null) {
|
|
162
|
-
unwatch();
|
|
163
|
-
return () => null;
|
|
164
|
-
}
|
|
165
|
-
;
|
|
166
|
-
function update(action) {
|
|
167
|
-
if (typeof action == "function")
|
|
168
|
-
action = action();
|
|
169
|
-
refresh();
|
|
170
|
-
if (action)
|
|
171
|
-
return action.finally(refresh);
|
|
172
|
-
}
|
|
173
|
-
function didMount() {
|
|
174
|
-
ready = true;
|
|
175
|
-
return unwatch;
|
|
176
|
-
}
|
|
177
|
-
return () => {
|
|
178
|
-
import_adapter2.Pragma.useLifecycle(didMount);
|
|
179
|
-
return value === void 0 ? null : value;
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
return render();
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// src/adapter.ts
|
|
186
|
-
var Pragma3 = {};
|
|
187
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
-
0 && (module.exports = {
|
|
189
|
-
Pragma
|
|
190
|
-
});
|
|
191
|
-
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts","../src/model.as.ts","../src/context.ts","../src/model.use.ts","../src/model.get.ts"],"sourcesContent":["import { Context } from '@expressive/mvc';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type HasProps<T extends Model> = {\n [K in Exclude<keyof T, keyof Model>]?: T[K];\n }\n\n /**\n * Props which will not conflict with a Model's use as a Component.\n * \n * Built-in properties must be optional, as they will always be omitted.\n */\n type RenderProps<T extends Model> = HasProps<T> & {\n is?: undefined;\n get?: undefined;\n set?: undefined;\n };\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void;\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the Model will be used.\n */\n fallback?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & Omit<P, keyof Model>\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nconst Pragma = {} as {\n useContext(): Context;\n\n useFactory<T extends Function>(\n factory: (refresh: () => void) => T\n ): T;\n\n useLifecycle(callback: () => () => void): void;\n};\n\nexport { Pragma };\n\nimport \"./model.as\";\nimport './model.use';\nimport './model.get';","import { Model } from '@expressive/mvc';\nimport React, { FunctionComponent } from 'react';\n\nimport { createProvider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Model.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (props: P, self: T) => React.ReactNode\n ): Component<T, P>;\n }\n}\n\nModel.as = function <T extends Model.Compat, P extends Model.Assign<T>> (\n this: Model.Init<T>,\n render: (props: P, self: T) => React.ReactNode\n){\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component: Model.Component<T, P> = (props) => {\n const local = this.use((self) => {\n self.set(props);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props);\n\n return createProvider(\n local,\n render(props, local),\n props.fallback || local.fallback,\n String(local)\n );\n }\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, Suspense, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Lookup);\n\n return create ?\n useMemo(() => ambient.push(), []) :\n ambient;\n}\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n /** Model or group of Models to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n forEach?: Context.Expect<T>;\n children?: ReactNode;\n\n /** A fallback react tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.include(props.for, (model) => {\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(cleanup, null);\n }\n });\n \n return createProvider(context, props.children, props.fallback, props.name);\n}\n\nexport function createProvider(\n context: Context | Model,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined){\n\n if(context instanceof Model)\n context = Context.get(context)!;\n\n const element = createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n\n return fallback !== undefined ?\n createElement(Suspense, { fallback, name }, element) :\n element;\n}\n\nexport { Consumer, Provider, Context }\n","import { Model, Context, createEffect } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n function use <T extends Model> (\n this: Model.Init<T>,\n apply?: Model.Assign<T>,\n repeat?: boolean\n ): T;\n\n function use <T extends Model> (\n this: Model.Init<T>,\n callback?: Model.Callback<T>,\n repeat?: boolean\n ): T;\n }\n}\n\nModel.use = function <T extends Model> (\n this: Model.Init<T>,\n argument?: Model.Assign<T> | Model.Callback<T>,\n repeat?: boolean){\n\n const context = Context.use(true);\n const render = Pragma.useFactory((refresh) => {\n let ready: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = createEffect(instance, current => {\n local = current;\n\n if(ready) \n refresh();\n });\n\n function didMount(){\n ready = true;\n return () => {\n unwatch();\n context.pop()\n instance.set(null);\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n\n if(ready && repeat && props){\n ready = false;\n\n if(typeof props == \"function\"){\n props.call(instance, instance);\n props = undefined\n }\n\n const update = instance.set(props);\n\n if(update)\n update.then(() => ready = true);\n else\n ready = true;\n }\n\n return local; \n };\n });\n\n return render(argument);\n}","import { createEffect, Model } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ntype ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n \n /**\n * Request a refresh and again after promise either resolves or rejects.\n * \n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n * \n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n * \n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n};\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type GetFactory<T extends Model, R> =\n (this: T, current: T, refresh: ForceRefresh) => R;\n\n type GetEffect<T extends Model> =\n (this: T, current: T, refresh: ForceRefresh) => null;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>): T;\n \n /** Fetch instance of this class optionally. */\n function get <T extends Model> (this: Model.Type<T>, required: false): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>, requireValues: true): Required<T>\n \n function get <T extends Model, R> (this: Model.Type<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;\n \n // TODO: eagerly metch this so any nulls are caught - would prevent updates.\n function get <T extends Model> (this: Model.Type<T>, factory: GetEffect<T>): null;\n }\n}\n\nModel.get = function <T extends Model, R> (\n this: Model.Type<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n){\n const context = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n const instance = context.get(this);\n\n if(!instance)\n if(argument === false)\n return () => undefined;\n else\n throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n const unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, update);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(ready)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n value.then(x => value = x, e => error = e).finally(refresh);\n value = null;\n\n return () => {\n if(error)\n throw error;\n\n return value === undefined ? null : value;\n }\n }\n\n if(value === null){\n unwatch();\n return () => null;\n };\n\n function update<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\n function didMount(){\n ready = true;\n return unwatch;\n }\n\n return () => {\n Pragma.useLifecycle(didMount);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA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AAI;AAEJ,cAAQ;AAER,YAAM,KAAK,OAAK,QAAQ,GAAG,OAAK,QAAQ,CAAC,EAAE,QAAQ,OAAO;AAC1D,cAAQ;AAER,aAAO,MAAM;AACX,YAAG;AACD,gBAAM;AAER,eAAO,UAAU,SAAY,OAAO;AAAA,MACtC;AAAA,IACF;AAEA,QAAG,UAAU,MAAK;AAChB,cAAQ;AACR,aAAO,MAAM;AAAA,IACf;AAAC;AAED,aAAS,OAAU,QAA+C;AAChE,UAAG,OAAO,UAAU;AAClB,iBAAS,OAAO;AAElB,cAAQ;AAER,UAAG;AACD,eAAO,OAAO,QAAQ,OAAO;AAAA,IACjC;AAEA,aAAS,WAAU;AACjB,cAAQ;AACR,aAAO;AAAA,IACT;AAEA,WAAO,MAAM;AACX,6BAAO,aAAa,QAAQ;AAC5B,aAAO,UAAU,SAAY,OAAO;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,OAAO;AAChB;;;AJnFA,IAAMC,UAAS,CAAC;","names":["Pragma","import_mvc","Model","import_mvc","import_mvc","import_adapter","Pragma"]}
|
package/dist/esm/adapter.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// src/model.as.ts
|
|
2
|
-
import { Model } from "@expressive/mvc";
|
|
3
|
-
import { createProvider } from "./context";
|
|
4
|
-
Model.as = function(render) {
|
|
5
|
-
if (this === Model)
|
|
6
|
-
throw new Error("Cannot create component from base Model.");
|
|
7
|
-
const Component = (props) => {
|
|
8
|
-
const local = this.use((self) => {
|
|
9
|
-
self.set(props);
|
|
10
|
-
if (props.is)
|
|
11
|
-
return props.is(self);
|
|
12
|
-
});
|
|
13
|
-
local.set(props);
|
|
14
|
-
return createProvider(
|
|
15
|
-
local,
|
|
16
|
-
render(props, local),
|
|
17
|
-
props.fallback || local.fallback,
|
|
18
|
-
String(local)
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
Component.Model = this;
|
|
22
|
-
Component.displayName = this.name;
|
|
23
|
-
return Component;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/model.use.ts
|
|
27
|
-
import { Model as Model2, Context, createEffect } from "@expressive/mvc";
|
|
28
|
-
import { Pragma } from "./adapter";
|
|
29
|
-
Model2.use = function(argument, repeat) {
|
|
30
|
-
const context = Context.use(true);
|
|
31
|
-
const render = Pragma.useFactory((refresh) => {
|
|
32
|
-
let ready;
|
|
33
|
-
let local;
|
|
34
|
-
const instance = new this(argument);
|
|
35
|
-
context.include(instance);
|
|
36
|
-
const unwatch = createEffect(instance, (current) => {
|
|
37
|
-
local = current;
|
|
38
|
-
if (ready)
|
|
39
|
-
refresh();
|
|
40
|
-
});
|
|
41
|
-
function didMount() {
|
|
42
|
-
ready = true;
|
|
43
|
-
return () => {
|
|
44
|
-
unwatch();
|
|
45
|
-
context.pop();
|
|
46
|
-
instance.set(null);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return (props) => {
|
|
50
|
-
Pragma.useLifecycle(didMount);
|
|
51
|
-
if (ready && repeat && props) {
|
|
52
|
-
ready = false;
|
|
53
|
-
if (typeof props == "function") {
|
|
54
|
-
props.call(instance, instance);
|
|
55
|
-
props = void 0;
|
|
56
|
-
}
|
|
57
|
-
const update = instance.set(props);
|
|
58
|
-
if (update)
|
|
59
|
-
update.then(() => ready = true);
|
|
60
|
-
else
|
|
61
|
-
ready = true;
|
|
62
|
-
}
|
|
63
|
-
return local;
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
return render(argument);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/model.get.ts
|
|
70
|
-
import { createEffect as createEffect2, Model as Model3 } from "@expressive/mvc";
|
|
71
|
-
import { Pragma as Pragma2 } from "./adapter";
|
|
72
|
-
Model3.get = function(argument) {
|
|
73
|
-
const context = Pragma2.useContext();
|
|
74
|
-
const render = Pragma2.useFactory((refresh) => {
|
|
75
|
-
const instance = context.get(this);
|
|
76
|
-
if (!instance)
|
|
77
|
-
if (argument === false)
|
|
78
|
-
return () => void 0;
|
|
79
|
-
else
|
|
80
|
-
throw new Error(`Could not find ${this} in context.`);
|
|
81
|
-
let ready;
|
|
82
|
-
let value;
|
|
83
|
-
const unwatch = createEffect2(instance, (current) => {
|
|
84
|
-
if (typeof argument === "function") {
|
|
85
|
-
const next = argument.call(current, current, update);
|
|
86
|
-
if (next === value)
|
|
87
|
-
return;
|
|
88
|
-
value = next;
|
|
89
|
-
} else
|
|
90
|
-
value = current;
|
|
91
|
-
if (ready)
|
|
92
|
-
refresh();
|
|
93
|
-
}, argument === true);
|
|
94
|
-
if (value instanceof Promise) {
|
|
95
|
-
let error;
|
|
96
|
-
unwatch();
|
|
97
|
-
value.then((x) => value = x, (e) => error = e).finally(refresh);
|
|
98
|
-
value = null;
|
|
99
|
-
return () => {
|
|
100
|
-
if (error)
|
|
101
|
-
throw error;
|
|
102
|
-
return value === void 0 ? null : value;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
if (value === null) {
|
|
106
|
-
unwatch();
|
|
107
|
-
return () => null;
|
|
108
|
-
}
|
|
109
|
-
;
|
|
110
|
-
function update(action) {
|
|
111
|
-
if (typeof action == "function")
|
|
112
|
-
action = action();
|
|
113
|
-
refresh();
|
|
114
|
-
if (action)
|
|
115
|
-
return action.finally(refresh);
|
|
116
|
-
}
|
|
117
|
-
function didMount() {
|
|
118
|
-
ready = true;
|
|
119
|
-
return unwatch;
|
|
120
|
-
}
|
|
121
|
-
return () => {
|
|
122
|
-
Pragma2.useLifecycle(didMount);
|
|
123
|
-
return value === void 0 ? null : value;
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
return render();
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/adapter.ts
|
|
130
|
-
var Pragma3 = {};
|
|
131
|
-
export {
|
|
132
|
-
Pragma3 as Pragma
|
|
133
|
-
};
|
|
134
|
-
//# sourceMappingURL=adapter.js.map
|
package/dist/esm/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model.as.ts","../../src/model.use.ts","../../src/model.get.ts","../../src/adapter.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React, { FunctionComponent } from 'react';\n\nimport { createProvider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Model.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (props: P, self: T) => React.ReactNode\n ): Component<T, P>;\n }\n}\n\nModel.as = function <T extends Model.Compat, P extends Model.Assign<T>> (\n this: Model.Init<T>,\n render: (props: P, self: T) => React.ReactNode\n){\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component: Model.Component<T, P> = (props) => {\n const local = this.use((self) => {\n self.set(props);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props);\n\n return createProvider(\n local,\n render(props, local),\n props.fallback || local.fallback,\n String(local)\n );\n }\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model, Context, createEffect } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n function use <T extends Model> (\n this: Model.Init<T>,\n apply?: Model.Assign<T>,\n repeat?: boolean\n ): T;\n\n function use <T extends Model> (\n this: Model.Init<T>,\n callback?: Model.Callback<T>,\n repeat?: boolean\n ): T;\n }\n}\n\nModel.use = function <T extends Model> (\n this: Model.Init<T>,\n argument?: Model.Assign<T> | Model.Callback<T>,\n repeat?: boolean){\n\n const context = Context.use(true);\n const render = Pragma.useFactory((refresh) => {\n let ready: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = createEffect(instance, current => {\n local = current;\n\n if(ready) \n refresh();\n });\n\n function didMount(){\n ready = true;\n return () => {\n unwatch();\n context.pop()\n instance.set(null);\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n\n if(ready && repeat && props){\n ready = false;\n\n if(typeof props == \"function\"){\n props.call(instance, instance);\n props = undefined\n }\n\n const update = instance.set(props);\n\n if(update)\n update.then(() => ready = true);\n else\n ready = true;\n }\n\n return local; \n };\n });\n\n return render(argument);\n}","import { createEffect, Model } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ntype ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n \n /**\n * Request a refresh and again after promise either resolves or rejects.\n * \n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n * \n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n * \n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n};\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type GetFactory<T extends Model, R> =\n (this: T, current: T, refresh: ForceRefresh) => R;\n\n type GetEffect<T extends Model> =\n (this: T, current: T, refresh: ForceRefresh) => null;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>): T;\n \n /** Fetch instance of this class optionally. */\n function get <T extends Model> (this: Model.Type<T>, required: false): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>, requireValues: true): Required<T>\n \n function get <T extends Model, R> (this: Model.Type<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;\n \n // TODO: eagerly metch this so any nulls are caught - would prevent updates.\n function get <T extends Model> (this: Model.Type<T>, factory: GetEffect<T>): null;\n }\n}\n\nModel.get = function <T extends Model, R> (\n this: Model.Type<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n){\n const context = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n const instance = context.get(this);\n\n if(!instance)\n if(argument === false)\n return () => undefined;\n else\n throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n const unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, update);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(ready)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n value.then(x => value = x, e => error = e).finally(refresh);\n value = null;\n\n return () => {\n if(error)\n throw error;\n\n return value === undefined ? null : value;\n }\n }\n\n if(value === null){\n unwatch();\n return () => null;\n };\n\n function update<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\n function didMount(){\n ready = true;\n return unwatch;\n }\n\n return () => {\n Pragma.useLifecycle(didMount);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}","import { Context } from '@expressive/mvc';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type HasProps<T extends Model> = {\n [K in Exclude<keyof T, keyof Model>]?: T[K];\n }\n\n /**\n * Props which will not conflict with a Model's use as a Component.\n * \n * Built-in properties must be optional, as they will always be omitted.\n */\n type RenderProps<T extends Model> = HasProps<T> & {\n is?: undefined;\n get?: undefined;\n set?: undefined;\n };\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void;\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the Model will be used.\n */\n fallback?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & Omit<P, keyof Model>\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nconst Pragma = {} as {\n useContext(): Context;\n\n useFactory<T extends Function>(\n factory: (refresh: () => void) => T\n ): T;\n\n useLifecycle(callback: () => () => void): void;\n};\n\nexport { Pragma };\n\nimport \"./model.as\";\nimport './model.use';\nimport './model.get';"],"mappings":";AAAA,SAAS,aAAa;AAGtB,SAAS,sBAAsB;AAe/B,MAAM,KAAK,SAET,QACD;AACC,MAAG,SAAS;AACV,UAAM,IAAI,MAAM,0CAA0C;AAE5D,QAAM,YAAmC,CAAC,UAAU;AAClD,UAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,WAAK,IAAI,KAAK;AAEd,UAAG,MAAM;AACP,eAAO,MAAM,GAAG,IAAI;AAAA,IACxB,CAAC;AAED,UAAM,IAAI,KAAK;AAEf,WAAO;AAAA,MACL;AAAA,MACA,OAAO,OAAO,KAAK;AAAA,MACnB,MAAM,YAAY,MAAM;AAAA,MACxB,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AAEA,YAAU,QAAQ;AAClB,YAAU,cAAc,KAAK;AAE7B,SAAO;AACT;;;AC/CA,SAAS,SAAAA,QAAO,SAAS,oBAAoB;AAE7C,SAAS,cAAc;AAkBvBA,OAAM,MAAM,SAEV,UACA,QAAiB;AAEjB,QAAM,UAAU,QAAQ,IAAI,IAAI;AAChC,QAAM,SAAS,OAAO,WAAW,CAAC,YAAY;AAC5C,QAAI;AACJ,QAAI;AAEJ,UAAM,WAAW,IAAI,KAAK,QAAQ;AAElC,YAAQ,QAAQ,QAAQ;AAExB,UAAM,UAAU,aAAa,UAAU,aAAW;AAChD,cAAQ;AAER,UAAG;AACD,gBAAQ;AAAA,IACZ,CAAC;AAED,aAAS,WAAU;AACjB,cAAQ;AACR,aAAO,MAAM;AACX,gBAAQ;AACR,gBAAQ,IAAI;AACZ,iBAAS,IAAI,IAAI;AAAA,MACnB;AAAA,IACF;AA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