effectable 0.1.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/LICENSE +21 -0
- package/README.md +157 -0
- package/build/LICENSE +21 -0
- package/build/bootstrap/bootstrap.d.ts +32 -0
- package/build/bootstrap/bootstrap.d.ts.map +1 -0
- package/build/bootstrap/bootstrap.js +179 -0
- package/build/bootstrap/bootstrap.js.map +1 -0
- package/build/bootstrap/index.d.ts +9 -0
- package/build/bootstrap/index.d.ts.map +1 -0
- package/build/bootstrap/index.js +14 -0
- package/build/bootstrap/index.js.map +1 -0
- package/build/bootstrap/types.d.ts +105 -0
- package/build/bootstrap/types.d.ts.map +1 -0
- package/build/bootstrap/types.js +26 -0
- package/build/bootstrap/types.js.map +1 -0
- package/build/component/Component.d.ts +126 -0
- package/build/component/Component.d.ts.map +1 -0
- package/build/component/Component.js +123 -0
- package/build/component/Component.js.map +1 -0
- package/build/component/GraphRuntime.d.ts +457 -0
- package/build/component/GraphRuntime.d.ts.map +1 -0
- package/build/component/GraphRuntime.js +1168 -0
- package/build/component/GraphRuntime.js.map +1 -0
- package/build/component/constants.d.ts +1 -0
- package/build/component/constants.d.ts.map +1 -0
- package/build/component/constants.js +2 -0
- package/build/component/constants.js.map +1 -0
- package/build/component/context.d.ts +199 -0
- package/build/component/context.d.ts.map +1 -0
- package/build/component/context.js +262 -0
- package/build/component/context.js.map +1 -0
- package/build/component/graphRuntime.constants.d.ts +13 -0
- package/build/component/graphRuntime.constants.d.ts.map +1 -0
- package/build/component/graphRuntime.constants.js +15 -0
- package/build/component/graphRuntime.constants.js.map +1 -0
- package/build/component/h.d.ts +48 -0
- package/build/component/h.d.ts.map +1 -0
- package/build/component/h.js +72 -0
- package/build/component/h.js.map +1 -0
- package/build/component/index.d.ts +19 -0
- package/build/component/index.d.ts.map +1 -0
- package/build/component/index.js +39 -0
- package/build/component/index.js.map +1 -0
- package/build/component/lifecycle.d.ts +179 -0
- package/build/component/lifecycle.d.ts.map +1 -0
- package/build/component/lifecycle.js +367 -0
- package/build/component/lifecycle.js.map +1 -0
- package/build/component/refs.d.ts +105 -0
- package/build/component/refs.d.ts.map +1 -0
- package/build/component/refs.js +128 -0
- package/build/component/refs.js.map +1 -0
- package/build/component/types.d.ts +169 -0
- package/build/component/types.d.ts.map +1 -0
- package/build/component/types.js +40 -0
- package/build/component/types.js.map +1 -0
- package/build/connect/connect.d.ts +31 -0
- package/build/connect/connect.d.ts.map +1 -0
- package/build/connect/connect.js +500 -0
- package/build/connect/connect.js.map +1 -0
- package/build/connect/index.d.ts +8 -0
- package/build/connect/index.d.ts.map +1 -0
- package/build/connect/index.js +11 -0
- package/build/connect/index.js.map +1 -0
- package/build/connect/types.d.ts +90 -0
- package/build/connect/types.d.ts.map +1 -0
- package/build/connect/types.js +8 -0
- package/build/connect/types.js.map +1 -0
- package/build/index.d.ts +26 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +60 -0
- package/build/index.js.map +1 -0
- package/build/runtime/BusDecorators.d.ts +113 -0
- package/build/runtime/BusDecorators.d.ts.map +1 -0
- package/build/runtime/BusDecorators.js +302 -0
- package/build/runtime/BusDecorators.js.map +1 -0
- package/build/runtime/CommandBus.d.ts +43 -0
- package/build/runtime/CommandBus.d.ts.map +1 -0
- package/build/runtime/CommandBus.js +65 -0
- package/build/runtime/CommandBus.js.map +1 -0
- package/build/runtime/EventBus.d.ts +50 -0
- package/build/runtime/EventBus.d.ts.map +1 -0
- package/build/runtime/EventBus.js +90 -0
- package/build/runtime/EventBus.js.map +1 -0
- package/build/runtime/HandleRegistry.d.ts +143 -0
- package/build/runtime/HandleRegistry.d.ts.map +1 -0
- package/build/runtime/HandleRegistry.js +244 -0
- package/build/runtime/HandleRegistry.js.map +1 -0
- package/build/runtime/QueryBus.d.ts +43 -0
- package/build/runtime/QueryBus.d.ts.map +1 -0
- package/build/runtime/QueryBus.js +65 -0
- package/build/runtime/QueryBus.js.map +1 -0
- package/build/runtime/index.d.ts +13 -0
- package/build/runtime/index.d.ts.map +1 -0
- package/build/runtime/index.js +32 -0
- package/build/runtime/index.js.map +1 -0
- package/build/runtime/types.d.ts +79 -0
- package/build/runtime/types.d.ts.map +1 -0
- package/build/runtime/types.js +8 -0
- package/build/runtime/types.js.map +1 -0
- package/build/store/createStore.d.ts +36 -0
- package/build/store/createStore.d.ts.map +1 -0
- package/build/store/createStore.js +131 -0
- package/build/store/createStore.js.map +1 -0
- package/build/store/index.d.ts +14 -0
- package/build/store/index.d.ts.map +1 -0
- package/build/store/index.js +39 -0
- package/build/store/index.js.map +1 -0
- package/build/store/middleware.d.ts +38 -0
- package/build/store/middleware.d.ts.map +1 -0
- package/build/store/middleware.js +99 -0
- package/build/store/middleware.js.map +1 -0
- package/build/store/selector.d.ts +62 -0
- package/build/store/selector.d.ts.map +1 -0
- package/build/store/selector.js +226 -0
- package/build/store/selector.js.map +1 -0
- package/build/store/semanticStateTree.d.ts +91 -0
- package/build/store/semanticStateTree.d.ts.map +1 -0
- package/build/store/semanticStateTree.js +263 -0
- package/build/store/semanticStateTree.js.map +1 -0
- package/build/store/types.d.ts +259 -0
- package/build/store/types.d.ts.map +1 -0
- package/build/store/types.js +28 -0
- package/build/store/types.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HOC connect: connects a component class to the store via mapStateToProps and/or mapDispatchToProps,
|
|
4
|
+
* implemented as a class-based wrapper over the original class.
|
|
5
|
+
*
|
|
6
|
+
* Call: `connect(store, mapState?, mapDispatch?)(Ctor)`.
|
|
7
|
+
* Third argument: full function `(dispatch, props) => …`, short `(dispatch) => …`,
|
|
8
|
+
* or an object of action creators `{ key: (...args) => action }` (see `resolveMapDispatchProps`).
|
|
9
|
+
*
|
|
10
|
+
* @module Effectable/connect/connect
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.connect = connect;
|
|
14
|
+
const types_1 = require("../component/types");
|
|
15
|
+
const context_1 = require("../component/context");
|
|
16
|
+
const CONNECT_STORE_CONTEXT = (0, context_1.createContext)('EFFECTABLE_CONNECT_STORE', null);
|
|
17
|
+
const CONNECT_STORE_CONTEXT_FIELD = '__connectStoreFromContext';
|
|
18
|
+
/**
|
|
19
|
+
* Default props filtering mode for `connect` when not set explicitly via {@link ConnectOptions}.
|
|
20
|
+
*
|
|
21
|
+
* Target `Effectable` contract: `'strict'` — parent props do not leak into public `this.props`;
|
|
22
|
+
* only what mappers explicitly return ends up there. Prefer explicit pass-through mappers.
|
|
23
|
+
* Legacy `'merge'` mode is enabled only explicitly via `ConnectOptions.ownPropsModeMerge: true`
|
|
24
|
+
* as a documented transitional mode.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_OWN_PROPS_MODE = 'strict';
|
|
27
|
+
/**
|
|
28
|
+
* Checks that a value looks like a Promise (thenable) and can be awaited asynchronously.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} value - value to check
|
|
31
|
+
* @returns {boolean} `true` if the object has a `then` method of type function
|
|
32
|
+
*/
|
|
33
|
+
function isPromiseLike(value) {
|
|
34
|
+
if (typeof value !== 'object' || value === null) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const record = value;
|
|
38
|
+
return typeof record['then'] === 'function';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks that a value looks like an Effectable store.
|
|
42
|
+
*
|
|
43
|
+
* @param {unknown} value - value to check
|
|
44
|
+
* @returns {boolean} `true` if the object implements the required store API
|
|
45
|
+
*/
|
|
46
|
+
function isStoreLike(value) {
|
|
47
|
+
if (typeof value !== 'object' || value === null) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const record = value;
|
|
51
|
+
return (typeof record['dispatch'] === 'function' &&
|
|
52
|
+
typeof record['getState'] === 'function' &&
|
|
53
|
+
typeof record['select'] === 'function' &&
|
|
54
|
+
typeof record['destroy'] === 'function');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adds metadata so the connected class can obtain the store from context before `onMount`.
|
|
58
|
+
*
|
|
59
|
+
* @param target - constructor of the dynamic connected class
|
|
60
|
+
*/
|
|
61
|
+
function attachConnectStoreContext(target) {
|
|
62
|
+
const inheritedFields = target[context_1.CONTEXT_FIELDS_META_KEY];
|
|
63
|
+
const nextFields = Array.isArray(inheritedFields) ? [...inheritedFields] : [];
|
|
64
|
+
nextFields.push({
|
|
65
|
+
propertyKey: CONNECT_STORE_CONTEXT_FIELD,
|
|
66
|
+
token: CONNECT_STORE_CONTEXT,
|
|
67
|
+
});
|
|
68
|
+
target[context_1.CONTEXT_FIELDS_META_KEY] = nextFields;
|
|
69
|
+
target[context_1.HAS_CONTEXT_FIELDS_KEY] = true;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Normalizes a mapper result into a props object for further merge into the instance.
|
|
73
|
+
*
|
|
74
|
+
* @param {unknown} mapped - result of `mapStateToProps` or `mapDispatchToProps`
|
|
75
|
+
* @returns {Record<string, unknown> | null} props dictionary, or `null` if the shape is unsupported
|
|
76
|
+
*/
|
|
77
|
+
function getMappedPropsRecord(mapped) {
|
|
78
|
+
if (mapped === null || typeof mapped !== 'object' || Array.isArray(mapped)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return mapped;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Converts mapDispatchToProps (function or action creators object) into a flat object for merge into props.
|
|
85
|
+
*
|
|
86
|
+
* Function as third argument: when `function.length <= 1` it is treated as “dispatch only”
|
|
87
|
+
* and called as `fn(dispatch)` (no need for a `(d) => mapXxx(d)` wrapper).
|
|
88
|
+
* Full form `(dispatch, props) => …` — when `function.length >= 2`, both arguments are passed.
|
|
89
|
+
* Do not use a default value on the second parameter if it is needed in the body — then
|
|
90
|
+
* `function.length` will be 1 and `props` will not reach the callback.
|
|
91
|
+
*
|
|
92
|
+
* @template S store state type
|
|
93
|
+
* @template P instance props type
|
|
94
|
+
* @template A action type
|
|
95
|
+
* @param {Store<S, A>} store - store with a `dispatch` method
|
|
96
|
+
* @param {MapDispatchToProps<S, P, A> | null | undefined} mapDispatch - function or action creators object; `null`/`undefined` — nothing to merge
|
|
97
|
+
* @param {P} props - current instance props (for the full `mapDispatch` form)
|
|
98
|
+
* @returns {Record<string, unknown> | null} flat object of callbacks/dispatch wrappers, or `null` if nothing to merge
|
|
99
|
+
*/
|
|
100
|
+
function resolveMapDispatchProps(store, mapDispatch, props) {
|
|
101
|
+
if (mapDispatch == null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (typeof mapDispatch === 'function') {
|
|
105
|
+
const fn = mapDispatch;
|
|
106
|
+
let out;
|
|
107
|
+
if (fn.length >= 2) {
|
|
108
|
+
out = fn(store.dispatch, props);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
out = fn(store.dispatch);
|
|
112
|
+
}
|
|
113
|
+
if (out == null || typeof out !== 'object' || Array.isArray(out)) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
const creators = mapDispatch;
|
|
119
|
+
const bound = {};
|
|
120
|
+
for (const key of Object.keys(creators)) {
|
|
121
|
+
const ac = creators[key];
|
|
122
|
+
if (typeof ac !== 'function') {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
bound[key] = (...args) => store.dispatch(ac(...args));
|
|
126
|
+
}
|
|
127
|
+
return bound;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Internal factory: returns an HOC that wraps the given constructor in a connected class.
|
|
131
|
+
*
|
|
132
|
+
* @template S store state type
|
|
133
|
+
* @template P props type of the wrapped component
|
|
134
|
+
* @template R result type of `mapStateToProps`
|
|
135
|
+
* @template A action type
|
|
136
|
+
* @param {Store<S, A> | null} explicitStore - explicitly passed store for a root-connected node, or `null`
|
|
137
|
+
* for a child node that will receive the store from context
|
|
138
|
+
* @param {MapStateToProps<S, P, R> | undefined | null} mapStateToProps - state → props selector, or no subscription
|
|
139
|
+
* @param {MapDispatchToProps<S, P, A> | undefined | null} mapDispatchToProps - binding dispatch to prop methods
|
|
140
|
+
* @returns {<C extends ConnectableHocTarget>(Constructor: C) => C} function `(Ctor) => Ctor-subclass` with subscription and merge into `props`
|
|
141
|
+
*/
|
|
142
|
+
function buildConnectHoc(explicitStore, mapStateToProps, mapDispatchToProps, ownPropsMode) {
|
|
143
|
+
return function connectHoc(Constructor) {
|
|
144
|
+
const BaseCtor = Constructor;
|
|
145
|
+
/**
|
|
146
|
+
* Subclass of the original component: on mount merges dispatch props; when `mapStateToProps` is present
|
|
147
|
+
* subscribes to `store.select` and updates `props` + `setState` after the first selector pass.
|
|
148
|
+
*/
|
|
149
|
+
class Connected extends BaseCtor {
|
|
150
|
+
__connectSubscription = null;
|
|
151
|
+
__connectPrevMapped = undefined;
|
|
152
|
+
__connectFirstPass = true;
|
|
153
|
+
__connectMountCompleted = false;
|
|
154
|
+
__connectPendingUpdate = false;
|
|
155
|
+
/**
|
|
156
|
+
* After mount completed, at least one `onUpdate` was delivered via `setState`
|
|
157
|
+
* (pending flush or store emit). Needed so the post-mount kick-off does not duplicate a pass.
|
|
158
|
+
*/
|
|
159
|
+
__connectDeliveredUpdateAfterMount = false;
|
|
160
|
+
/** Kick-off via `queueMicrotask` has already been queued (exactly once per mount). */
|
|
161
|
+
__connectKickoffScheduled = false;
|
|
162
|
+
__connectStore = explicitStore;
|
|
163
|
+
__connectStoreFromContext = undefined;
|
|
164
|
+
__connectOwnProps;
|
|
165
|
+
__connectStateProps = null;
|
|
166
|
+
__connectDispatchProps = null;
|
|
167
|
+
constructor(props) {
|
|
168
|
+
super(props);
|
|
169
|
+
this.__connectOwnProps = this.props;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Delivers an update-pass via `setState({})` and marks that the post-mount kick-off
|
|
173
|
+
* is no longer needed (avoids a double onUpdate).
|
|
174
|
+
*
|
|
175
|
+
* @returns {void}
|
|
176
|
+
*/
|
|
177
|
+
deliverConnectUpdate() {
|
|
178
|
+
this.__connectDeliveredUpdateAfterMount = true;
|
|
179
|
+
this.setState({});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Schedules one deferred `onUpdate` kick-off after mount completes.
|
|
183
|
+
*
|
|
184
|
+
* Microtask (not sync): right after `onMount` the immediate post-mount contract is preserved
|
|
185
|
+
* (`['mount:…']` without update), and by the time of the microtask GraphRuntime has already injected
|
|
186
|
+
* `SCHEDULE_UPDATE_HOOK`, so the kick-off also rebuilds `compose()`.
|
|
187
|
+
*
|
|
188
|
+
* @returns {void}
|
|
189
|
+
*/
|
|
190
|
+
schedulePostMountKickoff() {
|
|
191
|
+
if (this.__connectKickoffScheduled) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
this.__connectKickoffScheduled = true;
|
|
195
|
+
queueMicrotask(() => {
|
|
196
|
+
if (this.__connectSubscription === null) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (!this.__connectMountCompleted) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.__connectDeliveredUpdateAfterMount) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
this.deliverConnectUpdate();
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Completes mount: flush any pending store emit deferred during `onMount`, then schedule post-mount kick-off.
|
|
210
|
+
*
|
|
211
|
+
* @returns {void}
|
|
212
|
+
*/
|
|
213
|
+
completeConnectMount() {
|
|
214
|
+
this.__connectMountCompleted = true;
|
|
215
|
+
if (this.__connectPendingUpdate) {
|
|
216
|
+
this.__connectPendingUpdate = false;
|
|
217
|
+
this.deliverConnectUpdate();
|
|
218
|
+
}
|
|
219
|
+
this.schedulePostMountKickoff();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Publishes the resolved store into the connected component's subtree.
|
|
223
|
+
*
|
|
224
|
+
* @param {ContextScope} parentScope - parent scope
|
|
225
|
+
* @returns {ContextScope} scope for child nodes
|
|
226
|
+
*/
|
|
227
|
+
applyToScope(parentScope) {
|
|
228
|
+
return (0, context_1.extendScope)(parentScope, CONNECT_STORE_CONTEXT, this.resolveConnectStore());
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Returns the store from the explicit `connect(store, ...)` argument or from the context
|
|
232
|
+
* of the nearest connected ancestor.
|
|
233
|
+
*
|
|
234
|
+
* @returns {Store<S, A>} resolved store
|
|
235
|
+
*/
|
|
236
|
+
resolveConnectStore() {
|
|
237
|
+
if (this.__connectStore !== null) {
|
|
238
|
+
return this.__connectStore;
|
|
239
|
+
}
|
|
240
|
+
if (isStoreLike(this.__connectStoreFromContext)) {
|
|
241
|
+
this.__connectStore = this.__connectStoreFromContext;
|
|
242
|
+
return this.__connectStore;
|
|
243
|
+
}
|
|
244
|
+
throw new Error('[Effectable.connect] Store is not available. ' +
|
|
245
|
+
'Use connect(store, ...) for the root connected component or mount this component under a connected parent.');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Attempts to obtain the store without throwing.
|
|
249
|
+
*
|
|
250
|
+
* Used on the reconcile path so props can be updated even if the store has not yet been
|
|
251
|
+
* fully cached.
|
|
252
|
+
*
|
|
253
|
+
* @returns {Store<S, A> | null}
|
|
254
|
+
*/
|
|
255
|
+
tryResolveConnectStore() {
|
|
256
|
+
if (this.__connectStore !== null) {
|
|
257
|
+
return this.__connectStore;
|
|
258
|
+
}
|
|
259
|
+
if (isStoreLike(this.__connectStoreFromContext)) {
|
|
260
|
+
this.__connectStore = this.__connectStoreFromContext;
|
|
261
|
+
return this.__connectStore;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Builds the instance's final `props` from already computed mapped groups.
|
|
267
|
+
*
|
|
268
|
+
* Overlay order: dispatch props -> state props (stateProps override dispatchProps,
|
|
269
|
+
* as they are closer to the selector result).
|
|
270
|
+
*
|
|
271
|
+
* Base layer depends on {@link OwnPropsMode}:
|
|
272
|
+
* - `'merge'`: base is parent props (legacy: props automatically appear in `this.props`);
|
|
273
|
+
* - `'strict'`: base is an empty object — parent props do NOT leak into public `this.props`;
|
|
274
|
+
* only what mappers explicitly returned appears there.
|
|
275
|
+
*
|
|
276
|
+
* @returns {void}
|
|
277
|
+
*/
|
|
278
|
+
rebuildConnectProps() {
|
|
279
|
+
let nextProps = ownPropsMode === 'strict'
|
|
280
|
+
? {}
|
|
281
|
+
: this.__connectOwnProps;
|
|
282
|
+
if (this.__connectDispatchProps !== null) {
|
|
283
|
+
nextProps = {
|
|
284
|
+
...nextProps,
|
|
285
|
+
...this.__connectDispatchProps,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (this.__connectStateProps !== null) {
|
|
289
|
+
nextProps = {
|
|
290
|
+
...nextProps,
|
|
291
|
+
...this.__connectStateProps,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
this.props = nextProps;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Recomputes dispatch props based on current props.
|
|
298
|
+
*
|
|
299
|
+
* @param {Store<S, A>} store
|
|
300
|
+
* @returns {void}
|
|
301
|
+
*/
|
|
302
|
+
refreshDispatchProps(store) {
|
|
303
|
+
this.__connectDispatchProps = resolveMapDispatchProps(store, mapDispatchToProps, this.__connectOwnProps);
|
|
304
|
+
this.rebuildConnectProps();
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Applies a new object from `mapStateToProps` as the current state-derived props.
|
|
308
|
+
*
|
|
309
|
+
* @param {unknown} mapped
|
|
310
|
+
* @returns {boolean} `true` if state-derived props actually updated
|
|
311
|
+
*/
|
|
312
|
+
applyMappedStateProps(mapped) {
|
|
313
|
+
if (mapped === this.__connectPrevMapped) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
const mappedProps = getMappedPropsRecord(mapped);
|
|
317
|
+
if (mappedProps === null) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
this.__connectPrevMapped = mapped;
|
|
321
|
+
this.__connectStateProps = mappedProps;
|
|
322
|
+
this.rebuildConnectProps();
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Tears down the active store subscription if it exists.
|
|
327
|
+
*
|
|
328
|
+
* @returns {void}
|
|
329
|
+
*/
|
|
330
|
+
disposeConnectSubscription() {
|
|
331
|
+
if (this.__connectSubscription !== null) {
|
|
332
|
+
this.__connectSubscription.unsubscribe();
|
|
333
|
+
this.__connectSubscription = null;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Updates props from GraphRuntime.reconcile and synchronously rebuilds merged props.
|
|
338
|
+
*
|
|
339
|
+
* Parent props are applied synchronously on the update path. When `mapStateToProps` is present
|
|
340
|
+
* it is recomputed synchronously on the new props (`mapStateToProps(store.getState(), nextProps)`)
|
|
341
|
+
* before the next `onUpdate`/`compose()`, without waiting for the next store emission.
|
|
342
|
+
* This eliminates stale state-derived props on reconcile.
|
|
343
|
+
*
|
|
344
|
+
* @param {P} nextProps
|
|
345
|
+
* @returns {void}
|
|
346
|
+
*/
|
|
347
|
+
[types_1.RUNTIME_PROPS_RECEIVER](nextProps) {
|
|
348
|
+
this.__connectOwnProps = nextProps;
|
|
349
|
+
const store = this.tryResolveConnectStore();
|
|
350
|
+
if (store !== null) {
|
|
351
|
+
if (mapStateToProps != null) {
|
|
352
|
+
const nextMapped = mapStateToProps(store.getState(), this.__connectOwnProps);
|
|
353
|
+
this.applyMappedStateProps(nextMapped);
|
|
354
|
+
}
|
|
355
|
+
this.refreshDispatchProps(store);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
this.rebuildConnectProps();
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Wires dispatch props and, if needed, a state subscription; then calls the base class `onMount`.
|
|
362
|
+
*
|
|
363
|
+
* @returns {void | Promise<void>} synchronously or a Promise if the superclass `onMount` is async
|
|
364
|
+
*/
|
|
365
|
+
onMount() {
|
|
366
|
+
const store = this.resolveConnectStore();
|
|
367
|
+
this.refreshDispatchProps(store);
|
|
368
|
+
const superOnMount = Constructor.prototype['onMount'];
|
|
369
|
+
const hasSuperOnMount = typeof superOnMount === 'function';
|
|
370
|
+
if (mapStateToProps == null) {
|
|
371
|
+
this.__connectMountCompleted = true;
|
|
372
|
+
if (!hasSuperOnMount) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const mountResult = superOnMount.call(this);
|
|
376
|
+
if (isPromiseLike(mountResult)) {
|
|
377
|
+
return mountResult;
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
let pendingMountResult = null;
|
|
382
|
+
// A sync throw in super.onMount on the first pass happens before
|
|
383
|
+
// this.__connectSubscription is assigned (subscribe has not yet returned a Subscription) —
|
|
384
|
+
// store the error and dispose after assignment, without rethrowing inside RxJS next.
|
|
385
|
+
let syncFirstPassError = null;
|
|
386
|
+
const selector = (state) => mapStateToProps(state, this.__connectOwnProps);
|
|
387
|
+
this.__connectSubscription = store.select(selector).subscribe((mapped) => {
|
|
388
|
+
this.applyMappedStateProps(mapped);
|
|
389
|
+
if (this.__connectFirstPass) {
|
|
390
|
+
this.__connectFirstPass = false;
|
|
391
|
+
if (!hasSuperOnMount) {
|
|
392
|
+
this.completeConnectMount();
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
let mountResult;
|
|
396
|
+
try {
|
|
397
|
+
mountResult = superOnMount.call(this);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
syncFirstPassError = error;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (!isPromiseLike(mountResult)) {
|
|
404
|
+
this.completeConnectMount();
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
pendingMountResult = Promise.resolve(mountResult).then(() => {
|
|
408
|
+
this.completeConnectMount();
|
|
409
|
+
}, (error) => {
|
|
410
|
+
this.disposeConnectSubscription();
|
|
411
|
+
this.__connectPendingUpdate = false;
|
|
412
|
+
throw error;
|
|
413
|
+
});
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (!this.__connectMountCompleted) {
|
|
417
|
+
this.__connectPendingUpdate = true;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
this.deliverConnectUpdate();
|
|
421
|
+
});
|
|
422
|
+
if (syncFirstPassError !== null) {
|
|
423
|
+
this.disposeConnectSubscription();
|
|
424
|
+
throw syncFirstPassError;
|
|
425
|
+
}
|
|
426
|
+
if (pendingMountResult !== null) {
|
|
427
|
+
return pendingMountResult;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Unsubscribes from the store and delegates to the base class `onUnmount`.
|
|
432
|
+
*
|
|
433
|
+
* @returns {void | Promise<void>}
|
|
434
|
+
*/
|
|
435
|
+
onUnmount() {
|
|
436
|
+
this.disposeConnectSubscription();
|
|
437
|
+
const superOnUnmount = Constructor.prototype['onUnmount'];
|
|
438
|
+
if (typeof superOnUnmount !== 'function') {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const result = superOnUnmount.call(this);
|
|
442
|
+
if (isPromiseLike(result)) {
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
Object.defineProperty(Connected.prototype, context_1.IS_CONTEXT_PROVIDER, {
|
|
448
|
+
value: true,
|
|
449
|
+
writable: false,
|
|
450
|
+
enumerable: false,
|
|
451
|
+
configurable: false,
|
|
452
|
+
});
|
|
453
|
+
if (explicitStore === null) {
|
|
454
|
+
attachConnectStoreContext(Connected);
|
|
455
|
+
}
|
|
456
|
+
Object.defineProperty(Connected, 'name', {
|
|
457
|
+
value: Constructor.name,
|
|
458
|
+
configurable: true,
|
|
459
|
+
});
|
|
460
|
+
return Connected;
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Connects a component class to the store (class-based HOC): merge into `props` from state and/or dispatch.
|
|
465
|
+
* Supports two forms:
|
|
466
|
+
* - `connect(store, mapState?, mapDispatch?)` for a root connected component;
|
|
467
|
+
* - `connect(mapState?, mapDispatch?)` for a child connected component that receives the store from context.
|
|
468
|
+
*
|
|
469
|
+
* @template S store state type
|
|
470
|
+
* @template P props type of the connected component
|
|
471
|
+
* @template R result type of `mapStateToProps`
|
|
472
|
+
* @template A action type
|
|
473
|
+
* @param {Store<S, A> | MapStateToProps<S, P, R> | null | undefined} [storeOrMapStateToProps] - explicit store or `mapStateToProps`
|
|
474
|
+
* @param {MapStateToProps<S, P, R> | MapDispatchToProps<S, P, A> | null | undefined} [mapStateToPropsOrMapDispatchToProps] - `mapStateToProps` or `mapDispatchToProps`
|
|
475
|
+
* @param {MapDispatchToProps<S, P, A> | ConnectOptions | null | undefined} [mapDispatchToPropsOrOptions] - `mapDispatchToProps` or {@link ConnectOptions}
|
|
476
|
+
* @param {ConnectOptions} [maybeOptions] - {@link ConnectOptions} (e.g. `ownPropsModeMerge`) for the form with an explicit store
|
|
477
|
+
* @returns {<C extends ConnectableHocTarget>(Constructor: C) => C} HOC: `(Ctor) => subclass of C` with the same constructor name
|
|
478
|
+
*/
|
|
479
|
+
function connect(storeOrMapStateToProps, mapStateToPropsOrMapDispatchToProps, mapDispatchToPropsOrOptions, maybeOptions) {
|
|
480
|
+
let store = null;
|
|
481
|
+
let mapStateToProps;
|
|
482
|
+
let mapDispatchToProps;
|
|
483
|
+
let options;
|
|
484
|
+
if (isStoreLike(storeOrMapStateToProps)) {
|
|
485
|
+
store = storeOrMapStateToProps;
|
|
486
|
+
mapStateToProps = mapStateToPropsOrMapDispatchToProps;
|
|
487
|
+
mapDispatchToProps = mapDispatchToPropsOrOptions;
|
|
488
|
+
options = maybeOptions;
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
mapStateToProps = storeOrMapStateToProps;
|
|
492
|
+
mapDispatchToProps = mapStateToPropsOrMapDispatchToProps;
|
|
493
|
+
options = mapDispatchToPropsOrOptions;
|
|
494
|
+
}
|
|
495
|
+
const ownPropsMode = options !== undefined && options.ownPropsModeMerge === true
|
|
496
|
+
? 'merge'
|
|
497
|
+
: DEFAULT_OWN_PROPS_MODE;
|
|
498
|
+
return buildConnectHoc(store, mapStateToProps ?? undefined, mapDispatchToProps ?? undefined, ownPropsMode);
|
|
499
|
+
}
|
|
500
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/connect/connect.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA2lBH,0BAgCC;AAvnBD,8CAA4D;AAC5D,kDAM8B;AAa9B,MAAM,qBAAqB,GAAG,IAAA,uBAAa,EAAiB,0BAA0B,EAAE,IAAI,CAAC,CAAC;AAC9F,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAiB,QAAQ,CAAC;AAEtD;;;;;GAKG;AACH,SAAS,aAAa,CAAE,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,KAAqC,CAAC;IACrD,OAAO,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAE,KAAc;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,KAAqC,CAAC;IACrD,OAAO,CACL,OAAO,MAAM,C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,WAAW,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACxC,KAAK,GAAG,sBAAqC,CAAC;QAC9C,eAAe,GAAG,mCAA2E,CAAC;QAC9F,kBAAkB,GAAG,2BAAsE,CAAC;QAC5F,OAAO,GAAG,YAAY,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,eAAe,GAAG,sBAA8D,CAAC;QACjF,kBAAkB,GAAG,mCAA8E,CAAC;QACpG,OAAO,GAAG,2BAAyD,CAAC;IACtE,CAAC;IAED,MAAM,YAAY,GAAiB,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,iBAAiB,KAAK,IAAI;QAC5F,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,sBAAsB,CAAC;IAE3B,OAAO,eAAe,CACpB,KAAK,EACL,eAAe,IAAI,SAAS,EAC5B,kBAAkB,IAAI,SAAS,EAC/B,YAAY,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export connect and types for Effectable/connect.
|
|
3
|
+
*
|
|
4
|
+
* @module Effectable/connect
|
|
5
|
+
*/
|
|
6
|
+
export { connect } from './connect';
|
|
7
|
+
export type { MapStateToProps, MapDispatchToProps, MapDispatchToPropsFunction, MapDispatchToPropsDispatchOnly, ActionCreatorsMap, ConnectOptions, OwnPropsMode, ConnectableInstance, ConnectableConstructor, ConnectableHocTarget } from './types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Re-export connect and types for Effectable/connect.
|
|
4
|
+
*
|
|
5
|
+
* @module Effectable/connect
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.connect = void 0;
|
|
9
|
+
var connect_1 = require("./connect");
|
|
10
|
+
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connect_1.connect; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the connect HOC: mapping store state into instance props/state, options.
|
|
3
|
+
*
|
|
4
|
+
* @module Effectable/connect/types
|
|
5
|
+
*/
|
|
6
|
+
import type { Action, DispatchMethod } from '../store/types';
|
|
7
|
+
import type { Lifecycle } from '../component/types';
|
|
8
|
+
/**
|
|
9
|
+
* Function that maps store state into state/props passed to the class instance.
|
|
10
|
+
*
|
|
11
|
+
* @template S - Store state type
|
|
12
|
+
* @template P - Props type passed when creating the instance
|
|
13
|
+
* @template R - Result type (store slice for merge into props)
|
|
14
|
+
*/
|
|
15
|
+
export type MapStateToProps<S, P = unknown, R = unknown> = (state: S, props: P) => R;
|
|
16
|
+
/**
|
|
17
|
+
* mapDispatchToProps function: (dispatch, props) => object of callbacks merged into props.
|
|
18
|
+
*
|
|
19
|
+
* @template S - not used directly in the signature; kept for consistency with mapStateToProps
|
|
20
|
+
* @template P - instance props type
|
|
21
|
+
* @template A - store action union type
|
|
22
|
+
*/
|
|
23
|
+
export type MapDispatchToPropsFunction<S, P, A extends Action = Action> = (dispatch: DispatchMethod<A>, props: P) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Short mapDispatch form: only `(dispatch) => object of callbacks`.
|
|
26
|
+
* Inside `connect` it is called as `fn(dispatch)` without passing `props` from outside
|
|
27
|
+
* (no need to write `(d) => mapXxx(d)` when passing `mapXxx` as the third argument).
|
|
28
|
+
*/
|
|
29
|
+
export type MapDispatchToPropsDispatchOnly<A extends Action = Action> = (dispatch: DispatchMethod<A>) => unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Action creators object: keys are prop names, values are functions returning an action.
|
|
32
|
+
* `connect` binds them via `dispatch(actionCreator(...args))`.
|
|
33
|
+
*/
|
|
34
|
+
export type ActionCreatorsMap<A extends Action = Action> = Record<string, (...args: unknown[]) => A>;
|
|
35
|
+
/**
|
|
36
|
+
* Third argument of `connect`: full function `(dispatch, props) => …`, short `(dispatch) => …`,
|
|
37
|
+
* or an object of action creators.
|
|
38
|
+
*/
|
|
39
|
+
export type MapDispatchToProps<S, P, A extends Action = Action> = MapDispatchToPropsFunction<S, P, A> | MapDispatchToPropsDispatchOnly<A> | ActionCreatorsMap<A>;
|
|
40
|
+
/**
|
|
41
|
+
* Mode for building the wrapped component's public `this.props` from props and mapper results.
|
|
42
|
+
*
|
|
43
|
+
* - `'merge'` (legacy/transitional): final props are `props -> dispatchProps -> stateProps`,
|
|
44
|
+
* i.e. parent props automatically appear in `this.props`.
|
|
45
|
+
* - `'strict'`: parent props are used only as mapper inputs; public `this.props`
|
|
46
|
+
* receives only what `mapStateToProps`/`mapDispatchToProps` explicitly returned.
|
|
47
|
+
*/
|
|
48
|
+
export type OwnPropsMode = 'merge' | 'strict';
|
|
49
|
+
/**
|
|
50
|
+
* Options for connect.
|
|
51
|
+
*/
|
|
52
|
+
export interface ConnectOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Enables the legacy `'merge'` props filtering mode (see {@link OwnPropsMode}).
|
|
55
|
+
*
|
|
56
|
+
* - `false` or unset (default): `'strict'` mode — parent props do not leak
|
|
57
|
+
* into public `this.props`; only mapper results appear there.
|
|
58
|
+
* - `true`: `'merge'` mode — parent props automatically appear in `this.props`.
|
|
59
|
+
*
|
|
60
|
+
* Strict is the target `Effectable` contract, so most components do not need this option.
|
|
61
|
+
* Set the flag to `true` only where legacy prop forwarding is intentionally required.
|
|
62
|
+
*/
|
|
63
|
+
ownPropsModeMerge?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Shape of a class instance suitable for connect: compatible with {@link Lifecycle}, has
|
|
67
|
+
* mutable `props` and `state`, and a `setState` method.
|
|
68
|
+
*
|
|
69
|
+
* The class must extend {@link Component} (directly or via an intermediate class).
|
|
70
|
+
*/
|
|
71
|
+
export interface ConnectableInstance<P = unknown, R = unknown> extends Lifecycle {
|
|
72
|
+
props: P;
|
|
73
|
+
state: R;
|
|
74
|
+
setState: (update: Partial<R> | ((prevState: R, props: P) => Partial<R>)) => void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Constructor of a class suitable for wrapping with connect.
|
|
78
|
+
*
|
|
79
|
+
* @template P - Instance props type
|
|
80
|
+
* @template R - Instance state type
|
|
81
|
+
* @template TInstance - Instance shape (defaults to ConnectableInstance<P, R>)
|
|
82
|
+
*/
|
|
83
|
+
export type ConnectableConstructor<P = unknown, R = unknown, TInstance extends ConnectableInstance<P, R> = ConnectableInstance<P, R>> = new (props: P) => TInstance;
|
|
84
|
+
/**
|
|
85
|
+
* Constructor allowed as an argument to the {@link connect} HOC.
|
|
86
|
+
* The `props` parameter is widened to `any`; otherwise under `strictFunctionTypes` a class with a narrow
|
|
87
|
+
* `new (props: ConcreteProps)` is incompatible with a generic `new (props: unknown)`.
|
|
88
|
+
*/
|
|
89
|
+
export type ConnectableHocTarget = new (props: any) => ConnectableInstance<any, any>;
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/connect/types.ts"],"names":[],"mappings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