esp-js-react 8.0.1-next.0 → 8.0.2-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 +32 -32
- 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 +2 -2
- package/.dist/typings/polimer/getEspPolimerImmutableModel.d.ts +21 -0
- package/package.json +4 -4
- package/src/connectableComponent.tsx +2 -2
- package/src/index.ts +5 -5
- package/src/polimer/getEspPolimerImmutableModel.ts +50 -0
- package/src/useModelSelector.ts +2 -2
- package/src/viewBinderConnectable.tsx +4 -4
- package/tests/connectableComponentLegacyTests.tsx +23 -23
- package/tests/connectableComponentTests.tsx +419 -0
- package/tests/indexTests.ts +25 -91
- package/tests/testApi/asserts.ts +75 -0
- package/tests/testApi/testApi.tsx +84 -0
- package/tests/testApi/testModel.ts +37 -0
- package/tests/testApi/useStoreReceivedProps.ts +11 -0
- package/tests/testApi/viewMetadata.tsx +46 -0
- package/tests/useModelSelectorTests.tsx +45 -149
- package/.dist/typings/polimer/getEspReactRenderModel.d.ts +0 -21
- package/src/polimer/getEspReactRenderModel.ts +0 -50
- /package/.dist/typings/polimer/{polimerExtentsions.d.ts → polimerModelBuilderExtentsions.d.ts} +0 -0
- /package/src/polimer/{polimerExtentsions.ts → polimerModelBuilderExtentsions.ts} +0 -0
- /package/tests/{routerSpy.ts → testApi/routerSpy.ts} +0 -0
|
@@ -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,gBAAk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nB,aACI,+EAAA9C,aAAa,IAEb,mFAAAsB,iBAAiB,IACjB,6EAAAI,WAAW,IAEX,iFAAAD,eAAe,IAEf,0FAAAE,wBAAwB,IACxB,sFAAAC,oBAAoB,IAEpB,uGAAAC,qCAAqC,IACrC,mGAAAC,iCAAiC,IACjC,yFAAAX,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/getEspReactRenderModel.ts","webpack://esp-js-react/./src/polimer/polimerExtentsions.ts","webpack://esp-js-react/./src/useModelSelector.ts","webpack://esp-js-react/./src/viewBinder.tsx","webpack://esp-js-react/./src/viewBinderConnectable.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\n/**\n * @deprecated\n */\nexport type ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps = {}> = (view: React.ComponentType) => (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) => React.JSX.Element;\n\n/**\n * @deprecated\n * @param mapModelToProps\n * @param createPublishEventProps\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 {tryGetRenderModel} from './polimer/getEspReactRenderModel';\nimport {modelSelectorOptions, useModelSelector} from './useModelSelector';\n\n/**\n * @deprecated\n */\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\n/**\n * @deprecated\n */\nexport type MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\n/**\n * @deprecated\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\n/**\n * @deprecated\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 // consume what this component owns, and let the rest end up in `...rest`\n const model = tryGetRenderModel<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\n/**\n * @deprecated - use ViewBinderConnectable and ESP hooks if you need to dynamically bind a view to a model\n * or useModelSelector with other ESP hooks for direct model subscription.\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 modelId = modelId || useGetModelId();\n if (utils.stringIsEmpty(modelId) || !router) {\n return null;\n }\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 = useModelSelector<TModel, TModel>(\n m => m,\n modelSelectorOptions()\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, Router, Status, Logger, utils} from 'esp-js';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useRouter} from './espRouterContextProvider';\n\nconst _log = Logger.create('EspModelContextProvider');\n\nexport type GetModelIdDelegate = () => string;\nexport const GetModelIdContext = createContext<GetModelIdDelegate>(null);\n/**\n * Returns a function which will return the ID of the model currently being rendered.\n */\nexport const useGetModelId = () => useContext(GetModelIdContext)();\n\nexport type GetModelDelegate = <TModel = any, >() => TModel;\nexport const GetModelContext = createContext<GetModelDelegate>(null);\n/**\n * Returns a function which will return the model set at last dispatch.\n */\nexport const useGetModel = () => useContext(GetModelContext)();\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 current model being rendered.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the current modelId.\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 current model being rendered, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the current modelId.\n */\nexport const usePublishModelEventWithEntityKey = () => useContext(PublishModelEventWithEntityKeyContext);\n\nexport interface EspModelContextProviderProps {\n modelId: string;\n model?: unknown;\n}\n\nexport const EspModelContextProvider = ({modelId, children, model}: PropsWithChildren<EspModelContextProviderProps>) => {\n const router = useRouter();\n const getModelId: () => string = useCallback(() => {\n return modelId;\n }, [router, modelId]);\n const getModel: () => any = useCallback(() => {\n warnIfModelAccessedOutSideDispatchLoop(router, modelId);\n return model;\n }, [model, router, modelId]);\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={getModelId}>\n <PublishModelEventContext.Provider value={publishModelEvent}>\n <PublishModelEventWithEntityKeyContext.Provider value={publishModelEventWithEntityKey}>\n <GetModelContext.Provider value={getModel}>\n {children}\n </GetModelContext.Provider>\n </PublishModelEventWithEntityKeyContext.Provider>\n </PublishModelEventContext.Provider>\n </GetModelIdContext.Provider>\n );\n};\n\nconst warnIfModelAccessedOutSideDispatchLoop = (router: Router, modelId: string) => {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if (utils.stringIsEmpty(modelId)) {\n return;\n }\n let isDispatchModelUpdateStatus = router.isModelDispatchStatus(modelId, Status.DispatchModelUpdates);\n if (!isDispatchModelUpdateStatus) {\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 _log.warn(\n `EspModelContextProvider useGetModelId has been invoked outside of the models (${modelId}) dispatch loop.` +\n `This may have unknown state state issues.` +\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 {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 the RouterContext\n *\n * To use this, please ensure your V-DOM has the EspRouterContext at a higher node:\n *\n * <EspRouterContext router={router}>\n * <YourComponents />\n * </EspRouterContext>\n */\nexport const useRouter = () => {\n const context: Router = useContext(RouterContext);\n if (context === undefined) {\n throw new Error('useRouter must be used within a RouterContext.Provider');\n }\n return context;\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 EspRouterContext 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 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 GetEspReactRenderModelMetadata {\n functionName: string;\n}\n\nexport namespace GetEspReactRenderModelConsts {\n export const CustomDataKey = 'GetEspReactRenderModelCustomDataKey';\n /**\n * If there is no @getEspReactRenderModel 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 = 'getEspReactRenderModel';\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 getEspReactRenderModel() {\n return function (target, name, descriptor) {\n let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);\n metadata.addCustomData(\n GetEspReactRenderModelConsts.CustomDataKey,\n <GetEspReactRenderModelMetadata>{ 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 tryGetRenderModel = <TRenderModel>(model: any): TRenderModel => {\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: GetEspReactRenderModelMetadata = EspDecoratorUtil.getCustomData(model, GetEspReactRenderModelConsts.CustomDataKey);\n if (metadata) {\n return model[metadata.functionName]();\n }\n }\n // else see if there is a function with name GetEspReactRenderModelConsts.HandlerFunctionName we can invoke to get a different model to render?\n let renderModelGetter = model[GetEspReactRenderModelConsts.HandlerFunctionName];\n if (renderModelGetter && utils.isFunction(renderModelGetter)) {\n return renderModelGetter.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 {Guard, utils} from 'esp-js';\nimport {useRouter} from './espRouterContextProvider';\nimport {useGetModelId} from './espModelContextProvider';\nimport {tryGetRenderModel} from './polimer/getEspReactRenderModel';\n\nexport type ModelSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\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 ModelSelectorOptions<TSelected> = {\n modelId?: string,\n tryPreSelectPolimerImmutableModel: boolean,\n equalityFn: ModelSelectorEqualityFn<TSelected>\n};\n\nexport interface EditableModelSelectorOptions<TSelected> extends ModelSelectorOptions<TSelected> {\n setModelId(modelId: string): this;\n\n setTryPreSelectPolimerImmutableModel(value: boolean): this;\n\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\nexport const modelSelectorOptions = <TSelected>() => {\n let modelId = undefined;\n let equalityFn: ModelSelectorEqualityFn<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: ModelSelectorEqualityFn<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 EditableModelSelectorOptions<TSelected>;\n};\n\nexport type UseModelSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options?: ModelSelectorOptions<TSelected>\n) => TSelected;\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 * @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 useModelSelector: UseModelSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: ModelSelectorOptions<TSelected> = modelSelectorOptions<TSelected>()\n) => {\n Guard.isFunction(selector, 'You must pass a selector function to connectSelector');\n const router = useRouter();\n const modelId = options?.modelId || useGetModelId();\n const tryPreSelectPolimerImmutableModel = options?.tryPreSelectPolimerImmutableModel;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\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, React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // It's not ideal but shouldn't be a problem as here we've wrapped all these dependent functions inside a single useMemo()\n let model: TModel = null;\n return {\n subscribe: (stateChanged: () => void) => {\n const modelSubscriptionDisposable = router\n .getModelObservable(modelId)\n .subscribe(\n (m: any) => {\n // try and get a submodel to render\n const nextModel = tryPreSelectPolimerImmutableModel\n ? tryGetRenderModel(m)\n : m;\n // if the above didn't manage to get a submodel,\n // we need to mutate to force useSyncExternalStoreWithSelector to pick up the change\n model = nextModel === m\n ? Object.create(nextModel)\n : nextModel;\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 // The first time this renders, react calls getSnapshot and the selector before the router has pushed a change.\n // In that case, there is no state for any component to process, therefore, we return null;\n return snapshot\n ? selector(snapshot)\n : null;\n }\n };\n },\n // Don't cache check against 'selector' argument as that will likely change unless the caller memoizes it.\n [router, modelId]\n );\n\n // If we don't have a modelId, we still need to return a hook so React doesn't complain.\n // Additionally, we need to let the above expiration (dependencies) run to unsubscribe from any previous subscription.\n if (utils.stringIsEmpty(modelId)) {\n return useSyncExternalStoreWithSelector(\n noopSubscription.subscribe,\n noopSubscription.getSnapshot,\n undefined,\n noopSubscription.wrappedSelector,\n equalityFn\n );\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 noopSubscription = {\n subscribe: () => { },\n getSnapshot: () => null,\n wrappedSelector: () => true\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\nexport const ViewBinder: React.FC<ViewBinderProps> = ({model, viewContext, ...rest}) => {\n if (model) {\n const router = useRouter();\n const newProps = Object.assign({}, {model, router}, rest);\n return createViewForModel(\n model,\n newProps,\n viewContext,\n null\n );\n }\n return null;\n};","import {useRouter} from './espRouterContextProvider';\nimport {EspModelContextProvider} from './espModelContextProvider';\nimport {Logger, Router} from 'esp-js';\nimport * as React from 'react';\nimport {modelSelectorOptions, useModelSelector} from './useModelSelector';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {tryGetRenderModel} from './polimer/getEspReactRenderModel';\n\nconst _log = Logger.create('ViewBinderConnectable');\n\nexport interface ViewBinderConnectableProps {\n modelId?: string;\n viewContext?: string;\n view?: React.ComponentType;\n}\n\ninterface ViewBinderConnectableChildProps {\n modelId: string;\n model: object;\n router: Router;\n}\n\n/**\n * Dynamically binds a view found via @viewBinder(SomeJsXView) to a model managed by the Router.\n * Optionally provide a view override and/or a viewContext\n * @param modelId\n * @param viewContext\n * @param view\n * @constructor\n */\nexport const ViewBinderConnectable = ({modelId, viewContext, view}: ViewBinderConnectableProps) => {\n const router = useRouter();\n const model = useModelSelector<object, object>(\n m => m,\n modelSelectorOptions()\n .setModelId(modelId)\n .setTryPreSelectPolimerImmutableModel(false)\n );\n if (!model) {\n return null;\n }\n let renderModel = tryGetRenderModel<object>(model);\n const childProps: ViewBinderConnectableChildProps = {\n modelId,\n router: router,\n model: renderModel\n };\n let viewElement = createViewForModel(model, childProps, viewContext, view);\n return (\n <EspModelContextProvider modelId={modelId} router={router} model={renderModel} {...childProps}>\n {viewElement}\n </EspModelContextProvider>\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 {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, 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) {\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/polimerExtentsions';\n\nexport {ViewBinder} from './viewBinder';\nexport {\n ViewBinderConnectableProps,\n ViewBinderConnectable\n} from './viewBinderConnectable';\nexport {viewBinding, DEFAULT_VIEW_KEY} from './viewBindingDecorator';\nexport {\n GetEspReactRenderModelMetadata,\n GetEspReactRenderModelConsts,\n getEspReactRenderModel\n} from './polimer/getEspReactRenderModel';\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 UseModelSelector,\n useModelSelector,\n EditableModelSelectorOptions,\n modelSelectorOptions,\n ModelSelectorOptions,\n ModelSelectorEqualityFn,\n} from './useModelSelector';\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 GetModelIdDelegate,\n GetModelIdContext,\n useGetModel,\n GetModelDelegate,\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","useGetModelId","utils","stringIsEmpty","publishEventProps","eventType","event","publishEvent","model","useModelSelector","modelSelectorOptions","setModelId","setTryPreSelectPolimerImmutableModel","childProps","restProps","initialModel","tryGetRenderModel","getChildProps","viewElement","createViewForModel","EspModelContextProvider","Logger","create","GetModelIdContext","createContext","useContext","GetModelContext","useGetModel","PublishModelEventContext","usePublishModelEvent","PublishModelEventWithEntityKeyContext","usePublishModelEventWithEntityKey","children","getModelId","useCallback","getModel","warnIfModelAccessedOutSideDispatchLoop","publishModelEvent","publishModelEventWithEntityKey","entityKey","DefaultModelAddress","Provider","RouterContext","context","undefined","Error","PublishEventContext","usePublishEvent","EspRouterContextProvider","modelIdOrModelAddress","RouterProvider","target","name","descriptor","EspDecoratorUtil","getOrCreateMetaData","constructor","addCustomData","GetEspReactRenderModelConsts","CustomDataKey","functionName","HandlerFunctionName","hasMetadata","metadata","getCustomData","renderModelGetter","isFunction","call","PolimerModelBuilder","prototype","withViewBindings","displayContext","DEFAULT_VIEW_KEY","viewMappings","this","_viewMappings","registerWithRouter","keys","forEach","viewBinding","equalityFn","tryPreSelectPolimerImmutableModel","setEqualityFn","selector","options","Guard","dependencies","subscribe","stateChanged","modelSubscriptionDisposable","getModelObservable","nextModel","dispose","getSnapshot","wrappedSelector","snapshot","noopSubscription","ViewBinder","newProps","assign","ViewBinderConnectable","renderModel","finalView","constructorFunction","_viewMetadata","viewMetadata","hasRegisteredViewContext","viewRegistrations","React","createElement","isDefined","isString","ViewMetadata","getMetadata","ViewMetadataRegistration","_viewRegistrations","_view","_displayContext","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","get","getEspReactRenderModel"],"sourceRoot":""}
|
|
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,EAA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C,IACjC,yFAAAX,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/useModelSelector.ts","webpack://esp-js-react/./src/viewBinder.tsx","webpack://esp-js-react/./src/viewBinderConnectable.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\n/**\n * @deprecated\n */\nexport type ConnectableComponentFactory<TModel, TPublishEventProps, TModelMappedToProps = {}> = (view: React.ComponentType) => (props: ConnectableComponentProps<TModel, TPublishEventProps, TModelMappedToProps>) => React.JSX.Element;\n\n/**\n * @deprecated\n * @param mapModelToProps\n * @param createPublishEventProps\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 {modelSelectorOptions, useModelSelector} from './useModelSelector';\n\n/**\n * @deprecated\n */\nexport type CreatePublishEventProps<TPublishEventProps> = (publishModelEvent: (eventType: string, event: any) => void) => TPublishEventProps;\n\n/**\n * @deprecated\n */\nexport type MapModelToProps<TModel, TModelMappedToProps, TPublishEventProps = {}> = (model: TModel, publishEventProps: TPublishEventProps) => TModelMappedToProps;\n\n/**\n * @deprecated\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\n/**\n * @deprecated\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 // consume what this component owns, and let the rest end up in `...rest`\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\n/**\n * @deprecated - use ViewBinderConnectable and ESP hooks if you need to dynamically bind a view to a model\n * or useModelSelector with other ESP hooks for direct model subscription.\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 modelId = modelId || useGetModelId();\n if (utils.stringIsEmpty(modelId) || !router) {\n return null;\n }\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 = useModelSelector<TModel, TModel>(\n m => m,\n modelSelectorOptions()\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, Router, Status, Logger, utils} from 'esp-js';\nimport {useContext, useCallback, createContext, PropsWithChildren} from 'react';\nimport {useRouter} from './espRouterContextProvider';\n\nconst _log = Logger.create('EspModelContextProvider');\n\nexport type GetModelIdDelegate = () => string;\nexport const GetModelIdContext = createContext<GetModelIdDelegate>(null);\n/**\n * Returns a function which will return the ID of the model currently being rendered.\n */\nexport const useGetModelId = () => useContext(GetModelIdContext)();\n\nexport type GetModelDelegate = <TModel = any, >() => TModel;\nexport const GetModelContext = createContext<GetModelDelegate>(null);\n/**\n * Returns a function which will return the model set at last dispatch.\n */\nexport const useGetModel = () => useContext(GetModelContext)();\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 current model being rendered.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the current modelId.\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 current model being rendered, allows an entityKey to be specified.\n *\n * Effectively, this is a version of usePublishEvent() which closes over the current modelId.\n */\nexport const usePublishModelEventWithEntityKey = () => useContext(PublishModelEventWithEntityKeyContext);\n\nexport interface EspModelContextProviderProps {\n modelId: string;\n model?: unknown;\n}\n\nexport const EspModelContextProvider = ({modelId, children, model}: PropsWithChildren<EspModelContextProviderProps>) => {\n const router = useRouter();\n const getModelId: () => string = useCallback(() => {\n return modelId;\n }, [router, modelId]);\n const getModel: () => any = useCallback(() => {\n warnIfModelAccessedOutSideDispatchLoop(router, modelId);\n return model;\n }, [model, router, modelId]);\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={getModelId}>\n <PublishModelEventContext.Provider value={publishModelEvent}>\n <PublishModelEventWithEntityKeyContext.Provider value={publishModelEventWithEntityKey}>\n <GetModelContext.Provider value={getModel}>\n {children}\n </GetModelContext.Provider>\n </PublishModelEventWithEntityKeyContext.Provider>\n </PublishModelEventContext.Provider>\n </GetModelIdContext.Provider>\n );\n};\n\nconst warnIfModelAccessedOutSideDispatchLoop = (router: Router, modelId: string) => {\n if (process.env.NODE_ENV === 'production') {\n return;\n }\n if (utils.stringIsEmpty(modelId)) {\n return;\n }\n let isDispatchModelUpdateStatus = router.isModelDispatchStatus(modelId, Status.DispatchModelUpdates);\n if (!isDispatchModelUpdateStatus) {\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 _log.warn(\n `EspModelContextProvider useGetModelId has been invoked outside of the models (${modelId}) dispatch loop.` +\n `This may have unknown state state issues.` +\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 {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 the RouterContext\n *\n * To use this, please ensure your V-DOM has the EspRouterContext at a higher node:\n *\n * <EspRouterContext router={router}>\n * <YourComponents />\n * </EspRouterContext>\n */\nexport const useRouter = () => {\n const context: Router = useContext(RouterContext);\n if (context === undefined) {\n throw new Error('useRouter must be used within a RouterContext.Provider');\n }\n return context;\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 EspRouterContext 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 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 {Guard, utils} from 'esp-js';\nimport {useRouter} from './espRouterContextProvider';\nimport {useGetModelId} from './espModelContextProvider';\nimport {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\n\nexport type ModelSelectorEqualityFn<T> = (last: T, next: T) => boolean;\n\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 ModelSelectorOptions<TSelected> = {\n modelId?: string,\n tryPreSelectPolimerImmutableModel: boolean,\n equalityFn: ModelSelectorEqualityFn<TSelected>\n};\n\nexport interface EditableModelSelectorOptions<TSelected> extends ModelSelectorOptions<TSelected> {\n setModelId(modelId: string): this;\n\n setTryPreSelectPolimerImmutableModel(value: boolean): this;\n\n setEqualityFn(fn: (a: TSelected, b: TSelected) => boolean): this;\n}\n\nexport const modelSelectorOptions = <TSelected>() => {\n let modelId = undefined;\n let equalityFn: ModelSelectorEqualityFn<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: ModelSelectorEqualityFn<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 EditableModelSelectorOptions<TSelected>;\n};\n\nexport type UseModelSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options?: ModelSelectorOptions<TSelected>\n) => TSelected;\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 * @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 useModelSelector: UseModelSelector = <TModel, TSelected>(\n selector: (model: TModel) => TSelected,\n options: ModelSelectorOptions<TSelected> = modelSelectorOptions<TSelected>()\n) => {\n Guard.isFunction(selector, 'You must pass a selector function to connectSelector');\n const router = useRouter();\n const modelId = options?.modelId || useGetModelId();\n const tryPreSelectPolimerImmutableModel = options?.tryPreSelectPolimerImmutableModel;\n const equalityFn = options?.equalityFn;\n const dependencies = useMemo(\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, React calls that when it deems it needs to.\n // Given that, we need to cache the state which getSnapshot will return.\n //\n // It's not ideal but shouldn't be a problem as here we've wrapped all these dependent functions inside a single useMemo()\n let model: TModel = null;\n return {\n subscribe: (stateChanged: () => void) => {\n const modelSubscriptionDisposable = router\n .getModelObservable(modelId)\n .subscribe(\n (m: any) => {\n // try and get a submodel to render\n const nextModel = tryPreSelectPolimerImmutableModel\n ? tryGetPolimerImmutableModel(m)\n : m;\n // if the above didn't manage to get a submodel,\n // we need to mutate to force useSyncExternalStoreWithSelector to pick up the change\n model = nextModel === m\n ? Object.create(nextModel)\n : nextModel;\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 // The first time this renders, react calls getSnapshot and the selector before the router has pushed a change.\n // In that case, there is no state for any component to process, therefore, we return null;\n return snapshot\n ? selector(snapshot)\n : null;\n }\n };\n },\n // Don't cache check against 'selector' argument as that will likely change unless the caller memoizes it.\n [router, modelId]\n );\n\n // If we don't have a modelId, we still need to return a hook so React doesn't complain.\n // Additionally, we need to let the above expiration (dependencies) run to unsubscribe from any previous subscription.\n if (utils.stringIsEmpty(modelId)) {\n return useSyncExternalStoreWithSelector(\n noopSubscription.subscribe,\n noopSubscription.getSnapshot,\n undefined,\n noopSubscription.wrappedSelector,\n equalityFn\n );\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 noopSubscription = {\n subscribe: () => { },\n getSnapshot: () => null,\n wrappedSelector: () => true\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\nexport const ViewBinder: React.FC<ViewBinderProps> = ({model, viewContext, ...rest}) => {\n if (model) {\n const router = useRouter();\n const newProps = Object.assign({}, {model, router}, rest);\n return createViewForModel(\n model,\n newProps,\n viewContext,\n null\n );\n }\n return null;\n};","import {useRouter} from './espRouterContextProvider';\nimport {EspModelContextProvider} from './espModelContextProvider';\nimport {Logger, Router} from 'esp-js';\nimport * as React from 'react';\nimport {modelSelectorOptions, useModelSelector} from './useModelSelector';\nimport {createViewForModel} from './viewBindingDecorator';\nimport {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';\n\nconst _log = Logger.create('ViewBinderConnectable');\n\nexport interface ViewBinderConnectableProps {\n modelId?: string;\n viewContext?: string;\n view?: React.ComponentType;\n}\n\ninterface ViewBinderConnectableChildProps {\n modelId: string;\n model: object;\n router: Router;\n}\n\n/**\n * Dynamically binds a view found via @viewBinder(SomeJsXView) to a model managed by the Router.\n * Optionally provide a view override and/or a viewContext\n * @param modelId\n * @param viewContext\n * @param view\n * @constructor\n */\nexport const ViewBinderConnectable = ({modelId, viewContext, view}: ViewBinderConnectableProps) => {\n const router = useRouter();\n const model = useModelSelector<object, object>(\n m => m,\n modelSelectorOptions()\n .setModelId(modelId)\n .setTryPreSelectPolimerImmutableModel(false)\n );\n if (!model) {\n return null;\n }\n let immutableModel = tryGetPolimerImmutableModel<object>(model);\n const childProps: ViewBinderConnectableChildProps = {\n modelId,\n router: router,\n model: immutableModel\n };\n let viewElement = createViewForModel(model, childProps, viewContext, view);\n return (\n <EspModelContextProvider modelId={modelId} router={router} model={immutableModel} {...childProps}>\n {viewElement}\n </EspModelContextProvider>\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 {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, 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) {\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 {\n ViewBinderConnectableProps,\n ViewBinderConnectable\n} from './viewBinderConnectable';\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 UseModelSelector,\n useModelSelector,\n EditableModelSelectorOptions,\n modelSelectorOptions,\n ModelSelectorOptions,\n ModelSelectorEqualityFn,\n} from './useModelSelector';\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 GetModelIdDelegate,\n GetModelIdContext,\n useGetModel,\n GetModelDelegate,\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","useGetModelId","utils","stringIsEmpty","publishEventProps","eventType","event","publishEvent","model","useModelSelector","modelSelectorOptions","setModelId","setTryPreSelectPolimerImmutableModel","childProps","restProps","initialModel","tryGetPolimerImmutableModel","getChildProps","viewElement","createViewForModel","EspModelContextProvider","Logger","create","GetModelIdContext","createContext","useContext","GetModelContext","useGetModel","PublishModelEventContext","usePublishModelEvent","PublishModelEventWithEntityKeyContext","usePublishModelEventWithEntityKey","children","getModelId","useCallback","getModel","warnIfModelAccessedOutSideDispatchLoop","publishModelEvent","publishModelEventWithEntityKey","entityKey","DefaultModelAddress","Provider","RouterContext","context","undefined","Error","PublishEventContext","usePublishEvent","EspRouterContextProvider","modelIdOrModelAddress","RouterProvider","target","name","descriptor","EspDecoratorUtil","getOrCreateMetaData","constructor","addCustomData","GetEspPolimerImmutableModelConsts","CustomDataKey","functionName","HandlerFunctionName","hasMetadata","metadata","getCustomData","immutableModel","isFunction","call","PolimerModelBuilder","prototype","withViewBindings","displayContext","DEFAULT_VIEW_KEY","viewMappings","this","_viewMappings","registerWithRouter","keys","forEach","viewBinding","equalityFn","tryPreSelectPolimerImmutableModel","setEqualityFn","selector","options","Guard","dependencies","subscribe","stateChanged","modelSubscriptionDisposable","getModelObservable","nextModel","dispose","getSnapshot","wrappedSelector","snapshot","noopSubscription","ViewBinder","newProps","assign","ViewBinderConnectable","finalView","constructorFunction","_viewMetadata","viewMetadata","hasRegisteredViewContext","viewRegistrations","React","createElement","isDefined","isString","ViewMetadata","getMetadata","ViewMetadataRegistration","_viewRegistrations","_view","_displayContext","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","get","getEspPolimerImmutableModel"],"sourceRoot":""}
|
package/.dist/typings/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import './polimer/
|
|
1
|
+
import './polimer/polimerModelBuilderExtentsions';
|
|
2
2
|
export { ViewBinder } from './viewBinder';
|
|
3
3
|
export { ViewBinderConnectableProps, ViewBinderConnectable } from './viewBinderConnectable';
|
|
4
4
|
export { viewBinding, DEFAULT_VIEW_KEY } from './viewBindingDecorator';
|
|
5
|
-
export {
|
|
5
|
+
export { GetEspPolimerImmutableModelMetadata, GetEspPolimerImmutableModelConsts, getEspPolimerImmutableModel } from './polimer/getEspPolimerImmutableModel';
|
|
6
6
|
export { createViewForModel } from './viewBindingDecorator';
|
|
7
7
|
export { connect, ConnectableComponentFactory } from './connect';
|
|
8
8
|
export { CreatePublishEventProps, MapModelToProps, ConnectableComponentProps, ConnectableComponentChildProps, ConnectableComponent, } from './connectableComponent';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface GetEspPolimerImmutableModelMetadata {
|
|
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;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the model which will be used to pluck state/props for the current view.
|
|
17
|
+
*
|
|
18
|
+
* 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
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export declare const tryGetPolimerImmutableModel: <TImmutableModel>(model: any) => TImmutableModel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esp-js-react",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2-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.2-next.0",
|
|
28
|
+
"esp-js-polimer": "^8.0.2-next.0",
|
|
29
29
|
"prop-types": "^15.7.2",
|
|
30
30
|
"react": "^18.3.1",
|
|
31
31
|
"use-sync-external-store": "^1.2.2"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"prop-types": "^15.0.0",
|
|
44
44
|
"react": "^18.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "b6d4d9e658a90dd5045fc796fd216111b0ae18d5"
|
|
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 {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';
|
|
8
8
|
import {modelSelectorOptions, useModelSelector} from './useModelSelector';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -48,7 +48,7 @@ const getChildProps = <TModel, TModelMappedToProps, TPublishEventProps>(
|
|
|
48
48
|
publishEventProps: TPublishEventProps
|
|
49
49
|
): ConnectableComponentChildProps<TModel> => {
|
|
50
50
|
// consume what this component owns, and let the rest end up in `...rest`
|
|
51
|
-
const model =
|
|
51
|
+
const model = tryGetPolimerImmutableModel<TModel>(initialModel);
|
|
52
52
|
let childProps = {
|
|
53
53
|
modelId,
|
|
54
54
|
router: router,
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
//
|
|
19
19
|
|
|
20
20
|
// import for side effects
|
|
21
|
-
import './polimer/
|
|
21
|
+
import './polimer/polimerModelBuilderExtentsions';
|
|
22
22
|
|
|
23
23
|
export {ViewBinder} from './viewBinder';
|
|
24
24
|
export {
|
|
@@ -27,10 +27,10 @@ export {
|
|
|
27
27
|
} from './viewBinderConnectable';
|
|
28
28
|
export {viewBinding, DEFAULT_VIEW_KEY} from './viewBindingDecorator';
|
|
29
29
|
export {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} from './polimer/
|
|
30
|
+
GetEspPolimerImmutableModelMetadata,
|
|
31
|
+
GetEspPolimerImmutableModelConsts,
|
|
32
|
+
getEspPolimerImmutableModel
|
|
33
|
+
} from './polimer/getEspPolimerImmutableModel';
|
|
34
34
|
export {createViewForModel} from './viewBindingDecorator';
|
|
35
35
|
export {
|
|
36
36
|
connect,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {EspMetadata, EspDecoratorUtil, utils} from 'esp-js';
|
|
2
|
+
|
|
3
|
+
export interface GetEspPolimerImmutableModelMetadata {
|
|
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
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the model which will be used to pluck state/props for the current view.
|
|
31
|
+
*
|
|
32
|
+
* 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
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export const tryGetPolimerImmutableModel = <TImmutableModel>(model: any): TImmutableModel => {
|
|
36
|
+
// does the given model have a decorated function we can invoke to get a different model to render?
|
|
37
|
+
if (EspDecoratorUtil.hasMetadata(model)) {
|
|
38
|
+
let metadata: GetEspPolimerImmutableModelMetadata = EspDecoratorUtil.getCustomData(model, GetEspPolimerImmutableModelConsts.CustomDataKey);
|
|
39
|
+
if (metadata) {
|
|
40
|
+
return model[metadata.functionName]();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// else see if there is a function with name GetEspPolimerImmutableModelConsts.HandlerFunctionName we can invoke to get a different model to render?
|
|
44
|
+
let immutableModel = model[GetEspPolimerImmutableModelConsts.HandlerFunctionName];
|
|
45
|
+
if (immutableModel && utils.isFunction(immutableModel)) {
|
|
46
|
+
return immutableModel.call(model);
|
|
47
|
+
}
|
|
48
|
+
// else return the initial model passed in
|
|
49
|
+
return model;
|
|
50
|
+
};
|
package/src/useModelSelector.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-sel
|
|
|
3
3
|
import {Guard, utils} from 'esp-js';
|
|
4
4
|
import {useRouter} from './espRouterContextProvider';
|
|
5
5
|
import {useGetModelId} from './espModelContextProvider';
|
|
6
|
-
import {
|
|
6
|
+
import {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';
|
|
7
7
|
|
|
8
8
|
export type ModelSelectorEqualityFn<T> = (last: T, next: T) => boolean;
|
|
9
9
|
|
|
@@ -93,7 +93,7 @@ export const useModelSelector: UseModelSelector = <TModel, TSelected>(
|
|
|
93
93
|
(m: any) => {
|
|
94
94
|
// try and get a submodel to render
|
|
95
95
|
const nextModel = tryPreSelectPolimerImmutableModel
|
|
96
|
-
?
|
|
96
|
+
? tryGetPolimerImmutableModel(m)
|
|
97
97
|
: m;
|
|
98
98
|
// if the above didn't manage to get a submodel,
|
|
99
99
|
// we need to mutate to force useSyncExternalStoreWithSelector to pick up the change
|
|
@@ -4,7 +4,7 @@ import {Logger, Router} from 'esp-js';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import {modelSelectorOptions, useModelSelector} from './useModelSelector';
|
|
6
6
|
import {createViewForModel} from './viewBindingDecorator';
|
|
7
|
-
import {
|
|
7
|
+
import {tryGetPolimerImmutableModel} from './polimer/getEspPolimerImmutableModel';
|
|
8
8
|
|
|
9
9
|
const _log = Logger.create('ViewBinderConnectable');
|
|
10
10
|
|
|
@@ -39,15 +39,15 @@ export const ViewBinderConnectable = ({modelId, viewContext, view}: ViewBinderCo
|
|
|
39
39
|
if (!model) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
|
-
let
|
|
42
|
+
let immutableModel = tryGetPolimerImmutableModel<object>(model);
|
|
43
43
|
const childProps: ViewBinderConnectableChildProps = {
|
|
44
44
|
modelId,
|
|
45
45
|
router: router,
|
|
46
|
-
model:
|
|
46
|
+
model: immutableModel
|
|
47
47
|
};
|
|
48
48
|
let viewElement = createViewForModel(model, childProps, viewContext, view);
|
|
49
49
|
return (
|
|
50
|
-
<EspModelContextProvider modelId={modelId} router={router} model={
|
|
50
|
+
<EspModelContextProvider modelId={modelId} router={router} model={immutableModel} {...childProps}>
|
|
51
51
|
{viewElement}
|
|
52
52
|
</EspModelContextProvider>
|
|
53
53
|
);
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ConnectableComponent,
|
|
6
6
|
ConnectableComponentProps,
|
|
7
7
|
viewBinding,
|
|
8
|
-
|
|
8
|
+
getEspPolimerImmutableModel,
|
|
9
9
|
PublishModelEventDelegate,
|
|
10
10
|
RouterContext,
|
|
11
11
|
EspRouterContextProvider
|
|
@@ -13,17 +13,17 @@ import {
|
|
|
13
13
|
import {Router, observeEvent, utils} from 'esp-js';
|
|
14
14
|
import {render, RenderResult} from '@testing-library/react';
|
|
15
15
|
|
|
16
|
-
const getPropsAsDataAttributesWithMetadata = (props: any) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
16
|
+
// const getPropsAsDataAttributesWithMetadata = (props: any) => {
|
|
17
|
+
// const propsAsDataAttributes: {[key: string]: string} = Object.keys(props).reduce((result: any, key: string) => {
|
|
18
|
+
// let prop = props[key];
|
|
19
|
+
// // need to lower case data-* attributes else React throws a warning
|
|
20
|
+
// result[`data-${key.toLowerCase()}`] = utils.isString(prop)
|
|
21
|
+
// ? prop
|
|
22
|
+
// : typeof prop;
|
|
23
|
+
// return result;
|
|
24
|
+
// }, {});
|
|
25
|
+
// return propsAsDataAttributes;
|
|
26
|
+
// };
|
|
27
27
|
|
|
28
28
|
class TestModelView1 extends React.Component {
|
|
29
29
|
constructor(props) {
|
|
@@ -77,7 +77,7 @@ class TestModel {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
class TestModel2 extends TestModel {
|
|
80
|
-
@
|
|
80
|
+
@getEspPolimerImmutableModel()
|
|
81
81
|
_getOtherState() {
|
|
82
82
|
return {
|
|
83
83
|
value: this.value,
|
|
@@ -88,7 +88,7 @@ class TestModel2 extends TestModel {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
class TestModel3 extends TestModel {
|
|
91
|
-
|
|
91
|
+
getEspPolimerImmutableModel() {
|
|
92
92
|
return {
|
|
93
93
|
value: this.value,
|
|
94
94
|
value2: this.value,
|
|
@@ -109,11 +109,11 @@ interface TestOptions {
|
|
|
109
109
|
useCreatePublishEventProps?: boolean;
|
|
110
110
|
useAlternativeViewContext?: boolean;
|
|
111
111
|
passOtherProps?: boolean;
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
useImmutableModelSelectorDecorator?: boolean;
|
|
113
|
+
useImmutableModelSelectorFunction?: boolean;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
xdescribe('ConnectableComponent', () => {
|
|
117
117
|
let router,
|
|
118
118
|
testModel: TestModel,
|
|
119
119
|
testModel2: TestModel,
|
|
@@ -126,10 +126,10 @@ describe('ConnectableComponent', () => {
|
|
|
126
126
|
otherProps = {other1: 'other-value'};
|
|
127
127
|
|
|
128
128
|
function createModel(options: TestOptions) {
|
|
129
|
-
if (options.
|
|
129
|
+
if (options.useImmutableModelSelectorDecorator) {
|
|
130
130
|
return new TestModel2();
|
|
131
131
|
}
|
|
132
|
-
if (options.
|
|
132
|
+
if (options.useImmutableModelSelectorFunction) {
|
|
133
133
|
return new TestModel3();
|
|
134
134
|
}
|
|
135
135
|
return new TestModel();
|
|
@@ -379,24 +379,24 @@ describe('ConnectableComponent', () => {
|
|
|
379
379
|
//
|
|
380
380
|
// describe('using @stateToRenderSelector', () => {
|
|
381
381
|
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
382
|
-
// setup({useConnectFunction: false,
|
|
382
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true});
|
|
383
383
|
// testModelHasBeenReplacedWithMappedModel('value-3');
|
|
384
384
|
// });
|
|
385
385
|
//
|
|
386
386
|
// it('passes the swapped model to mapModelToProps function', () => {
|
|
387
|
-
// setup({useConnectFunction: false,
|
|
387
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorDecorator: true, useMapModelToProps: true});
|
|
388
388
|
// testSwappedModelPassedToMapModelToPropsFunction('value-3');
|
|
389
389
|
// });
|
|
390
390
|
// });
|
|
391
391
|
//
|
|
392
392
|
// describe('using state to render function', () => {
|
|
393
393
|
// it('Swaps the model for that returned by the function decorated with a @stateToRenderSelector decorator', () => {
|
|
394
|
-
// setup({useConnectFunction: false,
|
|
394
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true});
|
|
395
395
|
// testModelHasBeenReplacedWithMappedModel('value-3.1');
|
|
396
396
|
// });
|
|
397
397
|
//
|
|
398
398
|
// it('passes the swapped model to mapModelToProps function', () => {
|
|
399
|
-
// setup({useConnectFunction: false,
|
|
399
|
+
// setup({useConnectFunction: false, useImmutableModelSelectorFunction: true, useMapModelToProps: true});
|
|
400
400
|
// testSwappedModelPassedToMapModelToPropsFunction('value-3.1');
|
|
401
401
|
// });
|
|
402
402
|
// });
|