@expressive/react 0.70.0 → 0.71.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/adapter.d.ts CHANGED
@@ -81,7 +81,7 @@ declare module '@expressive/mvc' {
81
81
  * Callback for newly created instance. Only called once.
82
82
  * @returns Callback to run when instance is destroyed.
83
83
  */
84
- is?: (instance: T) => void | (() => void);
84
+ is?: (instance: T) => void;
85
85
  render?(props: HasProps<T>, self: T): React.ReactNode;
86
86
  /**
87
87
  * A fallback react tree to show when suspended.
@@ -1 +1 @@
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 | (() => 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;AAAA,gBAAAA;AAAA;AAAA;;;ACAA,IAAAC,cAAsB;;;ACAtB,iBAA+B;AAC/B,mBAAkG;AAElG,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA0DO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB,WAAAC;AACpB,cAAU,mBAAQ,IAAI,OAAO;AAE/B,QAAM,cAAU,4BAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,aAClB,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;;;AD5EA,kBAAM,KAAK,SAET,QACD;AACC,MAAG,S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CAAC;","names":["Pragma","import_mvc","Model","import_mvc","import_mvc","import_adapter","Pragma"]}
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;AAAA,gBAAAA;AAAA;AAAA;;;ACAA,IAAAC,cAAsB;;;ACAtB,iBAA+B;AAC/B,mBAAkG;AAElG,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA0DO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB,WAAAC;AACpB,cAAU,mBAAQ,IAAI,OAAO;AAE/B,QAAM,cAAU,4BAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,aAClB,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;;;AD5EA,kBAAM,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;AAA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AAkB,IAAI,cAAc;AAExD,QAAI;AACJ,QAAI;AAEJ,UAAM,cAAU,0BAAa,UAAU,aAAW;AAChD,UAAG,OAAO,aAAa,YAAW;AAChC,cAAM,OAAO,SAAS,KAAK,SAAS,SAAS,MAAM;AAEnD,YAAG,SAAS;AACV;AAEF,gBAAQ;AAAA,MACV;AAEE,gBAAQ;AAEV,UAAG;AACD,gBAAQ;AAAA,IACZ,GAAG,aAAa,IAAI;AAEpB,QAAG,iBAAiB,SAAQ;AAC1B,UAAI;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"]}
@@ -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';"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X,MAAAE,QAAO,aAAa,QAAQ;AAC5B,aAAO,UAAU,SAAY,OAAO;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,OAAO;AAChB;;;ACnFA,IAAMC,UAAS,CAAC;","names":["Model","createEffect","Model","Pragma","Pragma"]}
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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AC,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,MAAAE,QAAO,aAAa,QAAQ;AAC5B,aAAO,UAAU,SAAY,OAAO;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,OAAO;AAChB;;;ACnFA,IAAMC,UAAS,CAAC;","names":["Model","createEffect","Model","Pragma","Pragma"]}
@@ -7,7 +7,7 @@ function MC({ is, ...props }) {
7
7
  const model = this.use((self) => {
8
8
  self.set(props);
9
9
  if (is)
10
- return is(self);
10
+ is(self);
11
11
  });
12
12
  model.set(props);
13
13
  const render = METHOD.get(model.render) || props.render || model.render;
@@ -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 { 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 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,SAAG,IAAI;AAAA,EACX,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":[]}
package/dist/index.d.ts CHANGED
@@ -25,7 +25,7 @@ declare namespace Consumer {
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 Model__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
30
  interface Props<T extends Model__default> {
31
31
  /** Model or group of Models to provide to descendant Consumers. */
@@ -3,6 +3,6 @@ import * as React from 'react';
3
3
  export { Fragment } from 'react';
4
4
  export { JSX } from './jsx-runtime';
5
5
 
6
- declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements> | Model.Model.Init<Model.Model>, ...args: any[]) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
6
+ declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements> | Model.Model.Init<Model.Model>, ...args: any[]) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
7
7
 
8
8
  export { jsxDEV };
@@ -51,7 +51,7 @@ declare namespace JSX {
51
51
  }
52
52
  }
53
53
  declare function compat(this: (type: React__default.ElementType, ...args: any[]) => React__default.ReactElement, type: React__default.ElementType | Model.Init, ...args: any[]): React__default.ReactElement;
54
- declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
55
- declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
54
+ declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
55
+ declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
56
56
 
57
57
  export { JSX, compat, jsx, jsxs };
@@ -64,7 +64,7 @@ function MC({ is, ...props }) {
64
64
  const model = this.use((self) => {
65
65
  self.set(props);
66
66
  if (is)
67
- return is(self);
67
+ is(self);
68
68
  });
69
69
  model.set(props);
70
70
  const render = import_mvc2.METHOD.get(model.render) || props.render || model.render;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.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\";","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA8B;AAE9B,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAkG;AAElG,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA0DO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB,WAAAC;AACpB,cAAU,mBAAQ,IAAI,OAAO;AAE/B,QAAM,cAAU,4BAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,aAClB,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;;;ADQA,IAAAC,gBAAyB;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,mBAAO,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,oBACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","Model","import_react","Runtime"]}
1
+ {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.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 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\";","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA8B;AAE9B,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAkG;AAElG,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA0DO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB,WAAAC;AACpB,cAAU,mBAAQ,IAAI,OAAO;AAE/B,QAAM,cAAU,4BAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,aAClB,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;;;ADQA,IAAAC,gBAAyB;AA3CzB,SAAS,GAEP,EAAE,IAAI,GAAG,MAAM,GACf;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG;AACD,SAAG,IAAI;AAAA,EACX,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,mBAAO,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,oBACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","Model","import_react","Runtime"]}
package/package.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "preversion": "npm run test && npm run build"
50
50
  },
51
51
  "dependencies": {
52
- "@expressive/mvc": "^0.70.0"
52
+ "@expressive/mvc": "^0.71.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0 <20.0.0"
@@ -67,6 +67,6 @@
67
67
  "react": "^18.2.0",
68
68
  "tsup": "^8.0.2"
69
69
  },
70
- "version": "0.70.0",
71
- "gitHead": "5d70709fcf2bdb5b868dafb65a67bf5d8ea7be2d"
70
+ "version": "0.71.0",
71
+ "gitHead": "4d1f02e2c64ae6a993d6fa1384d385bd58a26e37"
72
72
  }