@expressive/react 0.70.0 → 0.72.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.
@@ -1,104 +1,95 @@
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
- };
1
+ import "./chunk-UIHA4AT6.js";
2
+ import "./chunk-4MR23TOU.js";
25
3
 
26
- // src/model.use.ts
27
- import { Model as Model2, Context, createEffect } from "@expressive/mvc";
4
+ // src/state.use.ts
5
+ import { State, Context, watch } from "@expressive/mvc";
28
6
  import { Pragma } from "./adapter";
29
- Model2.use = function(argument, repeat) {
30
- const context = Context.use(true);
31
- const render = Pragma.useFactory((refresh) => {
7
+ State.use = function(...args) {
8
+ const ambient = Context.use();
9
+ const state = Pragma.useState(() => {
32
10
  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();
11
+ let active;
12
+ const instance = this.new(
13
+ (x) => x.use ? Promise.resolve(x.use(...args)) : args
14
+ );
15
+ const context = ambient.push(instance);
16
+ watch(instance, (current) => {
17
+ active = current;
18
+ if (ready) state[1]((x) => x.bind(null));
40
19
  });
41
20
  function didMount() {
42
21
  ready = true;
43
22
  return () => {
44
- unwatch();
45
23
  context.pop();
46
24
  instance.set(null);
47
25
  };
48
26
  }
49
- return (props) => {
50
- Pragma.useLifecycle(didMount);
51
- if (ready && repeat && props) {
27
+ return (...args2) => {
28
+ Pragma.useEffect(didMount, []);
29
+ if (ready) {
52
30
  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
31
+ Promise.resolve(
32
+ instance.use ? instance.use(...args2) : Promise.all(
33
+ args2.flat().map(
34
+ (arg) => typeof arg == "object" && instance.set(arg)
35
+ )
36
+ )
37
+ ).finally(() => {
61
38
  ready = true;
39
+ });
62
40
  }
63
- return local;
41
+ return active;
64
42
  };
65
43
  });
66
- return render(argument);
44
+ return state[0](...args);
67
45
  };
68
46
 
69
- // src/model.get.ts
70
- import { createEffect as createEffect2, Model as Model3 } from "@expressive/mvc";
47
+ // src/state.get.ts
48
+ import { Context as Context2, watch as watch2, State as State2 } from "@expressive/mvc";
71
49
  import { Pragma as Pragma2 } from "./adapter";
72
- Model3.get = function(argument) {
73
- const context = Pragma2.useContext();
74
- const render = Pragma2.useFactory((refresh) => {
50
+ State2.get = function(argument) {
51
+ const context = Context2.use();
52
+ const state = Pragma2.useState(() => {
75
53
  const instance = context.get(this);
76
54
  if (!instance)
77
- if (argument === false)
78
- return () => void 0;
79
- else
80
- throw new Error(`Could not find ${this} in context.`);
55
+ if (argument === false) return () => void 0;
56
+ else throw new Error(`Could not find ${this} in context.`);
81
57
  let ready;
82
58
  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);
59
+ function render() {
60
+ state[1]((x) => x.bind(null));
61
+ }
62
+ function refresh(action) {
63
+ if (typeof action == "function") action = action();
64
+ render();
65
+ if (action) return action.finally(render);
66
+ }
67
+ function onMount() {
68
+ ready = true;
69
+ return unwatch;
70
+ }
71
+ const unwatch = watch2(
72
+ instance,
73
+ (current) => {
74
+ if (typeof argument === "function") {
75
+ const next = argument.call(current, current, refresh);
76
+ if (next === value) return;
77
+ value = next;
78
+ } else value = current;
79
+ if (ready) render();
80
+ },
81
+ argument === true
82
+ );
94
83
  if (value instanceof Promise) {
95
84
  let error;
96
85
  unwatch();
97
- value.then((x) => value = x, (e) => error = e).finally(refresh);
86
+ value.then(
87
+ (x) => value = x,
88
+ (e) => error = e
89
+ ).finally(render);
98
90
  value = null;
99
91
  return () => {
100
- if (error)
101
- throw error;
92
+ if (error) throw error;
102
93
  return value === void 0 ? null : value;
103
94
  };
104
95
  }
@@ -106,24 +97,12 @@ Model3.get = function(argument) {
106
97
  unwatch();
107
98
  return () => null;
108
99
  }
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
100
  return () => {
122
- Pragma2.useLifecycle(didMount);
101
+ Pragma2.useEffect(onMount, []);
123
102
  return value === void 0 ? null : value;
124
103
  };
125
104
  });
126
- return render();
105
+ return state[0]();
127
106
  };
128
107
 
129
108
  // src/adapter.ts
@@ -1 +1 @@
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 | (() => 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":"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","names":["Model","createEffect","Model","Pragma","Pragma"]}
1
+ {"version":3,"sources":["../../src/state.use.ts","../../src/state.get.ts","../../src/adapter.ts"],"sourcesContent":["import { State, Context, watch } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace State {\n interface Valid {\n use?(...props: any[]): Promise<void> | void;\n }\n\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n function use<T extends State>(this: New<T>, ...args: UseArgs<T>): T;\n }\n}\n\nState.use = function <T extends State.Valid>(\n this: State.New<T>,\n ...args: any[]\n) {\n const ambient = Context.use();\n const state = Pragma.useState(() => {\n let ready: boolean | undefined;\n let active: T;\n\n const instance = this.new((x) =>\n x.use ? Promise.resolve(x.use(...args)) : args\n );\n const context = ambient.push(instance);\n\n watch(instance, (current) => {\n active = current;\n\n if (ready) state[1]((x) => x.bind(null));\n });\n\n function didMount() {\n ready = true;\n return () => {\n context.pop();\n instance.set(null);\n };\n }\n\n return (...args: State.Args<T>) => {\n Pragma.useEffect(didMount, []);\n\n if (ready) {\n ready = false;\n\n Promise.resolve(\n instance.use\n ? instance.use(...args)\n : Promise.all(\n args\n .flat()\n .map(\n (arg) =>\n typeof arg == 'object' &&\n instance.set(arg as State.Assign<T>)\n )\n )\n ).finally(() => {\n ready = true;\n });\n }\n\n return active;\n };\n });\n\n return state[0](...args);\n};\n","import { Context, watch, State } 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 State {\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n // TODO: eagerly match this so any nulls are caught - would prevent updates.\n function get<T extends State>(\n this: Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.get = function <T extends State, R>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const context = Context.use();\n const state = Pragma.useState(() => {\n const instance = context.get(this);\n\n if (!instance)\n if (argument === false) return () => undefined;\n else throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n function render() {\n state[1]((x) => x.bind(null));\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n\n render();\n\n if (action) return action.finally(render);\n }\n\n function onMount() {\n ready = true;\n return unwatch;\n }\n\n const unwatch = watch(\n instance,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n\n if (next === value) return;\n\n value = next;\n } else value = current;\n\n if (ready) render();\n },\n argument === true\n );\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n unwatch();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(render);\n\n value = null;\n\n return () => {\n if (error) throw error;\n\n return value === undefined ? null : value;\n };\n }\n\n if (value === null) {\n unwatch();\n return () => null;\n }\n\n return () => {\n Pragma.useEffect(onMount, []);\n return value === undefined ? null : value;\n };\n });\n\n return state[0]() as R;\n};\n","namespace Pragma {}\n\nconst Pragma = {} as {\n useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => () => void, deps?: any[]): void;\n createElement(type: any, props?: any, ...children: any[]): any;\n};\n\nexport { Pragma };\n\nimport './state.as';\nimport './state.use';\nimport './state.get';\n"],"mappings":"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","names":["args","Context","watch","State","Pragma","Pragma"]}
@@ -0,0 +1,45 @@
1
+ // src/context.ts
2
+ import { Context } from "@expressive/mvc";
3
+ import {
4
+ createContext,
5
+ createElement,
6
+ Suspense,
7
+ useContext,
8
+ useEffect,
9
+ useMemo
10
+ } from "react";
11
+ var Layers = createContext(new Context());
12
+ Context.use = (create) => {
13
+ const ambient = useContext(Layers);
14
+ return create ? useMemo(() => ambient.push(), [ambient]) : ambient;
15
+ };
16
+ function Consumer(props) {
17
+ return props.for.get((i) => props.children(i));
18
+ }
19
+ function Provider(props) {
20
+ const context = Context.use(true);
21
+ useEffect(() => () => context.pop(), [context]);
22
+ context.use(props.for, (state) => {
23
+ if (props.forEach) {
24
+ const cleanup = props.forEach(state);
25
+ if (cleanup) state.set(cleanup, null);
26
+ }
27
+ });
28
+ return provide(context, props.children, props.fallback, props.name);
29
+ }
30
+ function provide(context, children, fallback, name) {
31
+ if (fallback !== void 0)
32
+ children = createElement(Suspense, { fallback, name }, children);
33
+ return createElement(Layers.Provider, {
34
+ key: context.id,
35
+ value: context,
36
+ children
37
+ });
38
+ }
39
+
40
+ export {
41
+ Consumer,
42
+ Provider,
43
+ provide
44
+ };
45
+ //# sourceMappingURL=chunk-4MR23TOU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context.ts"],"sourcesContent":["import State, { Context } from '@expressive/mvc';\nimport {\n createContext,\n createElement,\n ReactNode,\n Suspense,\n useContext,\n useEffect,\n useMemo\n} from 'react';\n\nexport const Layers = 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(Layers);\n\n return create ? useMemo(() => ambient.push(), [ambient]) : ambient;\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.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 State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends State> {\n /** State or group of States to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n /**\n * Callback to run for each provided State.\n */\n forEach?: Context.Expect<T>;\n\n /**\n * Children to render within this Provider.\n */\n children?: ReactNode;\n\n /** A fallback 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 State>(props: Provider.Props<T>) {\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.use(props.for, (state) => {\n if (props.forEach) {\n const cleanup = props.forEach(state);\n\n if (cleanup) state.set(cleanup, null);\n }\n });\n\n return provide(context, props.children, props.fallback, props.name);\n}\n\nfunction provide(\n context: Context,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined\n): ReactNode {\n if (fallback !== undefined)\n children = createElement(Suspense, { fallback, name }, children);\n\n return createElement(Layers.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, provide };\n"],"mappings":";AAAA,SAAgB,eAAe;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,SAAS,cAAc,IAAI,QAAQ,CAAC;AASjD,QAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,UAAU,WAAW,MAAM;AAEjC,SAAO,SAAS,QAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI;AAC7D;AAkBA,SAAS,SAA0B,OAA0B;AAC3D,SAAO,MAAM,IAAI,IAAI,CAAC,MAAM,MAAM,SAAS,CAAC,CAAC;AAC/C;AA4BA,SAAS,SAA0B,OAA0B;AAC3D,QAAM,UAAU,QAAQ,IAAI,IAAI;AAEhC,YAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,IAAI,MAAM,KAAK,CAAC,UAAU;AAChC,QAAI,MAAM,SAAS;AACjB,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAI,QAAS,OAAM,IAAI,SAAS,IAAI;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,QAAQ,SAAS,MAAM,UAAU,MAAM,UAAU,MAAM,IAAI;AACpE;AAEA,SAAS,QACP,SACA,UACA,UACA,MACW;AACX,MAAI,aAAa;AACf,eAAW,cAAc,UAAU,EAAE,UAAU,KAAK,GAAG,QAAQ;AAEjE,SAAO,cAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,58 @@
1
+ import {
2
+ provide
3
+ } from "./chunk-4MR23TOU.js";
4
+
5
+ // src/state.as.ts
6
+ import { Context, watch, METHOD, State } from "@expressive/mvc";
7
+ import { Pragma } from "./adapter";
8
+ State.as = function(render) {
9
+ const FC = Render.bind(this, { render });
10
+ return Object.assign(FC, {
11
+ displayName: this.name,
12
+ State: this
13
+ });
14
+ };
15
+ function Render(props, props2) {
16
+ const { is, ...rest } = { ...props, ...props2 };
17
+ const ambient = Context.use();
18
+ const state = Pragma.useState(() => {
19
+ const instance = this.new(rest, is && ((x) => void is(x)));
20
+ const context = ambient.push(instance);
21
+ let ready;
22
+ let active;
23
+ watch(instance, (current) => {
24
+ active = current;
25
+ if (ready) state[1]((x) => x.bind(null));
26
+ });
27
+ function didMount() {
28
+ ready = true;
29
+ return () => {
30
+ context.pop();
31
+ instance.set(null);
32
+ };
33
+ }
34
+ function Render2(props3) {
35
+ const render = METHOD.get(active.render) || props3.render || active.render;
36
+ return render ? render.call(active, props3, active) : props3.children;
37
+ }
38
+ return (props3) => {
39
+ ready = false;
40
+ Pragma.useEffect(didMount, []);
41
+ Promise.resolve(instance.set(props3)).finally(() => {
42
+ ready = true;
43
+ });
44
+ return provide(
45
+ context,
46
+ Pragma.createElement(Render2, props3),
47
+ props3.fallback || active.fallback,
48
+ String(instance)
49
+ );
50
+ };
51
+ });
52
+ return state[0](rest);
53
+ }
54
+
55
+ export {
56
+ Render
57
+ };
58
+ //# sourceMappingURL=chunk-UIHA4AT6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/state.as.ts"],"sourcesContent":["import { Context, watch, METHOD, State } from '@expressive/mvc';\nimport { FunctionComponent, ReactNode } from 'react';\n\nimport { provide } from './context';\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace State {\n type HasProps<T extends State> = {\n [K in Exclude<keyof T, keyof State>]?: T[K];\n };\n\n type ComponentProps<T extends State> = HasProps<T> & {\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 /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the State will be used.\n */\n fallback?: React.ReactNode;\n };\n\n type Props<T extends State> = T extends {\n render(props: infer P, self: any): any;\n }\n ? ComponentProps<T> & Omit<P, keyof AsComponent>\n : ComponentProps<T> & { children?: React.ReactNode };\n\n /**\n * Props which will not conflict with a State'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 State> = HasProps<T> & {\n is?: never;\n get?: never;\n set?: never;\n };\n\n /** State which is not incompatable as Component in React. */\n interface AsComponent extends State.Valid {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface FC<\n T extends State,\n P extends State.Assign<T>\n > extends FunctionComponent<P & State.Props<T>> {\n displayName?: string;\n State: State.Extends<T>;\n }\n\n function as<T extends State, P extends State.Assign<T>>(\n this: State.New<T>,\n render: (props: P, self: T) => ReactNode\n ): FC<T, P>;\n }\n}\n\nState.as = function <T extends State.AsComponent, P extends State.Assign<T>>(\n this: State.Class<T>,\n render: (props: P, self: T) => ReactNode\n): State.FC<T, P> {\n const FC = Render.bind(this as State.Class, { render } as {});\n\n return Object.assign(FC, {\n displayName: this.name,\n State: this\n });\n};\n\nexport function Render<T extends State.AsComponent>(\n this: State.Class<T>,\n props: State.Props<T>,\n props2?: State.Props<T>\n) {\n const { is, ...rest } = { ...props, ...props2 };\n\n const ambient = Context.use();\n const state = Pragma.useState<(props: any) => any>(() => {\n const instance = this.new(rest as {}, is && ((x) => void is(x)));\n const context = ambient.push(instance);\n\n let ready: boolean | undefined;\n let active: T;\n\n watch(instance, (current) => {\n active = current;\n\n if (ready) state[1]((x) => x.bind(null));\n });\n\n function didMount() {\n ready = true;\n return () => {\n context.pop();\n instance.set(null);\n };\n }\n\n function Render(props: State.Props<T>) {\n const render = METHOD.get(active.render) || props.render || active.render;\n\n return render\n ? render.call(active, props as State.HasProps<T>, active)\n : props.children;\n }\n\n return (props: State.RenderProps<T>) => {\n ready = false;\n\n Pragma.useEffect(didMount, []);\n Promise.resolve(instance.set(props as {})).finally(() => {\n ready = true;\n });\n\n return provide(\n context,\n Pragma.createElement(Render, props as any),\n props.fallback || active.fallback,\n String(instance)\n );\n };\n });\n\n return state[0](rest);\n}\n"],"mappings":";;;;;AAAA,SAAS,SAAS,OAAO,QAAQ,aAAa;AAI9C,SAAS,cAAc;AA4DvB,MAAM,KAAK,SAET,QACgB;AAChB,QAAM,KAAK,OAAO,KAAK,MAAqB,EAAE,OAAO,CAAO;AAE5D,SAAO,OAAO,OAAO,IAAI;AAAA,IACvB,aAAa,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,OAEd,OACA,QACA;AACA,QAAM,EAAE,IAAI,GAAG,KAAK,IAAI,EAAE,GAAG,OAAO,GAAG,OAAO;AAE9C,QAAM,UAAU,QAAQ,IAAI;AAC5B,QAAM,QAAQ,OAAO,SAA8B,MAAM;AACvD,UAAM,WAAW,KAAK,IAAI,MAAY,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC,EAAE;AAC/D,UAAM,UAAU,QAAQ,KAAK,QAAQ;AAErC,QAAI;AACJ,QAAI;AAEJ,UAAM,UAAU,CAAC,YAAY;AAC3B,eAAS;AAET,UAAI,MAAO,OAAM,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAAA,IACzC,CAAC;AAED,aAAS,WAAW;AAClB,cAAQ;AACR,aAAO,MAAM;AACX,gBAAQ,IAAI;AACZ,iBAAS,IAAI,IAAI;AAAA,MACnB;AAAA,IACF;AAEA,aAASA,QAAOC,QAAuB;AACrC,YAAM,SAAS,OAAO,IAAI,OAAO,MAAM,KAAKA,OAAM,UAAU,OAAO;AAEnE,aAAO,SACH,OAAO,KAAK,QAAQA,QAA4B,MAAM,IACtDA,OAAM;AAAA,IACZ;AAEA,WAAO,CAACA,WAAgC;AACtC,cAAQ;AAER,aAAO,UAAU,UAAU,CAAC,CAAC;AAC7B,cAAQ,QAAQ,SAAS,IAAIA,MAAW,CAAC,EAAE,QAAQ,MAAM;AACvD,gBAAQ;AAAA,MACV,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA,OAAO,cAAcD,SAAQC,MAAY;AAAA,QACzCA,OAAM,YAAY,OAAO;AAAA,QACzB,OAAO,QAAQ;AAAA,MACjB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,MAAM,CAAC,EAAE,IAAI;AACtB;","names":["Render","props"]}
package/dist/esm/index.js CHANGED
@@ -1,38 +1,36 @@
1
+ import {
2
+ Consumer,
3
+ Provider
4
+ } from "./chunk-4MR23TOU.js";
5
+
1
6
  // src/index.ts
2
- import { useEffect, useState } from "react";
3
- import { Pragma } from "./adapter";
4
- import { Context } from "./context";
5
7
  import {
8
+ Context,
6
9
  Observable,
7
- Model,
8
- Model as Model2,
10
+ State,
9
11
  get,
10
12
  use,
11
13
  ref,
12
- set,
13
- has
14
+ set
14
15
  } from "@expressive/mvc";
15
- import { Consumer, Context as Context2, Provider } from "./context";
16
- import { Fragment, createElement } from "react";
17
- Pragma.useContext = () => Context.use();
18
- Pragma.useLifecycle = (callback) => useEffect(() => callback(), []);
19
- Pragma.useFactory = (factory) => {
20
- const state = useState(() => factory(() => {
21
- state[1]((x) => x.bind(null));
22
- }));
23
- return state[0];
24
- };
16
+ import { createElement, useEffect, useState } from "react";
17
+ import { Pragma } from "./adapter";
18
+ import { Fragment, createElement as createElement2 } from "react";
19
+ Pragma.useEffect = useEffect;
20
+ Pragma.useState = useState;
21
+ Pragma.createElement = createElement;
22
+ var src_default = State;
25
23
  export {
26
24
  Consumer,
27
- Context2 as Context,
25
+ Context,
28
26
  Fragment,
29
- Model,
30
27
  Observable,
28
+ Pragma,
31
29
  Provider,
32
- createElement,
33
- Model2 as default,
30
+ State,
31
+ createElement2 as createElement,
32
+ src_default as default,
34
33
  get,
35
- has,
36
34
  ref,
37
35
  set,
38
36
  use
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => Context.use();\n\nPragma.useLifecycle = (callback) => useEffect(() => callback(), []);\n\nPragma.useFactory = (factory) => {\n const state = useState(() => factory(() => {\n state[1](x => x.bind(null) as any);\n }));\n\n return state[0];\n}\n\nexport {\n Observable,\n Model, Model as default,\n get, use, ref, set, has\n} from '@expressive/mvc';\n\nexport { Consumer, Context, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { type Pragma };\n"],"mappings":";AAAA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,cAAc;AACvB,SAAS,eAAe;AAcxB;AAAA,EACE;AAAA,EACA;AAAA,EAAgB,SAATA;AAAA,EACP;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,OACf;AAEP,SAAS,UAAU,WAAAC,UAAS,gBAAgB;AAC5C,SAAS,UAAU,qBAAqB;AAnBxC,OAAO,aAAa,MAAM,QAAQ,IAAI;AAEtC,OAAO,eAAe,CAAC,aAAa,UAAU,MAAM,SAAS,GAAG,CAAC,CAAC;AAElE,OAAO,aAAa,CAAC,YAAY;AAC/B,QAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM;AACzC,UAAM,CAAC,EAAE,OAAK,EAAE,KAAK,IAAI,CAAQ;AAAA,EACnC,CAAC,CAAC;AAEF,SAAO,MAAM,CAAC;AAChB;","names":["Model","Context"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {\n Context,\n Observable,\n State,\n get,\n use,\n ref,\n set\n} from '@expressive/mvc';\nimport { createElement, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\n\nPragma.useEffect = useEffect;\nPragma.useState = useState;\nPragma.createElement = createElement;\n\nexport default State;\nexport { Context, get, State, Observable, ref, set, use };\nexport { Consumer, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { Pragma };\n"],"mappings":";;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,WAAW,gBAAgB;AAEnD,SAAS,cAAc;AASvB,SAAS,UAAU,iBAAAA,sBAAqB;AAPxC,OAAO,YAAY;AACnB,OAAO,WAAW;AAClB,OAAO,gBAAgB;AAEvB,IAAO,cAAQ;","names":["createElement"]}
@@ -1,8 +1,8 @@
1
1
  // src/jsx-dev-runtime.ts
2
2
  import Runtime from "react/jsx-dev-runtime";
3
- import { compat } from "./jsx-runtime";
3
+ import { patch } from "./jsx-runtime";
4
4
  import { Fragment } from "react";
5
- var jsxDEV = compat.bind(Runtime.jsxDEV);
5
+ var jsxDEV = patch.bind(Runtime.jsxDEV);
6
6
  export {
7
7
  Fragment,
8
8
  jsxDEV
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport { compat } from './jsx-runtime';\n\nexport const jsxDEV = compat.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from \"react\";\n"],"mappings":";AAAA,OAAO,aAAa;AAEpB,SAAS,cAAc;AAKvB,SAAS,gBAAgB;AAHlB,IAAM,SAAS,OAAO,KAAK,QAAQ,MAAM;","names":[]}
1
+ {"version":3,"sources":["../../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport { patch } from './jsx-runtime';\n\nexport const jsxDEV = patch.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from 'react';\n"],"mappings":";AAAA,OAAO,aAAa;AAEpB,SAAS,aAAa;AAKtB,SAAS,gBAAgB;AAHlB,IAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;","names":[]}
@@ -1,35 +1,25 @@
1
+ import {
2
+ Render
3
+ } from "./chunk-UIHA4AT6.js";
4
+ import "./chunk-4MR23TOU.js";
5
+
1
6
  // src/jsx-runtime.ts
2
- import { METHOD, Model } from "@expressive/mvc";
7
+ import { State } from "@expressive/mvc";
3
8
  import Runtime from "react/jsx-runtime";
4
- import { createProvider } from "./context";
5
9
  import { Fragment } from "react";
6
- function MC({ is, ...props }) {
7
- const model = this.use((self) => {
8
- self.set(props);
9
- if (is)
10
- return is(self);
11
- });
12
- model.set(props);
13
- const render = METHOD.get(model.render) || props.render || model.render;
14
- const children = render ? render.call(model, props, model) : props.children;
15
- return createProvider(model, children, props.fallback || model.fallback, String(model));
16
- }
17
10
  var RENDER = /* @__PURE__ */ new WeakMap();
18
- function compat(type, ...args) {
19
- if (typeof type == "function") {
20
- if (RENDER.has(type))
21
- type = RENDER.get(type);
22
- else if (typeof type == "function")
23
- RENDER.set(type, type = type.prototype instanceof Model ? MC.bind(type) : type);
24
- }
11
+ function patch(type, ...args) {
12
+ if (State.is(type))
13
+ if (RENDER.has(type)) type = RENDER.get(type);
14
+ else RENDER.set(type, type = Render.bind(type));
25
15
  return this(type, ...args);
26
16
  }
27
- var jsx = compat.bind(Runtime.jsx);
28
- var jsxs = compat.bind(Runtime.jsxs);
17
+ var jsx = patch.bind(Runtime.jsx);
18
+ var jsxs = patch.bind(Runtime.jsxs);
29
19
  export {
30
20
  Fragment,
31
- compat,
32
21
  jsx,
33
- jsxs
22
+ jsxs,
23
+ patch
34
24
  };
35
25
  //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { METHOD, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<Props<T> & P>;\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n { is, ...props }: Model.Props<T>\n) {\n const model = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(is)\n return is(self);\n });\n\n model.set(props as Model.Assign<T>);\n\n const render = METHOD.get(model.render) || props.render || model.render;\n const children = render\n ? render.call(model, props as Model.HasProps<T>, model)\n : props.children;\n\n return createProvider(model, children, props.fallback || model.fallback, String(model));\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";"],"mappings":";AAAA,SAAS,QAAQ,aAAa;AAE9B,OAAO,aAAa;AAEpB,SAAS,sBAAsB;AAkG/B,SAAS,gBAAgB;AA3CzB,SAAS,GAEP,EAAE,IAAI,GAAG,MAAM,GACf;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG;AACD,aAAO,GAAG,IAAI;AAAA,EAClB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,OAAO,IAAI,MAAM,MAAM,KAAK,MAAM,UAAU,MAAM;AACjE,QAAM,WAAW,SACb,OAAO,KAAK,OAAO,OAA4B,KAAK,IACpD,MAAM;AAEV,SAAO,eAAe,OAAO,UAAU,MAAM,YAAY,MAAM,UAAU,OAAO,KAAK,CAAC;AACxF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,QACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,QAAQ,IAAI;","names":[]}
1
+ {"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { State } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Render } from './state.as';\n\nexport declare namespace JSX {\n type ElementType =\n | State.Extends<State.AsComponent>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U }\n ? U\n : C extends State.Extends<infer U>\n ? State.Props<U>\n : React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n\n // This is a hack to make TypeScript happy - React's interface insists on `props` property existing.\n // I await the \"Find Out\" phase of this in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute\n extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX\n .IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function patch(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | State.Class,\n ...args: any[]\n): React.ReactElement {\n if (State.is(type))\n if (RENDER.has(type)) type = RENDER.get(type)!;\n else RENDER.set(type, (type = Render.bind(type)));\n\n return this(type, ...args);\n}\n\nexport const jsx = patch.bind(Runtime.jsx);\nexport const jsxs = patch.bind(Runtime.jsxs);\n\nexport { Fragment } from 'react';\n"],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,OAAO,aAAa;AAkDpB,SAAS,gBAAgB;AAjBzB,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,MAEd,SACG,MACiB;AACpB,MAAI,MAAM,GAAG,IAAI;AACf,QAAI,OAAO,IAAI,IAAI,EAAG,QAAO,OAAO,IAAI,IAAI;AAAA,QACvC,QAAO,IAAI,MAAO,OAAO,OAAO,KAAK,IAAI,CAAE;AAElD,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,MAAM,KAAK,QAAQ,GAAG;AAClC,IAAM,OAAO,MAAM,KAAK,QAAQ,IAAI;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import State__default, { Context, State } from '@expressive/mvc';
2
+ export { Context, Observable, State, State as default, get, ref, set, use } from '@expressive/mvc';
1
3
  export { Pragma } from './adapter';
2
- import Model__default, { Context } from '@expressive/mvc';
3
- export { Context, Model, Observable, Model as default, get, has, ref, set, use } from '@expressive/mvc';
4
4
  import * as React from 'react';
5
5
  import { ReactNode } from 'react';
6
6
  export { Fragment, createElement } from 'react';
@@ -12,27 +12,33 @@ declare module '@expressive/mvc' {
12
12
  }
13
13
  }
14
14
  declare namespace Consumer {
15
- type Props<T extends Model__default> = {
15
+ type Props<T extends State__default> = {
16
16
  /** Type of controller to fetch from context. */
17
- for: Model__default.Type<T>;
17
+ for: State__default.Extends<T>;
18
18
  /**
19
19
  * Render function, will receive instance of desired controller.
20
20
  *
21
21
  * Called every render of parent component.
22
- * Similar to `Model.get()`, updates to properties accessed in
22
+ * Similar to `State.get()`, updates to properties accessed in
23
23
  * this function will cause a refresh when they change.
24
24
  */
25
25
  children: (value: T) => ReactNode | void;
26
26
  };
27
27
  }
28
- declare function Consumer<T extends Model__default>(props: Consumer.Props<T>): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal | null;
28
+ declare function Consumer<T extends State__default>(props: Consumer.Props<T>): string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal | null;
29
29
  declare namespace Provider {
30
- interface Props<T extends Model__default> {
31
- /** Model or group of Models to provide to descendant Consumers. */
30
+ interface Props<T extends State__default> {
31
+ /** State or group of States to provide to descendant Consumers. */
32
32
  for: Context.Accept<T>;
33
+ /**
34
+ * Callback to run for each provided State.
35
+ */
33
36
  forEach?: Context.Expect<T>;
37
+ /**
38
+ * Children to render within this Provider.
39
+ */
34
40
  children?: ReactNode;
35
- /** A fallback react tree to show when suspended. */
41
+ /** A fallback tree to show when suspended. */
36
42
  fallback?: ReactNode;
37
43
  /**
38
44
  * A name for this Suspense boundary for instrumentation purposes.
@@ -41,6 +47,6 @@ declare namespace Provider {
41
47
  name?: string | undefined;
42
48
  }
43
49
  }
44
- declare function Provider<T extends Model__default>(props: Provider.Props<T>): React.FunctionComponentElement<React.ProviderProps<Context>> | React.FunctionComponentElement<React.SuspenseProps>;
50
+ declare function Provider<T extends State__default>(props: Provider.Props<T>): ReactNode;
45
51
 
46
52
  export { Consumer, Provider };