esp-js-react 8.0.5-next.0 → 8.0.7-next.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/esp-react.js +62 -72
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +1 -1
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/index.d.ts +0 -1
- package/.dist/typings/polimer/getEspPolimerImmutableModel.d.ts +3 -15
- package/.dist/typings/useSyncModelWithSelector.d.ts +2 -0
- package/.yarnignore +0 -1
- package/package.json +5 -5
- package/src/connectableComponent.tsx +4 -2
- package/src/index.ts +0 -5
- package/src/polimer/getEspPolimerImmutableModel.ts +13 -38
- package/src/useSyncModelWithSelector.ts +51 -36
- package/tests/connectableComponentTests.tsx +37 -56
- package/tests/indexTests.ts +0 -2
- package/tests/testApi/testModel.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esp-react.min.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,UAAWA,QAAQ,kBAAmBA,QAAQ,UACtD,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,SAAU,iBAAkB,SAAUJ,GACpB,iBAAZC,QACdA,QAAQ,gBAAkBD,EAAQG,QAAQ,UAAWA,QAAQ,kBAAmBA,QAAQ,UAExFJ,EAAK,gBAAkBC,EAAQD,EAAK,UAAWA,EAAK,kBAAmBA,EAAY,MACpF,CATD,CASGO,MAAM,CAACC,EAAkCC,EAAiCC,4CCAhE,IAAIC,EAAE,EAAQ,KAAwE,IAAIC,EAAE,mBAAoBC,OAAOC,GAAGD,OAAOC,GAA1G,SAAWC,EAAEC,GAAG,OAAOD,IAAIC,IAAI,IAAID,GAAG,EAAEA,GAAI,EAAEC,IAAID,GAAIA,GAAGC,GAAIA,CAAC,EAAiDC,EAAEN,EAAEO,qBAAqBC,EAAER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AGpEtK,EAAOD,OACf,koBCFA,OAEA,aAAQ,4EAAAoJ,UAAU,IAClB,aAAQ,6EAAA7B,WAAW,IAAE,kFAAAP,gBAAgB,IACrC,aAEI,mGAAAf,iCAAiC,IACjC,qEAAA0E,IAAA,oBAAAC,2BAA2B,IAE/B,aAAQ,oFAAA3G,kBAAkB,IAC1B,aACI,yEAAA5B,OAAO,IAGX,aAKI,sFAAAQ,oBAAoB,IAExB,aACI,0FAAAU,wBAAwB,IAExB,8FAAAC,4BAA4B,IAIhC,aACI,gFAAAiC,cAAc,IAEd,0FAAAH,wBAAwB,IAExB,+EAAAH,aAAa,IACb,2EAAApC,SAAS,IAET,qFAAAqC,mBAAmB,IACnB,iFAAAC,eAAe,IAEnB,aACI,+EAAApC,aAAa,IACb,mFAAAkB,iBAAiB,IACjB,6EAAAI,WAAW,IACX,iFAAAD,eAAe,IAEf,0FAAAE,wBAAwB,IACxB,sFAAAC,oBAAoB,IAEpB,uGAAAC,qCAAqC,IACrC,mGAAAC,iCAAiC,IACjC,yFAAAT,uBAAuB","sources":["webpack://esp-js-react/webpack/universalModuleDefinition","webpack://esp-js-react/../../node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.min.js","webpack://esp-js-react/../../node_modules/use-sync-external-store/with-selector.js","webpack://esp-js-react/./src/connect.tsx","webpack://esp-js-react/./src/connectableComponent.tsx","webpack://esp-js-react/./src/espModelContextProvider.tsx","webpack://esp-js-react/./src/espRouterContextProvider.tsx","webpack://esp-js-react/./src/polimer/getEspPolimerImmutableModel.ts","webpack://esp-js-react/./src/polimer/polimerModelBuilderExtentsions.ts","webpack://esp-js-react/./src/useSyncModelWithSelector.ts","webpack://esp-js-react/./src/viewBinder.tsx","webpack://esp-js-react/./src/viewBindingDecorator.ts","webpack://esp-js-react/external umd \"esp-js\"","webpack://esp-js-react/external umd \"esp-js-polimer\"","webpack://esp-js-react/external umd \"react\"","webpack://esp-js-react/webpack/bootstrap","webpack://esp-js-react/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"esp-js\"), require(\"esp-js-polimer\"), require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"esp-js\", \"esp-js-polimer\", \"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"esp-js-react\"] = factory(require(\"esp-js\"), require(\"esp-js-polimer\"), require(\"react\"));\n\telse\n\t\troot[\"esp-js-react\"] = factory(root[\"esp-js\"], root[\"esp-js-polimer\"], root[\"react\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__152__, __WEBPACK_EXTERNAL_MODULE__43__, __WEBPACK_EXTERNAL_MODULE__155__) => {\nreturn ","/**\n * @license React\n * use-sync-external-store-with-selector.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var g=require(\"react\");function n(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var p=\"function\"===typeof Object.is?Object.is:n,q=g.useSyncExternalStore,r=g.useRef,t=g.useEffect,u=g.useMemo,v=g.useDebugValue;\nexports.useSyncExternalStoreWithSelector=function(a,b,e,l,h){var c=r(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f}else f=c.current;c=u(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==h&&f.hasValue){var b=f.value;if(h(b,a))return k=b}return k=a}b=k;if(p(d,a))return b;var e=l(a);if(void 0!==h&&h(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return[function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,h]);var d=q(a,c[0],c[1]);\nt(function(){f.hasValue=!0;f.value=d},[d]);v(d);return d};\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.min.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n","import * as React from 'react';\nimport {ConnectableComponent, ConnectableComponentProps, CreatePublishEventProps, MapModelToProps} from './connectableComponent';\n\nexport type ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps = {}> = (view: React.ComponentType) => (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) => React.JSX.Element;\n\n/**\n * @param mapModelToProps - maps the model to a different structure, that structure is sent as props to the view.\n * @param createPublishEventProps - creates functions to publish events, the structure is sent as props to the view.\n */\nexport const connect = function <TModel, TPublishEventProps, TModelMappedToProps = {}>(\n mapModelToProps?: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>\n): ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps> {\n return function (view: React.ComponentType) {\n return function (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) {\n const {modelId, viewContext, ...rest} = props;\n return <ConnectableComponent\n modelId={modelId}\n view={view}\n viewContext={viewContext}\n createPublishEventProps={createPublishEventProps}\n mapModelToProps={mapModelToProps}\n {...rest}\n />;\n };\n };\n};","import * as React from 'react';\nimport {useRouter} from './espRouterContextProvider';\nimport {useMemo} from 'react';\nimport {Router, utils} from 'esp-js';\nimport {EspModelContextProvider, useGetModelId} from './espModelContextProvider';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\nimport {syncModelWithSelectorOptions, useSyncModelWithSelector} from './useSyncModelWithSelector';\n\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\nexport type MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\nexport interface ConnectableComponentProps<TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}> {\n modelId?: string;\n viewContext?: string;\n view?: React.ComponentType;\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>;\n mapModelToProps?: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>;\n [key: string]: any; // ...rest props, including the result of mapPublish and mapPublish if 'connect' was used\n}\n\nexport interface ConnectableComponentChildProps<TModel = object> {\n modelId: string;\n model: TModel;\n router: Router;\n [key: string]: any; // ...rest props\n}\n\nconst getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(\n router: Router,\n modelId: string,\n restProps: object,\n initialModel: TModel,\n mapModelToProps: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n publishEventProps: TPublishEventProps\n): ConnectableComponentChildProps<TModel> => {\n const model = tryGetPolimerImmutableModel<TModel>(initialModel);\n let childProps = {\n modelId,\n router: router,\n ...restProps,\n ...publishEventProps,\n model\n };\n if (mapModelToProps) {\n childProps = {\n ...childProps,\n ...(mapModelToProps(model, publishEventProps) as TModelMappedToProps)\n };\n }\n return childProps;\n};\n\nexport const ConnectableComponent = <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>(\n {\n modelId,\n mapModelToProps,\n createPublishEventProps,\n view,\n viewContext,\n ...rest\n }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>\n) => {\n const router = useRouter();\n // Note: we always need to render the hooks else react will complain about a different count.\n let modelIdFromContext = useGetModelId();\n modelId = modelId || modelIdFromContext;\n const publishEventProps: TPublishEventProps = useMemo(\n () => {\n if (createPublishEventProps) {\n const publishModelEvent = (eventType: string, event: any) => {\n router.publishEvent(modelId, eventType, event);\n };\n return createPublishEventProps(publishModelEvent);\n }\n return {} as TPublishEventProps;\n },\n [router, modelId]\n );\n const model = useSyncModelWithSelector<TModel, TModel>(\n m => m,\n syncModelWithSelectorOptions()\n .setModelId(modelId)\n .setTryPreSelectPolimerImmutableModel(false)\n );\n if (model == null) {\n return null;\n }\n let childProps = getChildProps(router, modelId, rest, model, mapModelToProps, publishEventProps);\n let viewElement = createViewForModel(model, childProps, viewContext, view);\n return (\n <EspModelContextProvider modelId={modelId} model={model} router={router} {...childProps}>\n {viewElement}\n </EspModelContextProvider>\n );\n};","import * as React from 'react';\nimport {DefaultModelAddress} from 'esp-js';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useRouter} from './espRouterContextProvider';\n\nexport const GetModelIdContext = createContext<string>(null);\n/**\n * Returns a function to get the ID of the model connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const useGetModelId = () => useContext(GetModelIdContext);\n\nexport const GetModelContext = createContext<object>(null);\n/**\n * Returns a function which will return the model connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const useGetModel = <TModel,>() => useContext(GetModelContext) as TModel;\n\nexport type PublishModelEventDelegate = (eventType: string, event: any) => void;\nexport const PublishModelEventContext = createContext<PublishModelEventDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the model connected at a higher point in the V-DOM.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the relevant modelId.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const usePublishModelEvent = () => useContext(PublishModelEventContext);\n\nexport type PublishModelEventWithEntityKeyDelegate = (entityKey: string, eventType: string, event: any) => void;\nexport const PublishModelEventWithEntityKeyContext = createContext<PublishModelEventWithEntityKeyDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the model connected at a higher point in the V-DOM, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the modelId.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const usePublishModelEventWithEntityKey = () => useContext(PublishModelEventWithEntityKeyContext);\n\nexport interface EspModelContextProviderProps {\n modelId: string;\n model?: any;\n}\n\n/**\n * Sets up various ESP context so ESP hooks are available below this point in the V-DOM\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node.\n * @param modelId\n * @param children\n * @param model\n * @constructor\n */\nexport const EspModelContextProvider = ({modelId, children, model}: PropsWithChildren<EspModelContextProviderProps>) => {\n const router = useRouter();\n // modelId may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let modelIdFromContext = useGetModelId();\n modelId = modelId || modelIdFromContext;\n const publishModelEvent: PublishModelEventDelegate = useCallback((eventType: string, event: any) => {\n router.publishEvent(modelId, eventType, event);\n }, [router, modelId]);\n const publishModelEventWithEntityKey: PublishModelEventWithEntityKeyDelegate = useCallback((entityKey: string, eventType: string, event: any) => {\n router.publishEvent(new DefaultModelAddress(modelId, entityKey), eventType, event);\n }, [router, modelId]);\n return (\n <GetModelIdContext.Provider value={modelId}>\n <PublishModelEventContext.Provider value={publishModelEvent}>\n <PublishModelEventWithEntityKeyContext.Provider value={publishModelEventWithEntityKey}>\n <GetModelContext.Provider value={model}>\n {children}\n </GetModelContext.Provider>\n </PublishModelEventWithEntityKeyContext.Provider>\n </PublishModelEventContext.Provider>\n </GetModelIdContext.Provider>\n );\n};","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {ModelAddress, Router} from 'esp-js';\nimport {PropsWithChildren, createContext, useContext, useCallback} from 'react';\n\nexport const RouterContext = createContext<Router>(null);\n\n/**\n * Get the esp Router from context.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node:\n *\n * <EspRouterContextProvider router={router}>\n * <YourComponents />\n * </EspRouterContextProvider>\n */\nexport const useRouter = () => {\n return useContext(RouterContext);\n};\n\nexport type PublishEventDelegate = (modelIdOrModelAddress: string | ModelAddress, eventType: string, event: any) => void;\nexport const PublishEventContext = createContext<PublishEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node:\n *\n * <EspRouterContextProvider router={router}>\n * <YourComponents />\n * </EspRouterContextProvider>\n */\nexport const usePublishEvent = () => useContext(PublishEventContext);\n\nexport type EspRouterContextProviderProps = PropsWithChildren<{ router: Router; }>;\n\n/**\n * Used to set the router on the RouterContext making it available to components down the tree via the useRouter() hook.\n *\n * Also sets up the usePublishEvent() hook so nested components can publish to the router.\n */\nexport const EspRouterContextProvider = ({children, router}: EspRouterContextProviderProps) => {\n // Router may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let routerFromContext = useRouter();\n router = router || routerFromContext;\n const publishEvent: PublishEventDelegate = useCallback((modelIdOrModelAddress: string, eventType: string, event: any) => {\n router.publishEvent(modelIdOrModelAddress, eventType, event);\n }, [router]);\n return (\n <RouterContext.Provider value={router}>\n <PublishEventContext.Provider value={publishEvent}>\n {children}\n </PublishEventContext.Provider>\n </RouterContext.Provider>\n );\n};\n\n/**\n * Used to set the router on the RouterContext making it available to components down the tree (via useRouter()).\n *\n * @deprecated use EspRouterContextProvider\n */\nexport const RouterProvider = EspRouterContextProvider;\n\n/**\n * Props for RouterProvider\n *\n * @deprecated use EspRouterContextProviderProps\n */\nexport type RouterProviderProps = EspRouterContextProviderProps;\n","import {EspMetadata, EspDecoratorUtil, utils} from 'esp-js';\n\nexport interface GetEspPolimerImmutableModelMetadata {\n functionName: string;\n}\n\nexport namespace GetEspPolimerImmutableModelConsts {\n export const CustomDataKey = 'GetEspReactImmutableModelCustomDataKey';\n /**\n * If there is no @getEspPolimerImmutableModel decorator and a function by this name exists on a model, then it will be invoked to identify the sub model which will replaced the `model` prop passed to the child view of a ConnectableComponent\n */\n export const HandlerFunctionName = 'getEspPolimerImmutableModel';\n}\n\n/**\n * A decorator which can be used to identify the render model which will replaced the `model` prop passed to the child view of a ConnectableComponent\n */\nexport function getEspPolimerImmutableModel() {\n return function (target, name, descriptor) {\n let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);\n metadata.addCustomData(\n GetEspPolimerImmutableModelConsts.CustomDataKey,\n <GetEspPolimerImmutableModelMetadata>{ functionName: name }\n );\n return descriptor;\n };\n}\n\n/**\n * Returns the model which will be used to pluck state/props for the current view.\n *\n * This is basically a hook (not a React 'hook') to call a function on `model` and get a new subgraph to use as state.\n *\n */\nexport const tryGetPolimerImmutableModel = <TImmutableModel>(model: any): TImmutableModel => {\n // does the given model have a decorated function we can invoke to get a different model to render?\n if (EspDecoratorUtil.hasMetadata(model)) {\n let metadata: GetEspPolimerImmutableModelMetadata = EspDecoratorUtil.getCustomData(model, GetEspPolimerImmutableModelConsts.CustomDataKey);\n if (metadata) {\n return model[metadata.functionName]();\n }\n }\n // else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?\n let immutableModel = model[GetEspPolimerImmutableModelConsts.HandlerFunctionName];\n if (immutableModel && utils.isFunction(immutableModel)) {\n return immutableModel.call(model);\n }\n // else return the initial model passed in\n return model;\n};","import {PolimerModelBuilder, PolimerModel} from 'esp-js-polimer';\nimport {DEFAULT_VIEW_KEY, viewBinding} from '../viewBindingDecorator';\n\ndeclare module 'esp-js-polimer/.dist/typings/modelBuilderUpdater' {\n export interface PolimerModelBuilder<TModel> {\n withViewBindings?(view: any, displayContext?: string): PolimerModelBuilder<TModel>;\n }\n}\n\ninterface ViewMappings {\n [displayContext: string]: any;\n}\n\nPolimerModelBuilder.prototype.withViewBindings = function (view: any, displayContext: string = DEFAULT_VIEW_KEY): PolimerModelBuilder<any> {\n let builder = this;\n // store some metadata on the builder which we'll use later to tack onto the model\n let viewMappings: ViewMappings = builder._viewMappings || { };\n viewMappings[displayContext] = view;\n builder._viewMappings = viewMappings;\n return this;\n};\n\n// we need to replace the registerWithRouter in order to dynamically add the\n// @viewBinding decorator to it\nlet registerWithRouter = PolimerModelBuilder.prototype.registerWithRouter;\nPolimerModelBuilder.prototype.registerWithRouter = function (): PolimerModel<any> {\n let builder = this;\n let model = registerWithRouter.call(builder);\n let viewMappings: ViewMappings = builder._viewMappings;\n if (viewMappings) {\n Object.keys(viewMappings).forEach(displayContext => {\n viewBinding(viewMappings[displayContext], displayContext)(model.constructor);\n });\n }\n return model;\n};\n","import {useMemo} from 'react';\nimport {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector';\nimport {Router, utils} from 'esp-js';\nimport {useRouter} from './espRouterContextProvider';\nimport {useGetModelId} from './espModelContextProvider';\nimport {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\n\nexport type SyncModelWithSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\n/**\n * Options affecting the subscription of the model to the Router.\n *\n * Use syncModelWithSelectorOptions() to create an instance of this type with sensible defaults.\n *\n * @param modelId - the modelId of the model to be observed via the esp Router.\n * @param tryPreSelectPolimerImmutableModel - if true, and the esp model is an esp-js-polimer model, the immutable model will be used when calling the selector.\n * @param equalityFn - Equality function which will be applied against TSelected, defaults to instance equality (a === b).\n */\nexport type SyncModelWithSelectorOptions<TSelected> = {\n modelId?: string,\n tryPreSelectPolimerImmutableModel: boolean,\n equalityFn: SyncModelWithSelectorEqualityFn<TSelected>\n};\n\n/**\n * Convenience API to build SyncModelWithSelectorOptions<TSelected>, has sensible defaulting.\n */\nexport interface SyncModelWithSelectorOptionsBuilder<TSelected> extends SyncModelWithSelectorOptions<TSelected> {\n /**\n * Sets the model ID\n * @param modelId - default if unset: undefined\n */\n setModelId(modelId: string): this;\n\n /**\n * If the model is a PolimerModel and this set true, PolimerModel.getImmutableModel() will be selected by default.\n * @param value - default if unset: true\n */\n setTryPreSelectPolimerImmutableModel(value: boolean): this;\n\n /**\n * Equality function used when comparing the last TSelected with the next.\n * @param fn - default if unset: obj instance equality (e.g. a===b)\n */\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\n/**\n * Convenience API to create SyncModelWithSelectorOptions\n */\nexport const syncModelWithSelectorOptions = <TSelected>() => {\n let modelId = undefined;\n let equalityFn: SyncModelWithSelectorEqualityFn<TSelected> = (a: TSelected, b: TSelected) => a === b;\n let tryPreSelectPolimerImmutableModel = true;\n return {\n get modelId() {\n return modelId;\n },\n setModelId(value: string) {\n modelId = value;\n return this;\n },\n get equalityFn() {\n return equalityFn;\n },\n setEqualityFn(value: SyncModelWithSelectorEqualityFn<TSelected>) {\n equalityFn = value;\n return this;\n },\n get tryPreSelectPolimerImmutableModel() {\n return tryPreSelectPolimerImmutableModel;\n },\n setTryPreSelectPolimerImmutableModel(value: boolean) {\n tryPreSelectPolimerImmutableModel = value;\n return this;\n }\n } as SyncModelWithSelectorOptionsBuilder<TSelected>;\n};\n\nconst checkArguments = (selector: (model: any) => any, options: SyncModelWithSelectorOptions<any> ) => {\n if (!utils.isFunction(selector)) {\n throw new Error('You must pass a selector function to useSyncModelWithSelector');\n }\n if (!utils.isObject(options)) {\n throw new Error('You must provide options when using useSyncModelWithSelector');\n }\n if (!utils.isFunction(options.equalityFn)) {\n throw new Error('You must provide an equalityFn when using useSyncModelWithSelector');\n }\n};\n\n/**\n * A hook which returns model state from the esp Router.\n *\n * This hooks wih observe updates and re-render the component if the model changes.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node, and optionally EspModelContextProvider.\n *\n * @param selector - a function to select a selection of the model - the selector does not need to be memoized, this selector will be cached against the modelId.\n * @param options\n */\nexport const useSyncModelWithSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: SyncModelWithSelectorOptions<TSelected> = syncModelWithSelectorOptions<TSelected>()\n): TSelected => {\n checkArguments(selector, options);\n const router = useRouter();\n const modelIdFromContext = useGetModelId();\n const modelId = options?.modelId || modelIdFromContext;\n const tryPreSelectPolimerImmutableModel = options?.tryPreSelectPolimerImmutableModel;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\n () => {\n const canSubscribe = router && utils.isString(modelId) && router.isModelRegistered(modelId);\n if (canSubscribe) {\n return createSubscriptionState(router, modelId, selector, tryPreSelectPolimerImmutableModel);\n }\n return createNoopSubscriptionState();\n },\n // Don't add 'selector' to the dependency list as that will likely change unless the caller memoizes it.\n [router, modelId]\n );\n\n // Docs on useSyncExternalStore https://github.com/reactwg/react-18/discussions/86\n // Redux's usage of this: https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.ts\n // Code: https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js\n return useSyncExternalStoreWithSelector(\n dependencies.subscribe,\n dependencies.getSnapshot,\n undefined,\n dependencies.wrappedSelector,\n // equalityFn can't be cached (needs to be a new fn each time)\n // It seems that if it is, you get the last value regardless of if dependencies (and it's associated functions) changes.\n equalityFn,\n );\n};\n\nconst createSubscriptionState = <TModel, TSelected>(\n router: Router,\n modelId: string,\n selector: (model: TModel) => TSelected,\n tryPreSelectPolimerImmutableModel: boolean\n) => {\n // Because of how useSyncExternalStore works, there is an implicit dependency between the subscribe and getSnapshot functions.\n // When the subscription receives the new state from the Router, it can't pass this directly onto getSnapshot,\n // React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // Another edge case with useSyncExternalStore:\n // It will call getSnapshot before it calls subscribe, to account for this we need to fetch the model first.\n // ESP will always dispatch the model when you initially observe it, because we pre-fetched it, the first updated is ignored below.\n const selectModelOrPolimerModel = (m: any): TModel => {\n // try use get the esp-js-polimer immutable model if possible.\n const nextModel = tryPreSelectPolimerImmutableModel\n ? tryGetPolimerImmutableModel(m)\n : m;\n // If the above didn't manage to get a polimer model,\n // we need to mutate to force useSyncExternalStoreWithSelector to pick up the change.\n // This should only affect older style OO models.\n let modelHasNotMutated = nextModel === m;\n return modelHasNotMutated\n ? Object.create(nextModel)\n : nextModel;\n };\n let isFirstRun = true;\n let model: TModel = selectModelOrPolimerModel(router.getModel(modelId));\n return {\n subscribe: (stateChanged: () => void) => {\n const modelSubscriptionDisposable = router\n .getModelObservable<TModel>(modelId)\n .map(m => selectModelOrPolimerModel(m))\n .subscribe(\n (m: any) => {\n if (isFirstRun) {\n isFirstRun = false;\n return;\n }\n model = m;\n stateChanged();\n }\n );\n return () => {\n model = null;\n modelSubscriptionDisposable.dispose();\n };\n },\n // React expects getSnapshot to be immutable, it'll only re-render if the instance changes\n getSnapshot: () => {\n return model;\n },\n // While getSnapshot needs to model to be immutable,\n // useSyncExternalStoreWithSelector builds on top of this, so the TSelected can defer to an equality check to determine if the change is propagated.\n // The selector here just maps the TSelected, useSyncExternalStoreWithSelector internally does the equality check.\n wrappedSelector: (snapshot: TModel) => {\n return snapshot\n ? selector(snapshot)\n : null;\n }\n };\n};\n\nconst createNoopSubscriptionState = () => ({\n subscribe: () => {\n return () => {};\n },\n getSnapshot: () => null,\n wrappedSelector: () => null\n});","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {useRouter} from './espRouterContextProvider';\n\nexport interface ViewBinderProps {\n model: any;\n viewContext?: string;\n /**\n * ...rest props, these will be passed to the child\n */\n [key: string]: any;\n}\n\n/**\n * Takes a model with a @viewBinding decorator and dynamically crates the view specified by the decorator\n */\nexport const ViewBinder: React.FC<ViewBinderProps> = ({model, viewContext, ...rest}) => {\n if (model) {\n const router = useRouter();\n const newProps = {\n model,\n router,\n ...rest\n };\n return createViewForModel(\n model,\n newProps,\n viewContext,\n null\n );\n }\n return null;\n};","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {Guard} from 'esp-js';\n\nexport const DEFAULT_VIEW_KEY = 'default-view-key';\n\nfunction getMetadata(target) {\n if (!target._viewMetadata) {\n target._viewMetadata = new ViewMetadata();\n }\n return target._viewMetadata;\n}\n\n/**\n * Tries to get a view for the given model.\n *\n * It does this using the following order:\n * 1) If a @viewBinding decorator was used and a display context was given, try get a view for that\n * 2) Else if a view was explicitly provided use that\n * 3) Else if a @viewBinding decorator was used and there is a view associated with the default display context, use that view\n * @param model\n * @param props\n * @param displayContext\n * @param view\n */\nexport function createViewForModel(model: any, props: object, displayContext: string, view: React.ComponentType) {\n let finalView: React.ComponentType = view; // default to that passed in, if any.\n\n // displayContext = displayContext || DEFAULT_VIEW_KEY;\n // the view decorator isn't on the instance, it's on the constructor function that created that instance\n if (model) {\n let constructorFunction = model.constructor;\n if (constructorFunction._viewMetadata) {\n let viewMetadata = constructorFunction._viewMetadata;\n if (displayContext && viewMetadata.hasRegisteredViewContext(displayContext)) {\n let viewMetadataRegistration = viewMetadata.viewRegistrations[displayContext];\n // we've found a view for the display context, use that\n finalView = viewMetadataRegistration.view;\n }\n\n // if we've not found a view yet, and one wasn't provided, is there a default one?\n if (!finalView && viewMetadata.hasRegisteredViewContext(DEFAULT_VIEW_KEY)) {\n let viewMetadataRegistration = viewMetadata.viewRegistrations[DEFAULT_VIEW_KEY];\n finalView = viewMetadataRegistration.view;\n }\n }\n }\n if (!finalView) {\n throw new Error(`No suitable view found for model id '${model.modelId}' using context '${displayContext}'`);\n }\n return React.createElement(finalView, props);\n}\n\n/**\n * An ES7 style decorator that associates a model with a view\n * @param view the react component that will be used to display this model\n * @param displayContext an optional context allowing for different views to display the same model\n * @returns {Function}\n */\nexport function viewBinding(view: any, displayContext: string = DEFAULT_VIEW_KEY) {\n Guard.isDefined(view, 'view must be defined');\n Guard.isString(displayContext, 'displayContext must be a string');\n return function (target: any) {\n let viewMetadata = getMetadata(target);\n if (viewMetadata.hasRegisteredViewContext(displayContext)) {\n throw new Error(`Context ${displayContext} already registered for view`);\n }\n viewMetadata.viewRegistrations[displayContext] = new ViewMetadataRegistration(view, displayContext);\n };\n}\n\nexport class ViewMetadata {\n private _viewRegistrations = {};\n\n get viewRegistrations() {\n return this._viewRegistrations;\n }\n\n hasRegisteredViewContext(displayContext) {\n return typeof this._viewRegistrations[displayContext] !== 'undefined';\n }\n}\n\nexport class ViewMetadataRegistration {\n\n constructor(private _view, private _displayContext) {\n }\n\n get view() {\n return this._view;\n }\n\n get displayContext() {\n return this._displayContext;\n }\n}","module.exports = __WEBPACK_EXTERNAL_MODULE__152__;","module.exports = __WEBPACK_EXTERNAL_MODULE__43__;","module.exports = __WEBPACK_EXTERNAL_MODULE__155__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n//\n\n// import for side effects\nimport './polimer/polimerModelBuilderExtentsions';\n\nexport {ViewBinder} from './viewBinder';\nexport {viewBinding, DEFAULT_VIEW_KEY} from './viewBindingDecorator';\nexport {\n GetEspPolimerImmutableModelMetadata,\n GetEspPolimerImmutableModelConsts,\n getEspPolimerImmutableModel\n} from './polimer/getEspPolimerImmutableModel';\nexport {createViewForModel} from './viewBindingDecorator';\nexport {\n connect,\n ConnectableComponentFactory\n} from './connect';\nexport {\n CreatePublishEventProps,\n MapModelToProps,\n ConnectableComponentProps,\n ConnectableComponentChildProps,\n ConnectableComponent,\n} from './connectableComponent';\nexport {\n useSyncModelWithSelector,\n SyncModelWithSelectorOptionsBuilder,\n syncModelWithSelectorOptions,\n SyncModelWithSelectorOptions,\n SyncModelWithSelectorEqualityFn,\n} from './useSyncModelWithSelector';\nexport {\n RouterProvider,\n RouterProviderProps,\n EspRouterContextProvider,\n EspRouterContextProviderProps,\n RouterContext,\n useRouter,\n PublishEventDelegate,\n PublishEventContext,\n usePublishEvent,\n} from './espRouterContextProvider';\nexport {\n useGetModelId,\n GetModelIdContext,\n useGetModel,\n GetModelContext,\n PublishModelEventDelegate,\n PublishModelEventContext,\n usePublishModelEvent,\n PublishModelEventWithEntityKeyDelegate,\n PublishModelEventWithEntityKeyContext,\n usePublishModelEventWithEntityKey,\n EspModelContextProvider,\n EspModelContextProviderProps,\n} from './espModelContextProvider';\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__152__","__WEBPACK_EXTERNAL_MODULE__43__","__WEBPACK_EXTERNAL_MODULE__155__","g","p","Object","is","a","b","q","useSyncExternalStore","r","useRef","t","useEffect","u","useMemo","v","useDebugValue","useSyncExternalStoreWithSelector","e","l","h","c","current","f","hasValue","value","d","k","m","connect","mapModelToProps","createPublishEventProps","view","props","modelId","viewContext","rest","ConnectableComponent","router","useRouter","modelIdFromContext","useGetModelId","publishEventProps","eventType","event","publishEvent","model","useSyncModelWithSelector","syncModelWithSelectorOptions","setModelId","setTryPreSelectPolimerImmutableModel","childProps","restProps","initialModel","tryGetPolimerImmutableModel","getChildProps","viewElement","createViewForModel","EspModelContextProvider","GetModelIdContext","createContext","useContext","GetModelContext","useGetModel","PublishModelEventContext","usePublishModelEvent","PublishModelEventWithEntityKeyContext","usePublishModelEventWithEntityKey","children","publishModelEvent","useCallback","publishModelEventWithEntityKey","entityKey","DefaultModelAddress","Provider","RouterContext","PublishEventContext","usePublishEvent","EspRouterContextProvider","routerFromContext","modelIdOrModelAddress","RouterProvider","target","name","descriptor","EspDecoratorUtil","getOrCreateMetaData","constructor","addCustomData","GetEspPolimerImmutableModelConsts","CustomDataKey","functionName","HandlerFunctionName","hasMetadata","metadata","getCustomData","immutableModel","utils","isFunction","call","PolimerModelBuilder","prototype","withViewBindings","displayContext","DEFAULT_VIEW_KEY","viewMappings","this","_viewMappings","registerWithRouter","keys","forEach","viewBinding","equalityFn","tryPreSelectPolimerImmutableModel","setEqualityFn","selector","options","Error","isObject","checkArguments","dependencies","isString","isModelRegistered","createSubscriptionState","createNoopSubscriptionState","subscribe","getSnapshot","undefined","wrappedSelector","selectModelOrPolimerModel","nextModel","create","isFirstRun","getModel","stateChanged","modelSubscriptionDisposable","getModelObservable","map","dispose","snapshot","ViewBinder","newProps","finalView","constructorFunction","_viewMetadata","viewMetadata","hasRegisteredViewContext","viewRegistrations","React","createElement","Guard","isDefined","ViewMetadata","getMetadata","ViewMetadataRegistration","_viewRegistrations","_view","_displayContext","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","get","getEspPolimerImmutableModel"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"esp-react.min.js","mappings":";CAAA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OD,QAAUO,WCAjBN,EAAOD,QAAUQ,ICCbsJ,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBjC,IAAjBkC,EACH,OAAOA,EAAajK,QAGrB,IAAIC,EAAS6J,EAAyBE,GAAY,CAGjDhK,QAAS,CAAC,GAOX,OAHAkK,EAAoBF,GAAUpE,KAAK3F,EAAOD,QAASC,EAAQA,EAAOD,QAAS+J,GAGpE9J,EAAOD,OACf,gkBCFA,OAEA,aAAQ,4EAAA2I,UAAU,IAClB,aAAQ,6EAAAhC,WAAW,IAAE,kFAAAP,gBAAgB,IACrC,aAAQ,oFAAAlC,kBAAkB,IAC1B,aACI,yEAAA7B,OAAO,IAGX,aAKI,sFAAAQ,oBAAoB,IAExB,aACI,0FAAAU,wBAAwB,IAExB,8FAAAC,4BAA4B,IAIhC,aACI,gFAAAkC,cAAc,IAEd,0FAAAH,wBAAwB,IAExB,+EAAAH,aAAa,IACb,2EAAArC,SAAS,IAET,qFAAAsC,mBAAmB,IACnB,iFAAAC,eAAe,IAEnB,aACI,+EAAArC,aAAa,IACb,mFAAAmB,iBAAiB,IACjB,6EAAAI,WAAW,IACX,iFAAAD,eAAe,IAEf,0FAAAE,wBAAwB,IACxB,sFAAAC,oBAAoB,IAEpB,uGAAAC,qCAAqC,IACrC,mGAAAC,iCAAiC,IACjC,yFAAAT,uBAAuB","sources":["webpack://esp-js-react/webpack/universalModuleDefinition","webpack://esp-js-react/../../node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.min.js","webpack://esp-js-react/../../node_modules/use-sync-external-store/with-selector.js","webpack://esp-js-react/./src/connect.tsx","webpack://esp-js-react/./src/connectableComponent.tsx","webpack://esp-js-react/./src/espModelContextProvider.tsx","webpack://esp-js-react/./src/espRouterContextProvider.tsx","webpack://esp-js-react/./src/polimer/getEspPolimerImmutableModel.ts","webpack://esp-js-react/./src/polimer/polimerModelBuilderExtentsions.ts","webpack://esp-js-react/./src/useSyncModelWithSelector.ts","webpack://esp-js-react/./src/viewBinder.tsx","webpack://esp-js-react/./src/viewBindingDecorator.ts","webpack://esp-js-react/external umd \"esp-js\"","webpack://esp-js-react/external umd \"esp-js-polimer\"","webpack://esp-js-react/external umd \"react\"","webpack://esp-js-react/webpack/bootstrap","webpack://esp-js-react/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"esp-js\"), require(\"esp-js-polimer\"), require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"esp-js\", \"esp-js-polimer\", \"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"esp-js-react\"] = factory(require(\"esp-js\"), require(\"esp-js-polimer\"), require(\"react\"));\n\telse\n\t\troot[\"esp-js-react\"] = factory(root[\"esp-js\"], root[\"esp-js-polimer\"], root[\"react\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__152__, __WEBPACK_EXTERNAL_MODULE__43__, __WEBPACK_EXTERNAL_MODULE__155__) => {\nreturn ","/**\n * @license React\n * use-sync-external-store-with-selector.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var g=require(\"react\");function n(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var p=\"function\"===typeof Object.is?Object.is:n,q=g.useSyncExternalStore,r=g.useRef,t=g.useEffect,u=g.useMemo,v=g.useDebugValue;\nexports.useSyncExternalStoreWithSelector=function(a,b,e,l,h){var c=r(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f}else f=c.current;c=u(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==h&&f.hasValue){var b=f.value;if(h(b,a))return k=b}return k=a}b=k;if(p(d,a))return b;var e=l(a);if(void 0!==h&&h(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return[function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,h]);var d=q(a,c[0],c[1]);\nt(function(){f.hasValue=!0;f.value=d},[d]);v(d);return d};\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.min.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n","import * as React from 'react';\nimport {ConnectableComponent, ConnectableComponentProps, CreatePublishEventProps, MapModelToProps} from './connectableComponent';\n\nexport type ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps = {}> = (view: React.ComponentType) => (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) => React.JSX.Element;\n\n/**\n * @param mapModelToProps - maps the model to a different structure, that structure is sent as props to the view.\n * @param createPublishEventProps - creates functions to publish events, the structure is sent as props to the view.\n */\nexport const connect = function <TModel, TPublishEventProps, TModelMappedToProps = {}>(\n mapModelToProps?: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>\n): ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps> {\n return function (view: React.ComponentType) {\n return function (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) {\n const {modelId, viewContext, ...rest} = props;\n return <ConnectableComponent\n modelId={modelId}\n view={view}\n viewContext={viewContext}\n createPublishEventProps={createPublishEventProps}\n mapModelToProps={mapModelToProps}\n {...rest}\n />;\n };\n };\n};","import * as React from 'react';\nimport {useRouter} from './espRouterContextProvider';\nimport {useMemo} from 'react';\nimport {Router, utils} from 'esp-js';\nimport {EspModelContextProvider, useGetModelId} from './espModelContextProvider';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {hasPolimerImmutableModel, getPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\nimport {syncModelWithSelectorOptions, useSyncModelWithSelector} from './useSyncModelWithSelector';\n\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\nexport type MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\nexport interface ConnectableComponentProps<TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}> {\n modelId?: string;\n viewContext?: string;\n view?: React.ComponentType;\n createPublishEventProps?: CreatePublishEventProps<TPublishEventProps>;\n mapModelToProps?: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>;\n [key: string]: any; // ...rest props, including the result of mapPublish and mapPublish if 'connect' was used\n}\n\nexport interface ConnectableComponentChildProps<TModel = object> {\n modelId: string;\n model: TModel;\n router: Router;\n [key: string]: any; // ...rest props\n}\n\nconst getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(\n router: Router,\n modelId: string,\n restProps: object,\n initialModel: TModel,\n mapModelToProps: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,\n publishEventProps: TPublishEventProps\n): ConnectableComponentChildProps<TModel> => {\n const model = hasPolimerImmutableModel(initialModel)\n ? getPolimerImmutableModel<TModel>(initialModel)\n : initialModel;\n let childProps = {\n modelId,\n router: router,\n ...restProps,\n ...publishEventProps,\n model\n };\n if (mapModelToProps) {\n childProps = {\n ...childProps,\n ...(mapModelToProps(model, publishEventProps) as TModelMappedToProps)\n };\n }\n return childProps;\n};\n\nexport const ConnectableComponent = <TModel = {}, TPublishEventProps = {}, TModelMappedToProps = {}>(\n {\n modelId,\n mapModelToProps,\n createPublishEventProps,\n view,\n viewContext,\n ...rest\n }: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>\n) => {\n const router = useRouter();\n // Note: we always need to render the hooks else react will complain about a different count.\n let modelIdFromContext = useGetModelId();\n modelId = modelId || modelIdFromContext;\n const publishEventProps: TPublishEventProps = useMemo(\n () => {\n if (createPublishEventProps) {\n const publishModelEvent = (eventType: string, event: any) => {\n router.publishEvent(modelId, eventType, event);\n };\n return createPublishEventProps(publishModelEvent);\n }\n return {} as TPublishEventProps;\n },\n [router, modelId]\n );\n const model = useSyncModelWithSelector<TModel, TModel>(\n m => m,\n syncModelWithSelectorOptions()\n .setModelId(modelId)\n .setTryPreSelectPolimerImmutableModel(false)\n );\n if (model == null) {\n return null;\n }\n let childProps = getChildProps(router, modelId, rest, model, mapModelToProps, publishEventProps);\n let viewElement = createViewForModel(model, childProps, viewContext, view);\n return (\n <EspModelContextProvider modelId={modelId} model={model} router={router} {...childProps}>\n {viewElement}\n </EspModelContextProvider>\n );\n};","import * as React from 'react';\nimport {DefaultModelAddress} from 'esp-js';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useRouter} from './espRouterContextProvider';\n\nexport const GetModelIdContext = createContext<string>(null);\n/**\n * Returns a function to get the ID of the model connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const useGetModelId = () => useContext(GetModelIdContext);\n\nexport const GetModelContext = createContext<object>(null);\n/**\n * Returns a function which will return the model connected at a higher point in the V-DOM.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const useGetModel = <TModel,>() => useContext(GetModelContext) as TModel;\n\nexport type PublishModelEventDelegate = (eventType: string, event: any) => void;\nexport const PublishModelEventContext = createContext<PublishModelEventDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the model connected at a higher point in the V-DOM.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the relevant modelId.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const usePublishModelEvent = () => useContext(PublishModelEventContext);\n\nexport type PublishModelEventWithEntityKeyDelegate = (entityKey: string, eventType: string, event: any) => void;\nexport const PublishModelEventWithEntityKeyContext = createContext<PublishModelEventWithEntityKeyDelegate>(null);\n/**\n * Returns a function which can be used to publish an event to the model connected at a higher point in the V-DOM, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the modelId.\n *\n * To use this, please ensure your V-DOM has the EspModelContextProvider at a higher node.\n */\nexport const usePublishModelEventWithEntityKey = () => useContext(PublishModelEventWithEntityKeyContext);\n\nexport interface EspModelContextProviderProps {\n modelId: string;\n model?: any;\n}\n\n/**\n * Sets up various ESP context so ESP hooks are available below this point in the V-DOM\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node.\n * @param modelId\n * @param children\n * @param model\n * @constructor\n */\nexport const EspModelContextProvider = ({modelId, children, model}: PropsWithChildren<EspModelContextProviderProps>) => {\n const router = useRouter();\n // modelId may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let modelIdFromContext = useGetModelId();\n modelId = modelId || modelIdFromContext;\n const publishModelEvent: PublishModelEventDelegate = useCallback((eventType: string, event: any) => {\n router.publishEvent(modelId, eventType, event);\n }, [router, modelId]);\n const publishModelEventWithEntityKey: PublishModelEventWithEntityKeyDelegate = useCallback((entityKey: string, eventType: string, event: any) => {\n router.publishEvent(new DefaultModelAddress(modelId, entityKey), eventType, event);\n }, [router, modelId]);\n return (\n <GetModelIdContext.Provider value={modelId}>\n <PublishModelEventContext.Provider value={publishModelEvent}>\n <PublishModelEventWithEntityKeyContext.Provider value={publishModelEventWithEntityKey}>\n <GetModelContext.Provider value={model}>\n {children}\n </GetModelContext.Provider>\n </PublishModelEventWithEntityKeyContext.Provider>\n </PublishModelEventContext.Provider>\n </GetModelIdContext.Provider>\n );\n};","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {ModelAddress, Router} from 'esp-js';\nimport {PropsWithChildren, createContext, useContext, useCallback} from 'react';\n\nexport const RouterContext = createContext<Router>(null);\n\n/**\n * Get the esp Router from context.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node:\n *\n * <EspRouterContextProvider router={router}>\n * <YourComponents />\n * </EspRouterContextProvider>\n */\nexport const useRouter = () => {\n return useContext(RouterContext);\n};\n\nexport type PublishEventDelegate = (modelIdOrModelAddress: string | ModelAddress, eventType: string, event: any) => void;\nexport const PublishEventContext = createContext<PublishEventDelegate>(null);\n\n/**\n * Returns a function which can be used to publish an event.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node:\n *\n * <EspRouterContextProvider router={router}>\n * <YourComponents />\n * </EspRouterContextProvider>\n */\nexport const usePublishEvent = () => useContext(PublishEventContext);\n\nexport type EspRouterContextProviderProps = PropsWithChildren<{ router: Router; }>;\n\n/**\n * Used to set the router on the RouterContext making it available to components down the tree via the useRouter() hook.\n *\n * Also sets up the usePublishEvent() hook so nested components can publish to the router.\n */\nexport const EspRouterContextProvider = ({children, router}: EspRouterContextProviderProps) => {\n // Router may have been set by a higher level version of this component, so we try and get it from context if it's not set by props.\n let routerFromContext = useRouter();\n router = router || routerFromContext;\n const publishEvent: PublishEventDelegate = useCallback((modelIdOrModelAddress: string, eventType: string, event: any) => {\n router.publishEvent(modelIdOrModelAddress, eventType, event);\n }, [router]);\n return (\n <RouterContext.Provider value={router}>\n <PublishEventContext.Provider value={publishEvent}>\n {children}\n </PublishEventContext.Provider>\n </RouterContext.Provider>\n );\n};\n\n/**\n * Used to set the router on the RouterContext making it available to components down the tree (via useRouter()).\n *\n * @deprecated use EspRouterContextProvider\n */\nexport const RouterProvider = EspRouterContextProvider;\n\n/**\n * Props for RouterProvider\n *\n * @deprecated use EspRouterContextProviderProps\n */\nexport type RouterProviderProps = EspRouterContextProviderProps;\n","import {utils} from 'esp-js';\n\nexport const GetEspPolimerImmutableModelFunctionName = 'getEspPolimerImmutableModel';\n\n/**\n * Returns the model which will be used to pluck state/props for the current view.\n *\n * This is basically a hook (not a React 'hook') to call a function on `model` and get a new subgraph to use as state.\n *\n */\nexport const getPolimerImmutableModel = <TImmutableModel>(model: any): TImmutableModel => {\n // else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?\n let immutableModel = model[GetEspPolimerImmutableModelFunctionName];\n return immutableModel.call(model);\n};\n\nexport const hasPolimerImmutableModel = <TImmutableModel>(model: any): boolean => {\n // else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?\n let getImmutableModelFn = model[GetEspPolimerImmutableModelFunctionName];\n if (getImmutableModelFn && utils.isFunction(getImmutableModelFn)) {\n return true;\n }\n // else return the initial model passed in\n return false;\n};","import {PolimerModelBuilder, PolimerModel} from 'esp-js-polimer';\nimport {DEFAULT_VIEW_KEY, viewBinding} from '../viewBindingDecorator';\n\ndeclare module 'esp-js-polimer/.dist/typings/modelBuilderUpdater' {\n export interface PolimerModelBuilder<TModel> {\n withViewBindings?(view: any, displayContext?: string): PolimerModelBuilder<TModel>;\n }\n}\n\ninterface ViewMappings {\n [displayContext: string]: any;\n}\n\nPolimerModelBuilder.prototype.withViewBindings = function (view: any, displayContext: string = DEFAULT_VIEW_KEY): PolimerModelBuilder<any> {\n let builder = this;\n // store some metadata on the builder which we'll use later to tack onto the model\n let viewMappings: ViewMappings = builder._viewMappings || { };\n viewMappings[displayContext] = view;\n builder._viewMappings = viewMappings;\n return this;\n};\n\n// we need to replace the registerWithRouter in order to dynamically add the\n// @viewBinding decorator to it\nlet registerWithRouter = PolimerModelBuilder.prototype.registerWithRouter;\nPolimerModelBuilder.prototype.registerWithRouter = function (): PolimerModel<any> {\n let builder = this;\n let model = registerWithRouter.call(builder);\n let viewMappings: ViewMappings = builder._viewMappings;\n if (viewMappings) {\n Object.keys(viewMappings).forEach(displayContext => {\n viewBinding(viewMappings[displayContext], displayContext)(model.constructor);\n });\n }\n return model;\n};\n","import {useMemo} from 'react';\nimport {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector';\nimport {Logger, Router, utils} from 'esp-js';\nimport {useRouter} from './espRouterContextProvider';\nimport {useGetModelId} from './espModelContextProvider';\nimport {getPolimerImmutableModel, hasPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\n\nexport type SyncModelWithSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\nexport const logger = Logger.create('useSyncModelWithSelector');\n\n/**\n * Options affecting the subscription of the model to the Router.\n *\n * Use syncModelWithSelectorOptions() to create an instance of this type with sensible defaults.\n *\n * @param modelId - the modelId of the model to be observed via the esp Router.\n * @param tryPreSelectPolimerImmutableModel - if true, and the esp model is an esp-js-polimer model, the immutable model will be used when calling the selector.\n * @param equalityFn - Equality function which will be applied against TSelected, defaults to instance equality (a === b).\n */\nexport type SyncModelWithSelectorOptions<TSelected> = {\n modelId?: string,\n tryPreSelectPolimerImmutableModel: boolean,\n equalityFn: SyncModelWithSelectorEqualityFn<TSelected>\n};\n\n/**\n * Convenience API to build SyncModelWithSelectorOptions<TSelected>, has sensible defaulting.\n */\nexport interface SyncModelWithSelectorOptionsBuilder<TSelected> extends SyncModelWithSelectorOptions<TSelected> {\n /**\n * Sets the model ID\n * @param modelId - default if unset: undefined\n */\n setModelId(modelId: string): this;\n\n /**\n * If the model is a PolimerModel and this set true, PolimerModel.getImmutableModel() will be selected by default.\n * @param value - default if unset: true\n */\n setTryPreSelectPolimerImmutableModel(value: boolean): this;\n\n /**\n * Equality function used when comparing the last TSelected with the next.\n * @param fn - default if unset: obj instance equality (e.g. a===b)\n */\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\n/**\n * Convenience API to create SyncModelWithSelectorOptions\n */\nexport const syncModelWithSelectorOptions = <TSelected>() => {\n let modelId = undefined;\n let equalityFn: SyncModelWithSelectorEqualityFn<TSelected> = (a: TSelected, b: TSelected) => a === b;\n let tryPreSelectPolimerImmutableModel = true;\n return {\n get modelId() {\n return modelId;\n },\n setModelId(value: string) {\n modelId = value;\n return this;\n },\n get equalityFn() {\n return equalityFn;\n },\n setEqualityFn(value: SyncModelWithSelectorEqualityFn<TSelected>) {\n equalityFn = value;\n return this;\n },\n get tryPreSelectPolimerImmutableModel() {\n return tryPreSelectPolimerImmutableModel;\n },\n setTryPreSelectPolimerImmutableModel(value: boolean) {\n tryPreSelectPolimerImmutableModel = value;\n return this;\n }\n } as SyncModelWithSelectorOptionsBuilder<TSelected>;\n};\n\nconst checkArguments = (selector: (model: any) => any, options: SyncModelWithSelectorOptions<any> ) => {\n if (!utils.isFunction(selector)) {\n throw new Error('You must pass a selector function to useSyncModelWithSelector');\n }\n if (!utils.isObject(options)) {\n throw new Error('You must provide options when using useSyncModelWithSelector');\n }\n if (!utils.isFunction(options.equalityFn)) {\n throw new Error('You must provide an equalityFn when using useSyncModelWithSelector');\n }\n};\n\n/**\n * A hook which returns model state from the esp Router.\n *\n * This hooks wih observe updates and re-render the component if the model changes.\n *\n * To use this, please ensure your V-DOM has the EspRouterContextProvider at a higher node, and optionally EspModelContextProvider.\n *\n * @param selector - a function to select a selection of the model - the selector does not need to be memoized, this selector will be cached against the modelId.\n * @param options\n */\nexport const useSyncModelWithSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: SyncModelWithSelectorOptions<TSelected> = syncModelWithSelectorOptions<TSelected>()\n): TSelected => {\n checkArguments(selector, options);\n const router = useRouter();\n const modelIdFromContext = useGetModelId();\n const modelId = options?.modelId || modelIdFromContext;\n const tryPreSelectPolimerImmutableModel = options?.tryPreSelectPolimerImmutableModel;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\n () => {\n const canSubscribe = router && utils.isString(modelId) && router.isModelRegistered(modelId);\n if (canSubscribe) {\n return createSubscriptionState(router, modelId, selector, tryPreSelectPolimerImmutableModel);\n }\n return createNoopSubscriptionState();\n },\n // Don't add 'selector' to the dependency list as that will likely change unless the caller memoizes it.\n [router, modelId]\n );\n\n // Docs on useSyncExternalStore https://github.com/reactwg/react-18/discussions/86\n // Redux's usage of this: https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.ts\n // Code: https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js\n return useSyncExternalStoreWithSelector(\n dependencies.subscribe,\n dependencies.getSnapshot,\n undefined,\n dependencies.wrappedSelector,\n equalityFn,\n );\n};\n\nconst createSubscriptionState = <TModel, TSelected>(\n router: Router,\n modelId: string,\n selector: (model: TModel) => TSelected,\n tryPreSelectPolimerImmutableModel: boolean\n) => {\n // Because of how useSyncExternalStore works, there is an implicit dependency between the subscribe and getSnapshot functions.\n // When the subscription receives the new state from the Router, it can't pass this directly onto getSnapshot,\n // React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // Another edge case with useSyncExternalStore:\n // It will call getSnapshot before it calls subscribe, to account for this we need to fetch the model first.\n let currentModel: TModel;\n let onStateChanged: () => void = null;\n const modelSubscriptionDisposable = router\n .getModelObservable<TModel>(modelId)\n .subscribe(\n (m: any) => {\n // try and get the esp-js-polimer immutable model if possible, this should mutate when any state changes\n const nextModel = tryPreSelectPolimerImmutableModel && hasPolimerImmutableModel(m)\n ? getPolimerImmutableModel<TModel>(m)\n // If the above didn't manage to get a polimer model,\n // we need to mutate to force useSyncExternalStoreWithSelector to pick up the change.\n // This should only affect older style OO models.\n : Object.create(m);\n warnIfModelInstanceHasNotChanged(modelId, currentModel, nextModel);\n currentModel = nextModel;\n if (onStateChanged) {\n onStateChanged();\n }\n }\n );\n return {\n subscribe: (stateChanged: () => void) => {\n onStateChanged = stateChanged;\n return () => {\n onStateChanged = null;\n currentModel = null;\n modelSubscriptionDisposable.dispose();\n };\n },\n // React expects getSnapshot to be immutable, it'll only re-render if the instance changes\n getSnapshot: () => {\n return currentModel;\n },\n // While getSnapshot needs to model to be immutable,\n // useSyncExternalStoreWithSelector builds on top of this, so the TSelected can defer to an equality check to determine if the change is propagated.\n // The selector here just maps the TSelected, useSyncExternalStoreWithSelector internally does the equality check.\n wrappedSelector: (snapshot: TModel) => {\n return snapshot\n ? selector(snapshot)\n : null;\n }\n };\n};\n\nconst createNoopSubscriptionState = () => ({\n subscribe: () => {\n return () => {};\n },\n getSnapshot: () => null,\n wrappedSelector: () => null\n});\n\nconst warnIfModelInstanceHasNotChanged = (modelId: string, lastModel: any, nextModel: string) => {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if (utils.stringIsEmpty(modelId)) {\n return;\n }\n if (lastModel === nextModel) {\n let stack: string | undefined = undefined;\n try {\n // noinspection ExceptionCaughtLocallyJS\n throw new Error();\n } catch (e) {\n stack = (e as Error).stack;\n }\n logger.warn(\n `useSyncModelWithSelector had detected the latest model update hasn't mutated. This will cause odd render bugs. modelId: ${modelId}`,\n stack\n );\n }\n};","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {useRouter} from './espRouterContextProvider';\n\nexport interface ViewBinderProps {\n model: any;\n viewContext?: string;\n /**\n * ...rest props, these will be passed to the child\n */\n [key: string]: any;\n}\n\n/**\n * Takes a model with a @viewBinding decorator and dynamically crates the view specified by the decorator\n */\nexport const ViewBinder: React.FC<ViewBinderProps> = ({model, viewContext, ...rest}) => {\n if (model) {\n const router = useRouter();\n const newProps = {\n model,\n router,\n ...rest\n };\n return createViewForModel(\n model,\n newProps,\n viewContext,\n null\n );\n }\n return null;\n};","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n\nimport * as React from 'react';\nimport {Guard} from 'esp-js';\n\nexport const DEFAULT_VIEW_KEY = 'default-view-key';\n\nfunction getMetadata(target) {\n if (!target._viewMetadata) {\n target._viewMetadata = new ViewMetadata();\n }\n return target._viewMetadata;\n}\n\n/**\n * Tries to get a view for the given model.\n *\n * It does this using the following order:\n * 1) If a @viewBinding decorator was used and a display context was given, try get a view for that\n * 2) Else if a view was explicitly provided use that\n * 3) Else if a @viewBinding decorator was used and there is a view associated with the default display context, use that view\n * @param model\n * @param props\n * @param displayContext\n * @param view\n */\nexport function createViewForModel(model: any, props: object, displayContext: string, view: React.ComponentType) {\n let finalView: React.ComponentType = view; // default to that passed in, if any.\n\n // displayContext = displayContext || DEFAULT_VIEW_KEY;\n // the view decorator isn't on the instance, it's on the constructor function that created that instance\n if (model) {\n let constructorFunction = model.constructor;\n if (constructorFunction._viewMetadata) {\n let viewMetadata = constructorFunction._viewMetadata;\n if (displayContext && viewMetadata.hasRegisteredViewContext(displayContext)) {\n let viewMetadataRegistration = viewMetadata.viewRegistrations[displayContext];\n // we've found a view for the display context, use that\n finalView = viewMetadataRegistration.view;\n }\n\n // if we've not found a view yet, and one wasn't provided, is there a default one?\n if (!finalView && viewMetadata.hasRegisteredViewContext(DEFAULT_VIEW_KEY)) {\n let viewMetadataRegistration = viewMetadata.viewRegistrations[DEFAULT_VIEW_KEY];\n finalView = viewMetadataRegistration.view;\n }\n }\n }\n if (!finalView) {\n throw new Error(`No suitable view found for model id '${model.modelId}' using context '${displayContext}'`);\n }\n return React.createElement(finalView, props);\n}\n\n/**\n * An ES7 style decorator that associates a model with a view\n * @param view the react component that will be used to display this model\n * @param displayContext an optional context allowing for different views to display the same model\n * @returns {Function}\n */\nexport function viewBinding(view: any, displayContext: string = DEFAULT_VIEW_KEY) {\n Guard.isDefined(view, 'view must be defined');\n Guard.isString(displayContext, 'displayContext must be a string');\n return function (target: any) {\n let viewMetadata = getMetadata(target);\n if (viewMetadata.hasRegisteredViewContext(displayContext)) {\n throw new Error(`Context ${displayContext} already registered for view`);\n }\n viewMetadata.viewRegistrations[displayContext] = new ViewMetadataRegistration(view, displayContext);\n };\n}\n\nexport class ViewMetadata {\n private _viewRegistrations = {};\n\n get viewRegistrations() {\n return this._viewRegistrations;\n }\n\n hasRegisteredViewContext(displayContext) {\n return typeof this._viewRegistrations[displayContext] !== 'undefined';\n }\n}\n\nexport class ViewMetadataRegistration {\n\n constructor(private _view, private _displayContext) {\n }\n\n get view() {\n return this._view;\n }\n\n get displayContext() {\n return this._displayContext;\n }\n}","module.exports = __WEBPACK_EXTERNAL_MODULE__152__;","module.exports = __WEBPACK_EXTERNAL_MODULE__43__;","module.exports = __WEBPACK_EXTERNAL_MODULE__155__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// notice_start\n/*\n * Copyright 2015 Dev Shop Limited\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// notice_end\n//\n\n// import for side effects\nimport './polimer/polimerModelBuilderExtentsions';\n\nexport {ViewBinder} from './viewBinder';\nexport {viewBinding, DEFAULT_VIEW_KEY} from './viewBindingDecorator';\nexport {createViewForModel} from './viewBindingDecorator';\nexport {\n connect,\n ConnectableComponentFactory\n} from './connect';\nexport {\n CreatePublishEventProps,\n MapModelToProps,\n ConnectableComponentProps,\n ConnectableComponentChildProps,\n ConnectableComponent,\n} from './connectableComponent';\nexport {\n useSyncModelWithSelector,\n SyncModelWithSelectorOptionsBuilder,\n syncModelWithSelectorOptions,\n SyncModelWithSelectorOptions,\n SyncModelWithSelectorEqualityFn,\n} from './useSyncModelWithSelector';\nexport {\n RouterProvider,\n RouterProviderProps,\n EspRouterContextProvider,\n EspRouterContextProviderProps,\n RouterContext,\n useRouter,\n PublishEventDelegate,\n PublishEventContext,\n usePublishEvent,\n} from './espRouterContextProvider';\nexport {\n useGetModelId,\n GetModelIdContext,\n useGetModel,\n GetModelContext,\n PublishModelEventDelegate,\n PublishModelEventContext,\n usePublishModelEvent,\n PublishModelEventWithEntityKeyDelegate,\n PublishModelEventWithEntityKeyContext,\n usePublishModelEventWithEntityKey,\n EspModelContextProvider,\n EspModelContextProviderProps,\n} from './espModelContextProvider';\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__152__","__WEBPACK_EXTERNAL_MODULE__43__","__WEBPACK_EXTERNAL_MODULE__155__","g","p","Object","is","a","b","q","useSyncExternalStore","r","useRef","t","useEffect","u","useMemo","v","useDebugValue","useSyncExternalStoreWithSelector","e","l","h","c","current","f","hasValue","value","d","k","m","connect","mapModelToProps","createPublishEventProps","view","props","modelId","viewContext","rest","ConnectableComponent","router","useRouter","modelIdFromContext","useGetModelId","publishEventProps","eventType","event","publishEvent","model","useSyncModelWithSelector","syncModelWithSelectorOptions","setModelId","setTryPreSelectPolimerImmutableModel","childProps","restProps","initialModel","hasPolimerImmutableModel","getPolimerImmutableModel","getChildProps","viewElement","createViewForModel","EspModelContextProvider","GetModelIdContext","createContext","useContext","GetModelContext","useGetModel","PublishModelEventContext","usePublishModelEvent","PublishModelEventWithEntityKeyContext","usePublishModelEventWithEntityKey","children","publishModelEvent","useCallback","publishModelEventWithEntityKey","entityKey","DefaultModelAddress","Provider","RouterContext","PublishEventContext","usePublishEvent","EspRouterContextProvider","routerFromContext","modelIdOrModelAddress","RouterProvider","GetEspPolimerImmutableModelFunctionName","call","getImmutableModelFn","utils","isFunction","PolimerModelBuilder","prototype","withViewBindings","displayContext","DEFAULT_VIEW_KEY","viewMappings","this","_viewMappings","registerWithRouter","keys","forEach","viewBinding","constructor","logger","Logger","create","equalityFn","tryPreSelectPolimerImmutableModel","setEqualityFn","selector","options","Error","isObject","checkArguments","dependencies","isString","isModelRegistered","createSubscriptionState","createNoopSubscriptionState","subscribe","getSnapshot","undefined","wrappedSelector","currentModel","onStateChanged","modelSubscriptionDisposable","getModelObservable","nextModel","warnIfModelInstanceHasNotChanged","stateChanged","dispose","snapshot","lastModel","ViewBinder","newProps","finalView","constructorFunction","_viewMetadata","viewMetadata","hasRegisteredViewContext","viewRegistrations","React","createElement","Guard","isDefined","target","ViewMetadata","getMetadata","ViewMetadataRegistration","_viewRegistrations","_view","_displayContext","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
package/.dist/typings/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import './polimer/polimerModelBuilderExtentsions';
|
|
2
2
|
export { ViewBinder } from './viewBinder';
|
|
3
3
|
export { viewBinding, DEFAULT_VIEW_KEY } from './viewBindingDecorator';
|
|
4
|
-
export { GetEspPolimerImmutableModelMetadata, GetEspPolimerImmutableModelConsts, getEspPolimerImmutableModel } from './polimer/getEspPolimerImmutableModel';
|
|
5
4
|
export { createViewForModel } from './viewBindingDecorator';
|
|
6
5
|
export { connect, ConnectableComponentFactory } from './connect';
|
|
7
6
|
export { CreatePublishEventProps, MapModelToProps, ConnectableComponentProps, ConnectableComponentChildProps, ConnectableComponent, } from './connectableComponent';
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
functionName: string;
|
|
3
|
-
}
|
|
4
|
-
export declare namespace GetEspPolimerImmutableModelConsts {
|
|
5
|
-
const CustomDataKey = "GetEspReactImmutableModelCustomDataKey";
|
|
6
|
-
/**
|
|
7
|
-
* If there is no @getEspPolimerImmutableModel decorator and a function by this name exists on a model, then it will be invoked to identify the sub model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
8
|
-
*/
|
|
9
|
-
const HandlerFunctionName = "getEspPolimerImmutableModel";
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A decorator which can be used to identify the render model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
13
|
-
*/
|
|
14
|
-
export declare function getEspPolimerImmutableModel(): (target: any, name: any, descriptor: any) => any;
|
|
1
|
+
export declare const GetEspPolimerImmutableModelFunctionName = "getEspPolimerImmutableModel";
|
|
15
2
|
/**
|
|
16
3
|
* Returns the model which will be used to pluck state/props for the current view.
|
|
17
4
|
*
|
|
18
5
|
* This is basically a hook (not a React 'hook') to call a function on `model` and get a new subgraph to use as state.
|
|
19
6
|
*
|
|
20
7
|
*/
|
|
21
|
-
export declare const
|
|
8
|
+
export declare const getPolimerImmutableModel: <TImmutableModel>(model: any) => TImmutableModel;
|
|
9
|
+
export declare const hasPolimerImmutableModel: <TImmutableModel>(model: any) => boolean;
|
package/.yarnignore
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esp-js-react",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.7-next.0",
|
|
4
4
|
"description": "Evented State Processor (ESP) React Components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dev": "nps dev"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"esp-js": "^8.0.
|
|
28
|
-
"esp-js-polimer": "^8.0.
|
|
27
|
+
"esp-js": "^8.0.7-next.0",
|
|
28
|
+
"esp-js-polimer": "^8.0.7-next.0",
|
|
29
29
|
"prop-types": "^15.7.2",
|
|
30
30
|
"react": "^18.3.1",
|
|
31
31
|
"use-sync-external-store": "^1.2.2"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"esp-js": "^7.0.0",
|
|
42
42
|
"esp-js-polimer": "^7.0.0",
|
|
43
43
|
"prop-types": "^15.0.0",
|
|
44
|
-
"react": "^18.0.0"
|
|
44
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "cf6d29ee45603404e9b5bdcd056b3fa651cc0ddc"
|
|
47
47
|
}
|
|
@@ -4,7 +4,7 @@ import {useMemo} from 'react';
|
|
|
4
4
|
import {Router, utils} from 'esp-js';
|
|
5
5
|
import {EspModelContextProvider, useGetModelId} from './espModelContextProvider';
|
|
6
6
|
import {createViewForModel} from './viewBindingDecorator';
|
|
7
|
-
import {
|
|
7
|
+
import {hasPolimerImmutableModel, getPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';
|
|
8
8
|
import {syncModelWithSelectorOptions, useSyncModelWithSelector} from './useSyncModelWithSelector';
|
|
9
9
|
|
|
10
10
|
export type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;
|
|
@@ -35,7 +35,9 @@ const getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(
|
|
|
35
35
|
mapModelToProps: MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps>,
|
|
36
36
|
publishEventProps: TPublishEventProps
|
|
37
37
|
): ConnectableComponentChildProps<TModel> => {
|
|
38
|
-
const model =
|
|
38
|
+
const model = hasPolimerImmutableModel(initialModel)
|
|
39
|
+
? getPolimerImmutableModel<TModel>(initialModel)
|
|
40
|
+
: initialModel;
|
|
39
41
|
let childProps = {
|
|
40
42
|
modelId,
|
|
41
43
|
router: router,
|
package/src/index.ts
CHANGED
|
@@ -22,11 +22,6 @@ import './polimer/polimerModelBuilderExtentsions';
|
|
|
22
22
|
|
|
23
23
|
export {ViewBinder} from './viewBinder';
|
|
24
24
|
export {viewBinding, DEFAULT_VIEW_KEY} from './viewBindingDecorator';
|
|
25
|
-
export {
|
|
26
|
-
GetEspPolimerImmutableModelMetadata,
|
|
27
|
-
GetEspPolimerImmutableModelConsts,
|
|
28
|
-
getEspPolimerImmutableModel
|
|
29
|
-
} from './polimer/getEspPolimerImmutableModel';
|
|
30
25
|
export {createViewForModel} from './viewBindingDecorator';
|
|
31
26
|
export {
|
|
32
27
|
connect,
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {utils} from 'esp-js';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
functionName: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export namespace GetEspPolimerImmutableModelConsts {
|
|
8
|
-
export const CustomDataKey = 'GetEspReactImmutableModelCustomDataKey';
|
|
9
|
-
/**
|
|
10
|
-
* If there is no @getEspPolimerImmutableModel decorator and a function by this name exists on a model, then it will be invoked to identify the sub model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
11
|
-
*/
|
|
12
|
-
export const HandlerFunctionName = 'getEspPolimerImmutableModel';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A decorator which can be used to identify the render model which will replaced the `model` prop passed to the child view of a ConnectableComponent
|
|
17
|
-
*/
|
|
18
|
-
export function getEspPolimerImmutableModel() {
|
|
19
|
-
return function (target, name, descriptor) {
|
|
20
|
-
let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);
|
|
21
|
-
metadata.addCustomData(
|
|
22
|
-
GetEspPolimerImmutableModelConsts.CustomDataKey,
|
|
23
|
-
<GetEspPolimerImmutableModelMetadata>{ functionName: name }
|
|
24
|
-
);
|
|
25
|
-
return descriptor;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
3
|
+
export const GetEspPolimerImmutableModelFunctionName = 'getEspPolimerImmutableModel';
|
|
28
4
|
|
|
29
5
|
/**
|
|
30
6
|
* Returns the model which will be used to pluck state/props for the current view.
|
|
@@ -32,19 +8,18 @@ export function getEspPolimerImmutableModel() {
|
|
|
32
8
|
* This is basically a hook (not a React 'hook') to call a function on `model` and get a new subgraph to use as state.
|
|
33
9
|
*
|
|
34
10
|
*/
|
|
35
|
-
export const
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
11
|
+
export const getPolimerImmutableModel = <TImmutableModel>(model: any): TImmutableModel => {
|
|
12
|
+
// else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?
|
|
13
|
+
let immutableModel = model[GetEspPolimerImmutableModelFunctionName];
|
|
14
|
+
return immutableModel.call(model);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const hasPolimerImmutableModel = <TImmutableModel>(model: any): boolean => {
|
|
43
18
|
// else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
19
|
+
let getImmutableModelFn = model[GetEspPolimerImmutableModelFunctionName];
|
|
20
|
+
if (getImmutableModelFn && utils.isFunction(getImmutableModelFn)) {
|
|
21
|
+
return true;
|
|
47
22
|
}
|
|
48
23
|
// else return the initial model passed in
|
|
49
|
-
return
|
|
24
|
+
return false;
|
|
50
25
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {useMemo} from 'react';
|
|
2
2
|
import {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector';
|
|
3
|
-
import {Router, utils} from 'esp-js';
|
|
3
|
+
import {Logger, Router, utils} from 'esp-js';
|
|
4
4
|
import {useRouter} from './espRouterContextProvider';
|
|
5
5
|
import {useGetModelId} from './espModelContextProvider';
|
|
6
|
-
import {
|
|
6
|
+
import {getPolimerImmutableModel, hasPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';
|
|
7
7
|
|
|
8
8
|
export type SyncModelWithSelectorEqualityFn<T> = (last: T, next: T) => boolean;
|
|
9
9
|
|
|
10
|
+
export const logger = Logger.create('useSyncModelWithSelector');
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Options affecting the subscription of the model to the Router.
|
|
12
14
|
*
|
|
@@ -129,8 +131,6 @@ export const useSyncModelWithSelector = <TModel, TSelected>(
|
|
|
129
131
|
dependencies.getSnapshot,
|
|
130
132
|
undefined,
|
|
131
133
|
dependencies.wrappedSelector,
|
|
132
|
-
// equalityFn can't be cached (needs to be a new fn each time)
|
|
133
|
-
// It seems that if it is, you get the last value regardless of if dependencies (and it's associated functions) changes.
|
|
134
134
|
equalityFn,
|
|
135
135
|
);
|
|
136
136
|
};
|
|
@@ -148,45 +148,38 @@ const createSubscriptionState = <TModel, TSelected>(
|
|
|
148
148
|
//
|
|
149
149
|
// Another edge case with useSyncExternalStore:
|
|
150
150
|
// It will call getSnapshot before it calls subscribe, to account for this we need to fetch the model first.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
let currentModel: TModel;
|
|
152
|
+
let onStateChanged: () => void = null;
|
|
153
|
+
const modelSubscriptionDisposable = router
|
|
154
|
+
.getModelObservable<TModel>(modelId)
|
|
155
|
+
.subscribe(
|
|
156
|
+
(m: any) => {
|
|
157
|
+
// try and get the esp-js-polimer immutable model if possible, this should mutate when any state changes
|
|
158
|
+
const nextModel = tryPreSelectPolimerImmutableModel && hasPolimerImmutableModel(m)
|
|
159
|
+
? getPolimerImmutableModel<TModel>(m)
|
|
160
|
+
// If the above didn't manage to get a polimer model,
|
|
161
|
+
// we need to mutate to force useSyncExternalStoreWithSelector to pick up the change.
|
|
162
|
+
// This should only affect older style OO models.
|
|
163
|
+
: Object.create(m);
|
|
164
|
+
warnIfModelInstanceHasNotChanged(modelId, currentModel, nextModel);
|
|
165
|
+
currentModel = nextModel;
|
|
166
|
+
if (onStateChanged) {
|
|
167
|
+
onStateChanged();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
167
171
|
return {
|
|
168
172
|
subscribe: (stateChanged: () => void) => {
|
|
169
|
-
|
|
170
|
-
.getModelObservable<TModel>(modelId)
|
|
171
|
-
.map(m => selectModelOrPolimerModel(m))
|
|
172
|
-
.subscribe(
|
|
173
|
-
(m: any) => {
|
|
174
|
-
if (isFirstRun) {
|
|
175
|
-
isFirstRun = false;
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
model = m;
|
|
179
|
-
stateChanged();
|
|
180
|
-
}
|
|
181
|
-
);
|
|
173
|
+
onStateChanged = stateChanged;
|
|
182
174
|
return () => {
|
|
183
|
-
|
|
175
|
+
onStateChanged = null;
|
|
176
|
+
currentModel = null;
|
|
184
177
|
modelSubscriptionDisposable.dispose();
|
|
185
178
|
};
|
|
186
179
|
},
|
|
187
180
|
// React expects getSnapshot to be immutable, it'll only re-render if the instance changes
|
|
188
181
|
getSnapshot: () => {
|
|
189
|
-
return
|
|
182
|
+
return currentModel;
|
|
190
183
|
},
|
|
191
184
|
// While getSnapshot needs to model to be immutable,
|
|
192
185
|
// useSyncExternalStoreWithSelector builds on top of this, so the TSelected can defer to an equality check to determine if the change is propagated.
|
|
@@ -205,4 +198,26 @@ const createNoopSubscriptionState = () => ({
|
|
|
205
198
|
},
|
|
206
199
|
getSnapshot: () => null,
|
|
207
200
|
wrappedSelector: () => null
|
|
208
|
-
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const warnIfModelInstanceHasNotChanged = (modelId: string, lastModel: any, nextModel: string) => {
|
|
204
|
+
if (process.env.NODE_ENV === 'production') {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (utils.stringIsEmpty(modelId)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (lastModel === nextModel) {
|
|
211
|
+
let stack: string | undefined = undefined;
|
|
212
|
+
try {
|
|
213
|
+
// noinspection ExceptionCaughtLocallyJS
|
|
214
|
+
throw new Error();
|
|
215
|
+
} catch (e) {
|
|
216
|
+
stack = (e as Error).stack;
|
|
217
|
+
}
|
|
218
|
+
logger.warn(
|
|
219
|
+
`useSyncModelWithSelector had detected the latest model update hasn't mutated. This will cause odd render bugs. modelId: ${modelId}`,
|
|
220
|
+
stack
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
};
|