esp-js-react 7.0.2-next.0 → 8.0.0-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 +425 -510
- package/.dist/esp-react.js.map +1 -1
- package/.dist/esp-react.min.js +2 -1
- package/.dist/esp-react.min.js.LICENSE.txt +9 -0
- package/.dist/esp-react.min.js.map +1 -1
- package/.dist/typings/connect.d.ts +12 -0
- package/.dist/typings/connectableComponent.d.ts +20 -46
- package/.dist/typings/espModelContext.d.ts +7 -8
- package/.dist/typings/espRouterContext.d.ts +47 -0
- package/.dist/typings/index.d.ts +7 -6
- package/.dist/typings/{getEspReactRenderModel.d.ts → polimer/getEspReactRenderModel.d.ts} +7 -0
- package/.dist/typings/useModelSelector.d.ts +13 -0
- package/.dist/typings/viewBinder.d.ts +1 -8
- package/.dist/typings/viewBinderConnectable.d.ts +15 -0
- package/.dist/typings/viewBindingDecorator.d.ts +1 -2
- package/package.json +7 -6
- package/src/connect.tsx +31 -0
- package/src/connectableComponent.tsx +93 -190
- package/src/espModelContext.tsx +49 -23
- package/src/espRouterContext.tsx +88 -0
- package/src/index.ts +32 -16
- package/src/polimer/getEspReactRenderModel.ts +50 -0
- package/src/useModelSelector.ts +94 -0
- package/src/viewBinder.tsx +14 -22
- package/src/viewBinderConnectable.tsx +53 -0
- package/src/viewBindingDecorator.ts +2 -3
- package/tests/connectWithSelectorTests.tsx +67 -0
- package/tests/connectableComponentLegacyTests.tsx +405 -0
- package/tests/indexTests.ts +0 -12
- package/.dist/typings/routerProvider.d.ts +0 -18
- package/.dist/typings/shallowEqual.d.ts +0 -21
- package/.dist/typings/shouldUpdateMixin.d.ts +0 -10
- package/.dist/typings/smartComponent.d.ts +0 -33
- package/.dist/typings/utils.d.ts +0 -5
- package/src/getEspReactRenderModel.ts +0 -27
- package/src/routerProvider.tsx +0 -47
- package/src/shallowEqual.ts +0 -70
- package/src/shouldUpdateMixin.ts +0 -73
- package/src/smartComponent.tsx +0 -93
- package/src/utils.ts +0 -61
- package/tests/connectableComponentTests.tsx +0 -390
package/.dist/esp-react.js
CHANGED
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
2
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory(require("esp-js"), require("esp-js-polimer"), require("
|
|
3
|
+
module.exports = factory(require("esp-js"), require("esp-js-polimer"), require("react"));
|
|
4
4
|
else if(typeof define === 'function' && define.amd)
|
|
5
|
-
define(["esp-js", "esp-js-polimer", "
|
|
5
|
+
define(["esp-js", "esp-js-polimer", "react"], factory);
|
|
6
6
|
else if(typeof exports === 'object')
|
|
7
|
-
exports["esp-js-react"] = factory(require("esp-js"), require("esp-js-polimer"), require("
|
|
7
|
+
exports["esp-js-react"] = factory(require("esp-js"), require("esp-js-polimer"), require("react"));
|
|
8
8
|
else
|
|
9
|
-
root["esp-js-react"] = factory(root["esp-js"], root["esp-js-polimer"], root["
|
|
10
|
-
})(self, (__WEBPACK_EXTERNAL_MODULE__152__, __WEBPACK_EXTERNAL_MODULE__43__,
|
|
9
|
+
root["esp-js-react"] = factory(root["esp-js"], root["esp-js-polimer"], root["react"]);
|
|
10
|
+
})(self, (__WEBPACK_EXTERNAL_MODULE__152__, __WEBPACK_EXTERNAL_MODULE__43__, __WEBPACK_EXTERNAL_MODULE__155__) => {
|
|
11
11
|
return /******/ (() => { // webpackBootstrap
|
|
12
12
|
/******/ "use strict";
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
14
14
|
|
|
15
|
-
/***/
|
|
15
|
+
/***/ 774:
|
|
16
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @license React
|
|
20
|
+
* use-sync-external-store-with-selector.production.min.js
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/
|
|
27
|
+
var g=__webpack_require__(155);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;
|
|
28
|
+
exports.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]);
|
|
29
|
+
t(function(){f.hasValue=!0;f.value=d},[d]);v(d);return d};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/***/ }),
|
|
33
|
+
|
|
34
|
+
/***/ 614:
|
|
35
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if (true) {
|
|
40
|
+
module.exports = __webpack_require__(774);
|
|
41
|
+
} else {}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/***/ }),
|
|
45
|
+
|
|
46
|
+
/***/ 746:
|
|
16
47
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
17
48
|
|
|
18
49
|
|
|
@@ -28,134 +59,92 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
28
59
|
return t;
|
|
29
60
|
};
|
|
30
61
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
31
|
-
exports.connect =
|
|
62
|
+
exports.connect = void 0;
|
|
32
63
|
const React = __webpack_require__(155);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
constructor(props, context) {
|
|
40
|
-
super(props, context);
|
|
41
|
-
this._isMounted = false;
|
|
42
|
-
this._publishEvent = (router, modelId) => (eventType, event) => router.publishEvent(modelId, eventType, event);
|
|
43
|
-
this.state = { model: null, currentModelId: null };
|
|
44
|
-
}
|
|
45
|
-
componentWillReceiveProps(nextProps, nextContext) {
|
|
46
|
-
const modelId = nextProps.modelId || nextContext.modelId;
|
|
47
|
-
const oldModelId = this._getModelId();
|
|
48
|
-
if (modelId === oldModelId) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (nextProps.modelId === oldModelId) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
this._tryObserveModel(modelId);
|
|
55
|
-
}
|
|
56
|
-
componentDidMount() {
|
|
57
|
-
this._isMounted = true;
|
|
58
|
-
this._tryObserveModel(this._getModelId());
|
|
59
|
-
}
|
|
60
|
-
componentWillUnmount() {
|
|
61
|
-
this._isMounted = false;
|
|
62
|
-
this._tryDisposeModelSubscription();
|
|
63
|
-
}
|
|
64
|
-
_getModelId() {
|
|
65
|
-
// props override context
|
|
66
|
-
return this.props.modelId || this.context.modelId;
|
|
67
|
-
}
|
|
68
|
-
_tryObserveModel(modelId) {
|
|
69
|
-
this._tryDisposeModelSubscription();
|
|
70
|
-
if (!modelId) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
let stateChanged = modelId !== this.state.currentModelId;
|
|
74
|
-
let publishEvent = this.state.publishEvent;
|
|
75
|
-
if (stateChanged) {
|
|
76
|
-
publishEvent = this._publishEvent(this.context.router, modelId);
|
|
77
|
-
}
|
|
78
|
-
let publishProps = this.state.publishProps;
|
|
79
|
-
// We only map the publish props once, as for well behaving components these callbacks should never change
|
|
80
|
-
if (stateChanged && this.props.createPublishEventProps) {
|
|
81
|
-
publishProps = this.props.createPublishEventProps(publishEvent);
|
|
82
|
-
}
|
|
83
|
-
if (stateChanged) {
|
|
84
|
-
this.setState({
|
|
85
|
-
currentModelId: modelId,
|
|
86
|
-
publishEvent,
|
|
87
|
-
publishProps
|
|
88
|
-
});
|
|
89
|
-
this._observationSubscription = this.context.router
|
|
90
|
-
.getModelObservable(modelId)
|
|
91
|
-
.subscribe(model => {
|
|
92
|
-
if (this._isMounted) {
|
|
93
|
-
this.setState({ model });
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
_tryDisposeModelSubscription() {
|
|
99
|
-
if (this._observationSubscription) {
|
|
100
|
-
this._observationSubscription.dispose();
|
|
101
|
-
this._observationSubscription = new esp_js_1.DisposableBase();
|
|
102
|
-
this.setState({ model: null, currentModelId: null, publishProps: null, publishEvent: null });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
render() {
|
|
106
|
-
if (this.state.model == null) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
let childProps = this._getChildProps();
|
|
110
|
-
let view = (0, viewBindingDecorator_1.createViewForModel)(this.state.model, childProps, this.props.viewContext, this.props.view);
|
|
111
|
-
return (React.createElement(espModelContext_1.EspModelContext, Object.assign({ modelId: this.props.modelId, router: this.context.router }, childProps), view));
|
|
112
|
-
}
|
|
113
|
-
_getChildProps() {
|
|
114
|
-
// consume what this component owns, and let the rest end up in `...rest`
|
|
115
|
-
const _a = this.props, { children, createPublishEventProps, modelId, mapModelToProps, view, viewContext } = _a, rest = __rest(_a, ["children", "createPublishEventProps", "modelId", "mapModelToProps", "view", "viewContext"]);
|
|
116
|
-
const model = this._getRenderModel(this.state.model);
|
|
117
|
-
let childProps = Object.assign(Object.assign(Object.assign({ modelId, router: this.context.router }, rest), this.state.publishProps), { model });
|
|
118
|
-
if (this.props.mapModelToProps) {
|
|
119
|
-
childProps = Object.assign(Object.assign({}, childProps), this.props.mapModelToProps(model, this.state.publishProps));
|
|
120
|
-
}
|
|
121
|
-
return childProps;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Sees if there is a special selector function which can be invoked to return a render model rather than the top level model model itself
|
|
125
|
-
*/
|
|
126
|
-
_getRenderModel(model) {
|
|
127
|
-
// does the given model have a decorated function we can invoke to get a different model to render?
|
|
128
|
-
if (esp_js_1.EspDecoratorUtil.hasMetadata(model)) {
|
|
129
|
-
let metadata = esp_js_1.EspDecoratorUtil.getCustomData(model, getEspReactRenderModel_1.GetEspReactRenderModelConsts.CustomDataKey);
|
|
130
|
-
if (metadata) {
|
|
131
|
-
return model[metadata.functionName]();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// else see if there is a function with name GetEspReactRenderModelConsts.HandlerFunctionName we can invoke to get a different model to render?
|
|
135
|
-
let renderModelGetter = model[getEspReactRenderModel_1.GetEspReactRenderModelConsts.HandlerFunctionName];
|
|
136
|
-
if (renderModelGetter && esp_js_1.utils.isFunction(renderModelGetter)) {
|
|
137
|
-
return renderModelGetter.call(model);
|
|
138
|
-
}
|
|
139
|
-
// else just return the default model
|
|
140
|
-
return model;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.ConnectableComponent = ConnectableComponent;
|
|
144
|
-
ConnectableComponent.contextTypes = {
|
|
145
|
-
router: PropTypes.instanceOf(esp_js_1.Router).isRequired,
|
|
146
|
-
modelId: PropTypes.string
|
|
147
|
-
};
|
|
64
|
+
const connectableComponent_1 = __webpack_require__(397);
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated
|
|
67
|
+
* @param mapModelToProps
|
|
68
|
+
* @param createPublishEventProps
|
|
69
|
+
*/
|
|
148
70
|
const connect = function (mapModelToProps, createPublishEventProps) {
|
|
149
71
|
return function (view) {
|
|
150
72
|
return function (props) {
|
|
151
73
|
const { modelId, viewContext } = props, rest = __rest(props, ["modelId", "viewContext"]);
|
|
152
|
-
return React.createElement(ConnectableComponent, Object.assign({ modelId: modelId, view: view, viewContext: viewContext, createPublishEventProps: createPublishEventProps, mapModelToProps: mapModelToProps }, rest));
|
|
74
|
+
return React.createElement(connectableComponent_1.ConnectableComponent, Object.assign({ modelId: modelId, view: view, viewContext: viewContext, createPublishEventProps: createPublishEventProps, mapModelToProps: mapModelToProps }, rest));
|
|
153
75
|
};
|
|
154
76
|
};
|
|
155
77
|
};
|
|
156
78
|
exports.connect = connect;
|
|
157
79
|
|
|
158
80
|
|
|
81
|
+
/***/ }),
|
|
82
|
+
|
|
83
|
+
/***/ 397:
|
|
84
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
88
|
+
var t = {};
|
|
89
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
90
|
+
t[p] = s[p];
|
|
91
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
92
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
93
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
94
|
+
t[p[i]] = s[p[i]];
|
|
95
|
+
}
|
|
96
|
+
return t;
|
|
97
|
+
};
|
|
98
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
99
|
+
exports.ConnectableComponent = void 0;
|
|
100
|
+
const React = __webpack_require__(155);
|
|
101
|
+
const espRouterContext_1 = __webpack_require__(46);
|
|
102
|
+
const react_1 = __webpack_require__(155);
|
|
103
|
+
const esp_js_1 = __webpack_require__(152);
|
|
104
|
+
const espModelContext_1 = __webpack_require__(680);
|
|
105
|
+
const viewBindingDecorator_1 = __webpack_require__(213);
|
|
106
|
+
const getEspReactRenderModel_1 = __webpack_require__(621);
|
|
107
|
+
const useModelSelector_1 = __webpack_require__(743);
|
|
108
|
+
const getChildProps = (router, modelId, restProps, initialModel, mapModelToProps, publishEventProps) => {
|
|
109
|
+
// consume what this component owns, and let the rest end up in `...rest`
|
|
110
|
+
const model = (0, getEspReactRenderModel_1.tryGetRenderModel)(initialModel);
|
|
111
|
+
let childProps = Object.assign(Object.assign(Object.assign({ modelId, router: router }, restProps), publishEventProps), { model });
|
|
112
|
+
if (mapModelToProps) {
|
|
113
|
+
childProps = Object.assign(Object.assign({}, childProps), mapModelToProps(model, publishEventProps));
|
|
114
|
+
}
|
|
115
|
+
return childProps;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated - use ViewBinderConnectable and ESP hooks if you need to dynamically bind a view to a model
|
|
119
|
+
* or useModelSelector with other ESP hooks for direct model subscription.
|
|
120
|
+
*/
|
|
121
|
+
const ConnectableComponent = (_a) => {
|
|
122
|
+
var { modelId, mapModelToProps, createPublishEventProps, view, viewContext } = _a, rest = __rest(_a, ["modelId", "mapModelToProps", "createPublishEventProps", "view", "viewContext"]);
|
|
123
|
+
const router = (0, espRouterContext_1.useRouter)();
|
|
124
|
+
modelId = modelId || (0, espModelContext_1.useGetModelId)();
|
|
125
|
+
if (esp_js_1.utils.stringIsEmpty(modelId) || !router) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const publishEventProps = (0, react_1.useMemo)(() => {
|
|
129
|
+
if (createPublishEventProps) {
|
|
130
|
+
const publishModelEvent = (eventType, event) => {
|
|
131
|
+
router.publishEvent(modelId, eventType, event);
|
|
132
|
+
};
|
|
133
|
+
return createPublishEventProps(publishModelEvent);
|
|
134
|
+
}
|
|
135
|
+
return {};
|
|
136
|
+
}, [router, modelId]);
|
|
137
|
+
const model = (0, useModelSelector_1.useModelSelector)(m => m, modelId, false);
|
|
138
|
+
if (model == null) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
let childProps = getChildProps(router, modelId, rest, model, mapModelToProps, publishEventProps);
|
|
142
|
+
let viewElement = (0, viewBindingDecorator_1.createViewForModel)(model, childProps, viewContext, view);
|
|
143
|
+
return (React.createElement(espModelContext_1.EspModelContext, Object.assign({ modelId: modelId, model: model, router: router }, childProps), viewElement));
|
|
144
|
+
};
|
|
145
|
+
exports.ConnectableComponent = ConnectableComponent;
|
|
146
|
+
|
|
147
|
+
|
|
159
148
|
/***/ }),
|
|
160
149
|
|
|
161
150
|
/***/ 680:
|
|
@@ -163,23 +152,24 @@ exports.connect = connect;
|
|
|
163
152
|
|
|
164
153
|
|
|
165
154
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
166
|
-
exports.EspModelContext = exports.usePublishModelEventWithEntityKey = exports.PublishModelEventWithEntityKeyContext = exports.usePublishModelEvent = exports.PublishModelEventContext = exports.
|
|
155
|
+
exports.EspModelContext = exports.usePublishModelEventWithEntityKey = exports.PublishModelEventWithEntityKeyContext = exports.usePublishModelEvent = exports.PublishModelEventContext = exports.useGetModel = exports.GetModelContext = exports.useGetModelId = exports.GetModelIdContext = void 0;
|
|
167
156
|
const React = __webpack_require__(155);
|
|
168
157
|
const esp_js_1 = __webpack_require__(152);
|
|
169
158
|
const react_1 = __webpack_require__(155);
|
|
170
|
-
const
|
|
159
|
+
const espRouterContext_1 = __webpack_require__(46);
|
|
160
|
+
const _log = esp_js_1.Logger.create('EspModelContext');
|
|
171
161
|
exports.GetModelIdContext = (0, react_1.createContext)(null);
|
|
172
162
|
/**
|
|
173
163
|
* Returns a function which will return the ID of the model currently being rendered.
|
|
174
164
|
*/
|
|
175
|
-
const useGetModelId = () => (0, react_1.useContext)(exports.GetModelIdContext);
|
|
165
|
+
const useGetModelId = () => (0, react_1.useContext)(exports.GetModelIdContext)();
|
|
176
166
|
exports.useGetModelId = useGetModelId;
|
|
177
|
-
exports.
|
|
167
|
+
exports.GetModelContext = (0, react_1.createContext)(null);
|
|
178
168
|
/**
|
|
179
|
-
* Returns a function which
|
|
169
|
+
* Returns a function which will return the model set at last dispatch.
|
|
180
170
|
*/
|
|
181
|
-
const
|
|
182
|
-
exports.
|
|
171
|
+
const useGetModel = () => (0, react_1.useContext)(exports.GetModelContext)();
|
|
172
|
+
exports.useGetModel = useGetModel;
|
|
183
173
|
exports.PublishModelEventContext = (0, react_1.createContext)(null);
|
|
184
174
|
/**
|
|
185
175
|
* Returns a function which can be used to publish an event to the current model being rendered.
|
|
@@ -196,36 +186,137 @@ exports.PublishModelEventWithEntityKeyContext = (0, react_1.createContext)(null)
|
|
|
196
186
|
*/
|
|
197
187
|
const usePublishModelEventWithEntityKey = () => (0, react_1.useContext)(exports.PublishModelEventWithEntityKeyContext);
|
|
198
188
|
exports.usePublishModelEventWithEntityKey = usePublishModelEventWithEntityKey;
|
|
199
|
-
const EspModelContext = ({ modelId, children,
|
|
189
|
+
const EspModelContext = ({ modelId, children, model }) => {
|
|
190
|
+
const router = (0, espRouterContext_1.useRouter)();
|
|
200
191
|
const getModelId = (0, react_1.useCallback)(() => {
|
|
201
192
|
return modelId;
|
|
202
193
|
}, [router, modelId]);
|
|
203
|
-
const
|
|
204
|
-
router
|
|
205
|
-
|
|
194
|
+
const getModel = (0, react_1.useCallback)(() => {
|
|
195
|
+
warnIfModelAccessedOutSideDispatchLoop(router, modelId);
|
|
196
|
+
return model;
|
|
197
|
+
}, [model, router, modelId]);
|
|
206
198
|
const publishModelEvent = (0, react_1.useCallback)((eventType, event) => {
|
|
207
199
|
router.publishEvent(modelId, eventType, event);
|
|
208
200
|
}, [router, modelId]);
|
|
209
201
|
const publishModelEventWithEntityKey = (0, react_1.useCallback)((entityKey, eventType, event) => {
|
|
210
202
|
router.publishEvent(new esp_js_1.DefaultModelAddress(modelId, entityKey), eventType, event);
|
|
211
203
|
}, [router, modelId]);
|
|
212
|
-
return (React.createElement(
|
|
213
|
-
React.createElement(exports.
|
|
214
|
-
React.createElement(exports.
|
|
215
|
-
React.createElement(exports.
|
|
216
|
-
React.createElement(exports.PublishModelEventWithEntityKeyContext.Provider, { value: publishModelEventWithEntityKey }, children))))));
|
|
204
|
+
return (React.createElement(exports.GetModelIdContext.Provider, { value: getModelId },
|
|
205
|
+
React.createElement(exports.PublishModelEventContext.Provider, { value: publishModelEvent },
|
|
206
|
+
React.createElement(exports.PublishModelEventWithEntityKeyContext.Provider, { value: publishModelEventWithEntityKey },
|
|
207
|
+
React.createElement(exports.GetModelContext.Provider, { value: getModel }, children)))));
|
|
217
208
|
};
|
|
218
209
|
exports.EspModelContext = EspModelContext;
|
|
210
|
+
const warnIfModelAccessedOutSideDispatchLoop = (router, modelId) => {
|
|
211
|
+
if (true) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (esp_js_1.utils.stringIsEmpty(modelId)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
let isDispatchModelUpdateStatus = router.isModelDispatchStatus(modelId, esp_js_1.Status.DispatchModelUpdates);
|
|
218
|
+
if (!isDispatchModelUpdateStatus) {
|
|
219
|
+
let stack = undefined;
|
|
220
|
+
try {
|
|
221
|
+
// noinspection ExceptionCaughtLocallyJS
|
|
222
|
+
throw new Error();
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
stack = e.stack;
|
|
226
|
+
}
|
|
227
|
+
_log.warn(`EspModelContext useGetModelId has been invoked outside of the models (${modelId}) dispatch loop.` +
|
|
228
|
+
`This may have unknown state state issues.` +
|
|
229
|
+
stack);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
219
232
|
|
|
220
233
|
|
|
221
234
|
/***/ }),
|
|
222
235
|
|
|
223
|
-
/***/
|
|
236
|
+
/***/ 46:
|
|
224
237
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
225
238
|
|
|
226
239
|
|
|
240
|
+
// notice_start
|
|
241
|
+
/*
|
|
242
|
+
* Copyright 2015 Dev Shop Limited
|
|
243
|
+
*
|
|
244
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
245
|
+
* you may not use this file except in compliance with the License.
|
|
246
|
+
* You may obtain a copy of the License at
|
|
247
|
+
*
|
|
248
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
249
|
+
*
|
|
250
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
251
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
252
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
253
|
+
* See the License for the specific language governing permissions and
|
|
254
|
+
* limitations under the License.
|
|
255
|
+
*/
|
|
256
|
+
// notice_end
|
|
227
257
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
228
|
-
exports.
|
|
258
|
+
exports.RouterProvider = exports.EspRouterContext = exports.usePublishEvent = exports.PublishEventContext = exports.useRouter = exports.RouterContext = void 0;
|
|
259
|
+
const React = __webpack_require__(155);
|
|
260
|
+
const react_1 = __webpack_require__(155);
|
|
261
|
+
exports.RouterContext = (0, react_1.createContext)(null);
|
|
262
|
+
/**
|
|
263
|
+
* Get the esp Router from the RouterContext
|
|
264
|
+
*
|
|
265
|
+
* To use this, please ensure your V-DOM has the EspRouterContext at a higher node:
|
|
266
|
+
*
|
|
267
|
+
* <EspRouterContext router={router}>
|
|
268
|
+
* <YourComponents />
|
|
269
|
+
* </EspRouterContext>
|
|
270
|
+
*/
|
|
271
|
+
const useRouter = () => {
|
|
272
|
+
const context = (0, react_1.useContext)(exports.RouterContext);
|
|
273
|
+
if (context === undefined) {
|
|
274
|
+
throw new Error('useRouter must be used within a RouterContext.Provider');
|
|
275
|
+
}
|
|
276
|
+
return context;
|
|
277
|
+
};
|
|
278
|
+
exports.useRouter = useRouter;
|
|
279
|
+
exports.PublishEventContext = (0, react_1.createContext)(null);
|
|
280
|
+
/**
|
|
281
|
+
* Returns a function which can be used to publish an event.
|
|
282
|
+
*
|
|
283
|
+
* To use this, please ensure your V-DOM has the EspRouterContext at a higher node:
|
|
284
|
+
*
|
|
285
|
+
* <EspRouterContext router={router}>
|
|
286
|
+
* <YourComponents />
|
|
287
|
+
* </EspRouterContext>
|
|
288
|
+
*/
|
|
289
|
+
const usePublishEvent = () => (0, react_1.useContext)(exports.PublishEventContext);
|
|
290
|
+
exports.usePublishEvent = usePublishEvent;
|
|
291
|
+
/**
|
|
292
|
+
* Used to set the router on the RouterContext making it available to components down the tree via the useRouter() hook.
|
|
293
|
+
*
|
|
294
|
+
* Also sets up the usePublishEvent() hook so nested components can publish to the router.
|
|
295
|
+
*/
|
|
296
|
+
const EspRouterContext = ({ children, router }) => {
|
|
297
|
+
const publishEvent = (0, react_1.useCallback)((modelIdOrModelAddress, eventType, event) => {
|
|
298
|
+
router.publishEvent(modelIdOrModelAddress, eventType, event);
|
|
299
|
+
}, [router]);
|
|
300
|
+
return (React.createElement(exports.RouterContext.Provider, { value: router },
|
|
301
|
+
React.createElement(exports.PublishEventContext.Provider, { value: publishEvent }, children)));
|
|
302
|
+
};
|
|
303
|
+
exports.EspRouterContext = EspRouterContext;
|
|
304
|
+
/**
|
|
305
|
+
* Used to set the router on the RouterContext making it available to components down the tree (via useRouter()).
|
|
306
|
+
*
|
|
307
|
+
* @deprecated use EspRouterContext
|
|
308
|
+
*/
|
|
309
|
+
exports.RouterProvider = exports.EspRouterContext;
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
/***/ }),
|
|
313
|
+
|
|
314
|
+
/***/ 621:
|
|
315
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
319
|
+
exports.tryGetRenderModel = exports.GetEspReactRenderModelConsts = void 0;
|
|
229
320
|
exports.getEspReactRenderModel = getEspReactRenderModel;
|
|
230
321
|
const esp_js_1 = __webpack_require__(152);
|
|
231
322
|
var GetEspReactRenderModelConsts;
|
|
@@ -246,79 +337,29 @@ function getEspReactRenderModel() {
|
|
|
246
337
|
return descriptor;
|
|
247
338
|
};
|
|
248
339
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/***/ }),
|
|
252
|
-
|
|
253
|
-
/***/ 872:
|
|
254
|
-
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// notice_start
|
|
258
|
-
/*
|
|
259
|
-
* Copyright 2015 Dev Shop Limited
|
|
260
|
-
*
|
|
261
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
262
|
-
* you may not use this file except in compliance with the License.
|
|
263
|
-
* You may obtain a copy of the License at
|
|
340
|
+
/**
|
|
341
|
+
* Returns the model which will be used to pluck state/props for the current view.
|
|
264
342
|
*
|
|
265
|
-
*
|
|
343
|
+
* This is basically a hook (not a React 'hook') to call a function on `model` and get a new sub graph to use as state.
|
|
266
344
|
*
|
|
267
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
268
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
269
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
270
|
-
* See the License for the specific language governing permissions and
|
|
271
|
-
* limitations under the License.
|
|
272
345
|
*/
|
|
273
|
-
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
346
|
+
const tryGetRenderModel = (model) => {
|
|
347
|
+
// does the given model have a decorated function we can invoke to get a different model to render?
|
|
348
|
+
if (esp_js_1.EspDecoratorUtil.hasMetadata(model)) {
|
|
349
|
+
let metadata = esp_js_1.EspDecoratorUtil.getCustomData(model, GetEspReactRenderModelConsts.CustomDataKey);
|
|
350
|
+
if (metadata) {
|
|
351
|
+
return model[metadata.functionName]();
|
|
352
|
+
}
|
|
280
353
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
354
|
+
// else see if there is a function with name GetEspReactRenderModelConsts.HandlerFunctionName we can invoke to get a different model to render?
|
|
355
|
+
let renderModelGetter = model[GetEspReactRenderModelConsts.HandlerFunctionName];
|
|
356
|
+
if (renderModelGetter && esp_js_1.utils.isFunction(renderModelGetter)) {
|
|
357
|
+
return renderModelGetter.call(model);
|
|
358
|
+
}
|
|
359
|
+
// else return the initial model passed in
|
|
360
|
+
return model;
|
|
288
361
|
};
|
|
289
|
-
|
|
290
|
-
exports.EspModelContext = exports.usePublishModelEventWithEntityKey = exports.PublishModelEventWithEntityKeyContext = exports.usePublishModelEvent = exports.PublishModelEventContext = exports.usePublishEvent = exports.PublishEventContext = exports.GetModelIdContext = exports.useGetModelId = exports.connect = exports.ConnectableComponent = exports.createViewForModel = exports.shouldUpdateMixin = exports.DEFAULT_VIEW_KEY = exports.viewBinding = exports.ViewBinder = exports.SmartComponent = exports.useRouter = exports.RouterContext = exports.RouterProvider = void 0;
|
|
291
|
-
// import for side effects
|
|
292
|
-
__webpack_require__(637);
|
|
293
|
-
var routerProvider_1 = __webpack_require__(182);
|
|
294
|
-
Object.defineProperty(exports, "RouterProvider", ({ enumerable: true, get: function () { return routerProvider_1.RouterProvider; } }));
|
|
295
|
-
Object.defineProperty(exports, "RouterContext", ({ enumerable: true, get: function () { return routerProvider_1.RouterContext; } }));
|
|
296
|
-
Object.defineProperty(exports, "useRouter", ({ enumerable: true, get: function () { return routerProvider_1.useRouter; } }));
|
|
297
|
-
var smartComponent_1 = __webpack_require__(438);
|
|
298
|
-
Object.defineProperty(exports, "SmartComponent", ({ enumerable: true, get: function () { return smartComponent_1.SmartComponent; } }));
|
|
299
|
-
var viewBinder_1 = __webpack_require__(453);
|
|
300
|
-
Object.defineProperty(exports, "ViewBinder", ({ enumerable: true, get: function () { return viewBinder_1.ViewBinder; } }));
|
|
301
|
-
var viewBindingDecorator_1 = __webpack_require__(213);
|
|
302
|
-
Object.defineProperty(exports, "viewBinding", ({ enumerable: true, get: function () { return viewBindingDecorator_1.viewBinding; } }));
|
|
303
|
-
Object.defineProperty(exports, "DEFAULT_VIEW_KEY", ({ enumerable: true, get: function () { return viewBindingDecorator_1.DEFAULT_VIEW_KEY; } }));
|
|
304
|
-
__exportStar(__webpack_require__(102), exports);
|
|
305
|
-
var shouldUpdateMixin_1 = __webpack_require__(79);
|
|
306
|
-
Object.defineProperty(exports, "shouldUpdateMixin", ({ enumerable: true, get: function () { return shouldUpdateMixin_1.shouldUpdateMixin; } }));
|
|
307
|
-
var viewBindingDecorator_2 = __webpack_require__(213);
|
|
308
|
-
Object.defineProperty(exports, "createViewForModel", ({ enumerable: true, get: function () { return viewBindingDecorator_2.createViewForModel; } }));
|
|
309
|
-
var connectableComponent_1 = __webpack_require__(397);
|
|
310
|
-
Object.defineProperty(exports, "ConnectableComponent", ({ enumerable: true, get: function () { return connectableComponent_1.ConnectableComponent; } }));
|
|
311
|
-
Object.defineProperty(exports, "connect", ({ enumerable: true, get: function () { return connectableComponent_1.connect; } }));
|
|
312
|
-
var espModelContext_1 = __webpack_require__(680);
|
|
313
|
-
Object.defineProperty(exports, "useGetModelId", ({ enumerable: true, get: function () { return espModelContext_1.useGetModelId; } }));
|
|
314
|
-
Object.defineProperty(exports, "GetModelIdContext", ({ enumerable: true, get: function () { return espModelContext_1.GetModelIdContext; } }));
|
|
315
|
-
Object.defineProperty(exports, "PublishEventContext", ({ enumerable: true, get: function () { return espModelContext_1.PublishEventContext; } }));
|
|
316
|
-
Object.defineProperty(exports, "usePublishEvent", ({ enumerable: true, get: function () { return espModelContext_1.usePublishEvent; } }));
|
|
317
|
-
Object.defineProperty(exports, "PublishModelEventContext", ({ enumerable: true, get: function () { return espModelContext_1.PublishModelEventContext; } }));
|
|
318
|
-
Object.defineProperty(exports, "usePublishModelEvent", ({ enumerable: true, get: function () { return espModelContext_1.usePublishModelEvent; } }));
|
|
319
|
-
Object.defineProperty(exports, "PublishModelEventWithEntityKeyContext", ({ enumerable: true, get: function () { return espModelContext_1.PublishModelEventWithEntityKeyContext; } }));
|
|
320
|
-
Object.defineProperty(exports, "usePublishModelEventWithEntityKey", ({ enumerable: true, get: function () { return espModelContext_1.usePublishModelEventWithEntityKey; } }));
|
|
321
|
-
Object.defineProperty(exports, "EspModelContext", ({ enumerable: true, get: function () { return espModelContext_1.EspModelContext; } }));
|
|
362
|
+
exports.tryGetRenderModel = tryGetRenderModel;
|
|
322
363
|
|
|
323
364
|
|
|
324
365
|
/***/ }),
|
|
@@ -356,202 +397,92 @@ esp_js_polimer_1.PolimerModelBuilder.prototype.registerWithRouter = function ()
|
|
|
356
397
|
|
|
357
398
|
/***/ }),
|
|
358
399
|
|
|
359
|
-
/***/
|
|
400
|
+
/***/ 743:
|
|
360
401
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
361
402
|
|
|
362
403
|
|
|
363
|
-
// notice_start
|
|
364
|
-
/*
|
|
365
|
-
* Copyright 2015 Dev Shop Limited
|
|
366
|
-
*
|
|
367
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
368
|
-
* you may not use this file except in compliance with the License.
|
|
369
|
-
* You may obtain a copy of the License at
|
|
370
|
-
*
|
|
371
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
372
|
-
*
|
|
373
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
374
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
375
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
376
|
-
* See the License for the specific language governing permissions and
|
|
377
|
-
* limitations under the License.
|
|
378
|
-
*/
|
|
379
|
-
// notice_end
|
|
380
404
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
381
|
-
exports.
|
|
382
|
-
const React = __webpack_require__(155);
|
|
383
|
-
const PropTypes = __webpack_require__(949);
|
|
384
|
-
const esp_js_1 = __webpack_require__(152);
|
|
405
|
+
exports.useModelSelector = exports.defaultConnectEqualityFn = void 0;
|
|
385
406
|
const react_1 = __webpack_require__(155);
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
render() {
|
|
396
|
-
return (React.createElement(exports.RouterContext.Provider, { value: this.props.router }, this.props.children));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
exports.RouterProvider = RouterProvider;
|
|
400
|
-
RouterProvider.childContextTypes = {
|
|
401
|
-
router: PropTypes.instanceOf(esp_js_1.Router).isRequired
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/***/ }),
|
|
406
|
-
|
|
407
|
-
/***/ 234:
|
|
408
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
409
|
-
|
|
410
|
-
// taken from fbjs:
|
|
411
|
-
// https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js
|
|
412
|
-
// Licence (MIT) https://github.com/facebook/fbjs/blob/master/packages/fbjs/LICENSE
|
|
413
|
-
/**
|
|
414
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
415
|
-
*
|
|
416
|
-
* This source code is licensed under the MIT license found in the
|
|
417
|
-
* LICENSE file in the root directory of this source tree.
|
|
418
|
-
*
|
|
419
|
-
* @providesModule shallowEqual
|
|
420
|
-
* @typechecks
|
|
421
|
-
* @flow
|
|
422
|
-
*/
|
|
423
|
-
/*eslint-disable no-self-compare */
|
|
424
|
-
|
|
425
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
426
|
-
exports.is = is;
|
|
427
|
-
exports.shallowEqual = shallowEqual;
|
|
428
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
429
|
-
/**
|
|
430
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
431
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
432
|
-
*/
|
|
433
|
-
function is(x, y) {
|
|
434
|
-
// SameValue algorithm
|
|
435
|
-
if (x === y) { // Steps 1-5, 7-10
|
|
436
|
-
// Steps 6.b-6.e: +0 != -0
|
|
437
|
-
// Added the nonzero y check to make Flow happy, but it is redundant
|
|
438
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
// Step 6.a: NaN == NaN
|
|
442
|
-
return x !== x && y !== y;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
407
|
+
const with_selector_1 = __webpack_require__(614);
|
|
408
|
+
const esp_js_1 = __webpack_require__(152);
|
|
409
|
+
const espRouterContext_1 = __webpack_require__(46);
|
|
410
|
+
const espModelContext_1 = __webpack_require__(680);
|
|
411
|
+
const getEspReactRenderModel_1 = __webpack_require__(621);
|
|
412
|
+
const defaultConnectEqualityFn = (a, b) => a === b; // reference equality
|
|
413
|
+
exports.defaultConnectEqualityFn = defaultConnectEqualityFn;
|
|
445
414
|
/**
|
|
446
|
-
*
|
|
447
|
-
* when any key has values which are not strictly equal between the arguments.
|
|
448
|
-
* Returns true when the values of all keys are strictly equal.
|
|
449
|
-
*/
|
|
450
|
-
function shallowEqual(objA, objB) {
|
|
451
|
-
if (is(objA, objB)) {
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
if (typeof objA !== 'object' || objA === null ||
|
|
455
|
-
typeof objB !== 'object' || objB === null) {
|
|
456
|
-
return false;
|
|
457
|
-
}
|
|
458
|
-
const keysA = Object.keys(objA);
|
|
459
|
-
const keysB = Object.keys(objB);
|
|
460
|
-
if (keysA.length !== keysB.length) {
|
|
461
|
-
return false;
|
|
462
|
-
}
|
|
463
|
-
// Test for A's keys different from B.
|
|
464
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
465
|
-
if (!hasOwnProperty.call(objB, keysA[i]) ||
|
|
466
|
-
!is(objA[keysA[i]], objB[keysA[i]])) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
return true;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
/***/ }),
|
|
475
|
-
|
|
476
|
-
/***/ 79:
|
|
477
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
// notice_start
|
|
481
|
-
/*
|
|
482
|
-
* Copyright 2018 Keith Woods
|
|
483
|
-
*
|
|
484
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
485
|
-
* you may not use this file except in compliance with the License.
|
|
486
|
-
* You may obtain a copy of the License at
|
|
415
|
+
* A hook which returns model state from the esp Router.
|
|
487
416
|
*
|
|
488
|
-
*
|
|
417
|
+
* This hooks wih observe updates and re-render the component if the model changes.
|
|
489
418
|
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* limitations under the License.
|
|
419
|
+
* @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.
|
|
420
|
+
* @param modelId - the modelId of the model to be observed via the esp Router.
|
|
421
|
+
* @param tryPreSelectPolimerImmutableModel - if true, and the esp model is an esp-js-polimer model, the immutable model will be used when calling the selector.
|
|
422
|
+
* @param equalityFn - Equality function which will be applied against TSelected, defaults to instance equality (a === b).
|
|
495
423
|
*/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const
|
|
501
|
-
//
|
|
502
|
-
//
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
//
|
|
517
|
-
//
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
render
|
|
529
|
-
|
|
424
|
+
const useModelSelector = (selector, modelId, tryPreSelectPolimerImmutableModel = true, equalityFn = exports.defaultConnectEqualityFn) => {
|
|
425
|
+
esp_js_1.Guard.isFunction(selector, 'You must pass a selector function to connectSelector');
|
|
426
|
+
const router = (0, espRouterContext_1.useRouter)();
|
|
427
|
+
modelId = modelId || (0, espModelContext_1.useGetModelId)();
|
|
428
|
+
const dependencies = (0, react_1.useMemo)(() => {
|
|
429
|
+
// Because of how useSyncExternalStore works, there is an implicit dependency between the subscribe and getSnapshot functions.
|
|
430
|
+
// 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.
|
|
431
|
+
// Given that, we need to cache the state which getSnapshot will return.
|
|
432
|
+
//
|
|
433
|
+
// It's not ideal but shouldn't be a problem as here we've wrapped all these dependent functions inside a single useMemo()
|
|
434
|
+
let model = null;
|
|
435
|
+
return {
|
|
436
|
+
subscribe: (stateChanged) => {
|
|
437
|
+
const modelSubscriptionDisposable = router
|
|
438
|
+
.getModelObservable(modelId)
|
|
439
|
+
.subscribe((m) => {
|
|
440
|
+
// try and get a submodel to render
|
|
441
|
+
const nextModel = tryPreSelectPolimerImmutableModel
|
|
442
|
+
? (0, getEspReactRenderModel_1.tryGetRenderModel)(m)
|
|
443
|
+
: m;
|
|
444
|
+
// if the above didn't manage to get a submodel,
|
|
445
|
+
// we need to mutate to force useSyncExternalStoreWithSelector to pick up the change
|
|
446
|
+
model = nextModel === m
|
|
447
|
+
? Object.create(nextModel)
|
|
448
|
+
: nextModel;
|
|
449
|
+
stateChanged();
|
|
450
|
+
});
|
|
451
|
+
return () => {
|
|
452
|
+
model = null;
|
|
453
|
+
modelSubscriptionDisposable.dispose();
|
|
454
|
+
};
|
|
455
|
+
},
|
|
456
|
+
// React expects getSnapshot to be immutable, it'll only re-render if the instance changes
|
|
457
|
+
getSnapshot: () => {
|
|
458
|
+
return model;
|
|
459
|
+
},
|
|
460
|
+
// While getSnapshot needs to model to be immutable,
|
|
461
|
+
// TODO confirm this comment with a test:
|
|
462
|
+
// useSyncExternalStoreWithSelector builds on top of this so the TSelected can defer to an equality check to determine if the change is propagated.
|
|
463
|
+
// The selector here just maps the TSelected, useSyncExternalStoreWithSelector internally does the equality check.
|
|
464
|
+
wrappedSelector: (snapshot) => {
|
|
465
|
+
// The first time this renders, react calls getSnapshot and the selector before the router has pushed a change.
|
|
466
|
+
// In that case, there is no state for any component to process, therefore, we return null;
|
|
467
|
+
return snapshot
|
|
468
|
+
? selector(snapshot)
|
|
469
|
+
: null;
|
|
530
470
|
}
|
|
531
471
|
};
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
//
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
// this._propBindings = newBindings;
|
|
542
|
-
// return !bindingsAreEqual;
|
|
543
|
-
// }
|
|
544
|
-
// render() {
|
|
545
|
-
// return React.createElement(Comp, this.props);
|
|
546
|
-
// }
|
|
547
|
-
// };
|
|
548
|
-
// };
|
|
549
|
-
// }
|
|
472
|
+
},
|
|
473
|
+
// Don't cache check against 'selector' argument as that will likely change unless the caller memoizes it.
|
|
474
|
+
[router, modelId]);
|
|
475
|
+
// Docs on useSyncExternalStore https://github.com/reactwg/react-18/discussions/86
|
|
476
|
+
// Redux's usage of this: https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.ts
|
|
477
|
+
// Code: https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js
|
|
478
|
+
return (0, with_selector_1.useSyncExternalStoreWithSelector)(dependencies.subscribe, dependencies.getSnapshot, undefined, dependencies.wrappedSelector, equalityFn);
|
|
479
|
+
};
|
|
480
|
+
exports.useModelSelector = useModelSelector;
|
|
550
481
|
|
|
551
482
|
|
|
552
483
|
/***/ }),
|
|
553
484
|
|
|
554
|
-
/***/
|
|
485
|
+
/***/ 453:
|
|
555
486
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
556
487
|
|
|
557
488
|
|
|
@@ -584,128 +515,61 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
584
515
|
return t;
|
|
585
516
|
};
|
|
586
517
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
587
|
-
exports.
|
|
588
|
-
const React = __webpack_require__(155);
|
|
589
|
-
const PropTypes = __webpack_require__(949);
|
|
518
|
+
exports.ViewBinder = void 0;
|
|
590
519
|
const viewBindingDecorator_1 = __webpack_require__(213);
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
componentWillReceiveProps(nextProps) {
|
|
599
|
-
this._tryObserveModel(nextProps.modelId);
|
|
600
|
-
}
|
|
601
|
-
componentWillMount() {
|
|
602
|
-
this._tryObserveModel(this.props.modelId);
|
|
603
|
-
}
|
|
604
|
-
componentWillUnmount() {
|
|
605
|
-
this._tryDisposeObservationSubscription();
|
|
606
|
-
}
|
|
607
|
-
_tryObserveModel(modelId) {
|
|
608
|
-
if (!modelId) {
|
|
609
|
-
this._tryDisposeObservationSubscription();
|
|
610
|
-
this.setState({ model: null });
|
|
611
|
-
}
|
|
612
|
-
else if (modelId !== this._currentObservingModelId) {
|
|
613
|
-
this._tryDisposeObservationSubscription();
|
|
614
|
-
this._currentObservingModelId = modelId;
|
|
615
|
-
this._observationSubscription = this.context.router
|
|
616
|
-
.getModelObservable(modelId)
|
|
617
|
-
.map(model => {
|
|
618
|
-
return this.props.modelSelector
|
|
619
|
-
? this.props.modelSelector(model)
|
|
620
|
-
: model;
|
|
621
|
-
})
|
|
622
|
-
.subscribe(model => {
|
|
623
|
-
this.setState({ model: model });
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
_tryDisposeObservationSubscription() {
|
|
628
|
-
this._currentObservingModelId = null;
|
|
629
|
-
if (this._observationSubscription) {
|
|
630
|
-
this._observationSubscription.dispose();
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
render() {
|
|
634
|
-
if (this.state.model) {
|
|
635
|
-
return (0, viewBindingDecorator_1.createViewForModel)(this.state.model, this._getChildProps(), this.props.viewContext, this.props.view);
|
|
636
|
-
}
|
|
637
|
-
return null; // this (in react 15) will render a 'comment node' rather than any actual html
|
|
638
|
-
}
|
|
639
|
-
_getChildProps() {
|
|
640
|
-
// 'consume' the props we own, pass the rest down
|
|
641
|
-
let _a = this.props, { modelId, viewContext, view, modelSelector } = _a, other = __rest(_a, ["modelId", "viewContext", "view", "modelSelector"]);
|
|
642
|
-
let newProps = {
|
|
643
|
-
model: this.state.model,
|
|
644
|
-
router: this.context.router
|
|
645
|
-
};
|
|
646
|
-
return Object.assign({}, newProps, other);
|
|
520
|
+
const espRouterContext_1 = __webpack_require__(46);
|
|
521
|
+
const ViewBinder = (_a) => {
|
|
522
|
+
var { model, viewContext } = _a, rest = __rest(_a, ["model", "viewContext"]);
|
|
523
|
+
if (model) {
|
|
524
|
+
const router = (0, espRouterContext_1.useRouter)();
|
|
525
|
+
const newProps = Object.assign({}, { model, router }, rest);
|
|
526
|
+
return (0, viewBindingDecorator_1.createViewForModel)(model, newProps, viewContext, null);
|
|
647
527
|
}
|
|
648
|
-
|
|
649
|
-
exports.SmartComponent = SmartComponent;
|
|
650
|
-
SmartComponent.contextTypes = {
|
|
651
|
-
router: PropTypes.instanceOf(esp_js_1.Router).isRequired
|
|
528
|
+
return null;
|
|
652
529
|
};
|
|
530
|
+
exports.ViewBinder = ViewBinder;
|
|
653
531
|
|
|
654
532
|
|
|
655
533
|
/***/ }),
|
|
656
534
|
|
|
657
|
-
/***/
|
|
658
|
-
/***/ (
|
|
535
|
+
/***/ 639:
|
|
536
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
659
537
|
|
|
660
538
|
|
|
661
|
-
// notice_start
|
|
662
|
-
/*
|
|
663
|
-
* Copyright 2015 Dev Shop Limited
|
|
664
|
-
*
|
|
665
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
666
|
-
* you may not use this file except in compliance with the License.
|
|
667
|
-
* You may obtain a copy of the License at
|
|
668
|
-
*
|
|
669
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
670
|
-
*
|
|
671
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
672
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
673
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
674
|
-
* See the License for the specific language governing permissions and
|
|
675
|
-
* limitations under the License.
|
|
676
|
-
*/
|
|
677
|
-
// notice_end
|
|
678
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
679
|
-
var t = {};
|
|
680
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
681
|
-
t[p] = s[p];
|
|
682
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
683
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
684
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
685
|
-
t[p[i]] = s[p[i]];
|
|
686
|
-
}
|
|
687
|
-
return t;
|
|
688
|
-
};
|
|
689
539
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
690
|
-
exports.
|
|
691
|
-
const
|
|
540
|
+
exports.ViewBinderConnectable = void 0;
|
|
541
|
+
const espRouterContext_1 = __webpack_require__(46);
|
|
542
|
+
const espModelContext_1 = __webpack_require__(680);
|
|
543
|
+
const esp_js_1 = __webpack_require__(152);
|
|
692
544
|
const React = __webpack_require__(155);
|
|
693
|
-
const
|
|
545
|
+
const useModelSelector_1 = __webpack_require__(743);
|
|
694
546
|
const viewBindingDecorator_1 = __webpack_require__(213);
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
547
|
+
const getEspReactRenderModel_1 = __webpack_require__(621);
|
|
548
|
+
const _log = esp_js_1.Logger.create('ViewBinderConnectable');
|
|
549
|
+
/**
|
|
550
|
+
* Dynamically binds a view found via @viewBinder(SomeJsXView) to a model managed by the Router.
|
|
551
|
+
* Optionally provide a view override and/or a viewContext
|
|
552
|
+
* @param modelId
|
|
553
|
+
* @param viewContext
|
|
554
|
+
* @param view
|
|
555
|
+
* @constructor
|
|
556
|
+
*/
|
|
557
|
+
const ViewBinderConnectable = ({ modelId, viewContext, view }) => {
|
|
558
|
+
const router = (0, espRouterContext_1.useRouter)();
|
|
559
|
+
const model = (0, useModelSelector_1.useModelSelector)(m => m, modelId, false);
|
|
560
|
+
if (!model) {
|
|
702
561
|
return null;
|
|
703
562
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
563
|
+
let renderModel = (0, getEspReactRenderModel_1.tryGetRenderModel)(model);
|
|
564
|
+
const childProps = {
|
|
565
|
+
modelId,
|
|
566
|
+
router: router,
|
|
567
|
+
model: renderModel
|
|
568
|
+
};
|
|
569
|
+
let viewElement = (0, viewBindingDecorator_1.createViewForModel)(model, childProps, viewContext, view);
|
|
570
|
+
return (React.createElement(espModelContext_1.EspModelContext, Object.assign({ modelId: modelId, router: router, model: renderModel }, childProps), viewElement));
|
|
708
571
|
};
|
|
572
|
+
exports.ViewBinderConnectable = ViewBinderConnectable;
|
|
709
573
|
|
|
710
574
|
|
|
711
575
|
/***/ }),
|
|
@@ -841,13 +705,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__43__;
|
|
|
841
705
|
|
|
842
706
|
/***/ }),
|
|
843
707
|
|
|
844
|
-
/***/ 949:
|
|
845
|
-
/***/ ((module) => {
|
|
846
|
-
|
|
847
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__949__;
|
|
848
|
-
|
|
849
|
-
/***/ }),
|
|
850
|
-
|
|
851
708
|
/***/ 155:
|
|
852
709
|
/***/ ((module) => {
|
|
853
710
|
|
|
@@ -882,12 +739,70 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__155__;
|
|
|
882
739
|
/******/ }
|
|
883
740
|
/******/
|
|
884
741
|
/************************************************************************/
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
742
|
+
var __webpack_exports__ = {};
|
|
743
|
+
// This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
|
|
744
|
+
(() => {
|
|
745
|
+
var exports = __webpack_exports__;
|
|
746
|
+
|
|
747
|
+
// notice_start
|
|
748
|
+
/*
|
|
749
|
+
* Copyright 2015 Dev Shop Limited
|
|
750
|
+
*
|
|
751
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
752
|
+
* you may not use this file except in compliance with the License.
|
|
753
|
+
* You may obtain a copy of the License at
|
|
754
|
+
*
|
|
755
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
756
|
+
*
|
|
757
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
758
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
759
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
760
|
+
* See the License for the specific language governing permissions and
|
|
761
|
+
* limitations under the License.
|
|
762
|
+
*/
|
|
763
|
+
// notice_end
|
|
764
|
+
//
|
|
765
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
766
|
+
exports.EspModelContext = exports.usePublishModelEventWithEntityKey = exports.PublishModelEventWithEntityKeyContext = exports.usePublishModelEvent = exports.PublishModelEventContext = exports.GetModelIdContext = exports.useGetModelId = exports.usePublishEvent = exports.PublishEventContext = exports.useRouter = exports.RouterContext = exports.EspRouterContext = exports.RouterProvider = exports.defaultConnectEqualityFn = exports.useModelSelector = exports.ConnectableComponent = exports.connect = exports.createViewForModel = exports.getEspReactRenderModel = exports.GetEspReactRenderModelConsts = exports.DEFAULT_VIEW_KEY = exports.viewBinding = exports.ViewBinderConnectable = exports.ViewBinder = void 0;
|
|
767
|
+
// import for side effects
|
|
768
|
+
__webpack_require__(637);
|
|
769
|
+
var viewBinder_1 = __webpack_require__(453);
|
|
770
|
+
Object.defineProperty(exports, "ViewBinder", ({ enumerable: true, get: function () { return viewBinder_1.ViewBinder; } }));
|
|
771
|
+
var viewBinderConnectable_1 = __webpack_require__(639);
|
|
772
|
+
Object.defineProperty(exports, "ViewBinderConnectable", ({ enumerable: true, get: function () { return viewBinderConnectable_1.ViewBinderConnectable; } }));
|
|
773
|
+
var viewBindingDecorator_1 = __webpack_require__(213);
|
|
774
|
+
Object.defineProperty(exports, "viewBinding", ({ enumerable: true, get: function () { return viewBindingDecorator_1.viewBinding; } }));
|
|
775
|
+
Object.defineProperty(exports, "DEFAULT_VIEW_KEY", ({ enumerable: true, get: function () { return viewBindingDecorator_1.DEFAULT_VIEW_KEY; } }));
|
|
776
|
+
var getEspReactRenderModel_1 = __webpack_require__(621);
|
|
777
|
+
Object.defineProperty(exports, "GetEspReactRenderModelConsts", ({ enumerable: true, get: function () { return getEspReactRenderModel_1.GetEspReactRenderModelConsts; } }));
|
|
778
|
+
Object.defineProperty(exports, "getEspReactRenderModel", ({ enumerable: true, get: function () { return getEspReactRenderModel_1.getEspReactRenderModel; } }));
|
|
779
|
+
var viewBindingDecorator_2 = __webpack_require__(213);
|
|
780
|
+
Object.defineProperty(exports, "createViewForModel", ({ enumerable: true, get: function () { return viewBindingDecorator_2.createViewForModel; } }));
|
|
781
|
+
var connect_1 = __webpack_require__(746);
|
|
782
|
+
Object.defineProperty(exports, "connect", ({ enumerable: true, get: function () { return connect_1.connect; } }));
|
|
783
|
+
var connectableComponent_1 = __webpack_require__(397);
|
|
784
|
+
Object.defineProperty(exports, "ConnectableComponent", ({ enumerable: true, get: function () { return connectableComponent_1.ConnectableComponent; } }));
|
|
785
|
+
var useModelSelector_1 = __webpack_require__(743);
|
|
786
|
+
Object.defineProperty(exports, "useModelSelector", ({ enumerable: true, get: function () { return useModelSelector_1.useModelSelector; } }));
|
|
787
|
+
Object.defineProperty(exports, "defaultConnectEqualityFn", ({ enumerable: true, get: function () { return useModelSelector_1.defaultConnectEqualityFn; } }));
|
|
788
|
+
var espRouterContext_1 = __webpack_require__(46);
|
|
789
|
+
Object.defineProperty(exports, "RouterProvider", ({ enumerable: true, get: function () { return espRouterContext_1.RouterProvider; } }));
|
|
790
|
+
Object.defineProperty(exports, "EspRouterContext", ({ enumerable: true, get: function () { return espRouterContext_1.EspRouterContext; } }));
|
|
791
|
+
Object.defineProperty(exports, "RouterContext", ({ enumerable: true, get: function () { return espRouterContext_1.RouterContext; } }));
|
|
792
|
+
Object.defineProperty(exports, "useRouter", ({ enumerable: true, get: function () { return espRouterContext_1.useRouter; } }));
|
|
793
|
+
Object.defineProperty(exports, "PublishEventContext", ({ enumerable: true, get: function () { return espRouterContext_1.PublishEventContext; } }));
|
|
794
|
+
Object.defineProperty(exports, "usePublishEvent", ({ enumerable: true, get: function () { return espRouterContext_1.usePublishEvent; } }));
|
|
795
|
+
var espModelContext_1 = __webpack_require__(680);
|
|
796
|
+
Object.defineProperty(exports, "useGetModelId", ({ enumerable: true, get: function () { return espModelContext_1.useGetModelId; } }));
|
|
797
|
+
Object.defineProperty(exports, "GetModelIdContext", ({ enumerable: true, get: function () { return espModelContext_1.GetModelIdContext; } }));
|
|
798
|
+
Object.defineProperty(exports, "PublishModelEventContext", ({ enumerable: true, get: function () { return espModelContext_1.PublishModelEventContext; } }));
|
|
799
|
+
Object.defineProperty(exports, "usePublishModelEvent", ({ enumerable: true, get: function () { return espModelContext_1.usePublishModelEvent; } }));
|
|
800
|
+
Object.defineProperty(exports, "PublishModelEventWithEntityKeyContext", ({ enumerable: true, get: function () { return espModelContext_1.PublishModelEventWithEntityKeyContext; } }));
|
|
801
|
+
Object.defineProperty(exports, "usePublishModelEventWithEntityKey", ({ enumerable: true, get: function () { return espModelContext_1.usePublishModelEventWithEntityKey; } }));
|
|
802
|
+
Object.defineProperty(exports, "EspModelContext", ({ enumerable: true, get: function () { return espModelContext_1.EspModelContext; } }));
|
|
803
|
+
|
|
804
|
+
})();
|
|
805
|
+
|
|
891
806
|
/******/ return __webpack_exports__;
|
|
892
807
|
/******/ })()
|
|
893
808
|
;
|