@reactables/core 1.3.0-beta.3 → 2.0.0-beta.1

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/index.js CHANGED
@@ -1,9 +1,5 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var operators = require('rxjs/operators');
6
- var rxjs = require('rxjs');
1
+ import { Subject, ReplaySubject, merge, combineLatest } from 'rxjs';
2
+ import { filter, map, takeUntil, shareReplay, tap, mergeAll, share, scan, startWith, pairwise } from 'rxjs/operators';
7
3
 
8
4
  /******************************************************************************
9
5
  Copyright (c) Microsoft Corporation.
@@ -19,6 +15,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
15
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
16
  PERFORMANCE OF THIS SOFTWARE.
21
17
  ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
19
+
22
20
 
23
21
  var __assign = function() {
24
22
  __assign = Object.assign || function __assign(t) {
@@ -58,299 +56,288 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
58
56
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
57
  };
60
58
 
61
- var ofTypes = function (types) { return function (dispatcher$) {
62
- return dispatcher$.pipe(operators.filter(function (_a) {
63
- var type = _a.type;
64
- return types.includes(type);
65
- }));
66
- }; };
67
-
68
- var addEffects = function (actionCreator, scopedEffects) {
69
- return function (payload) { return (__assign(__assign({}, actionCreator(payload)), { scopedEffects: scopedEffects(payload) })); };
59
+ var addEffects = function (actionCreator, scopedEffects) {
60
+ return function (payload) { return (__assign(__assign({}, actionCreator(payload)), { scopedEffects: scopedEffects(payload) })); };
70
61
  };
71
-
72
- var createSlice = function (config) {
73
- var initialState = config.initialState, reducers = config.reducers;
74
- var reducer = Object.entries(reducers).reduce(function (acc, _a) {
75
- var key = _a[0], _case = _a[1];
76
- var _reducer = typeof _case === 'function' ? _case : _case.reducer;
77
- var newFunc = function (state, action) {
78
- if (action && action.type === key) {
79
- return _reducer(state, action);
80
- }
81
- return acc(state, action);
82
- };
83
- return newFunc;
84
- }, function (state) {
85
- if (state === void 0) { state = initialState; }
86
- return state;
87
- });
88
- var actions = Object.entries(reducers).reduce(function (acc, _a) {
89
- var key = _a[0], _case = _a[1];
90
- acc[key] = function (payload) { return ({
91
- type: key,
92
- payload: payload
93
- }); };
94
- if (typeof _case !== 'function' && _case.effects) {
95
- var effects = typeof _case.effects === 'function'
96
- ? _case.effects
97
- : (function () { return ({ effects: _case.effects }); });
98
- acc[key] = addEffects(acc[key], effects);
99
- }
100
- return acc;
101
- }, {});
102
- return {
103
- reducer: reducer,
104
- actions: actions
105
- };
62
+ var createSlice = function (config) {
63
+ var initialState = config.initialState, reducers = config.reducers;
64
+ var reducer = Object.entries(reducers).reduce(function (acc, _a) {
65
+ var key = _a[0], _case = _a[1];
66
+ var _reducer = typeof _case === 'function' ? _case : _case.reducer;
67
+ var newFunc = function (state, action) {
68
+ if (action && action.type === key) {
69
+ return _reducer(state, action);
70
+ }
71
+ return acc(state, action);
72
+ };
73
+ return newFunc;
74
+ }, function (state) {
75
+ if (state === void 0) { state = initialState; }
76
+ return state;
77
+ });
78
+ var actions = Object.entries(reducers).reduce(function (acc, _a) {
79
+ var key = _a[0], _case = _a[1];
80
+ acc[key] = function (payload) { return ({
81
+ type: key,
82
+ payload: payload
83
+ }); };
84
+ if (typeof _case !== 'function' && _case.effects) {
85
+ var effects = typeof _case.effects === 'function'
86
+ ? _case.effects
87
+ : (function () { return ({ effects: _case.effects }); });
88
+ acc[key] = addEffects(acc[key], effects);
89
+ }
90
+ return acc;
91
+ }, {});
92
+ return {
93
+ reducer: reducer,
94
+ actionCreators: actions
95
+ };
106
96
  };
107
97
 
108
- var jsonDiff = function (obj, newObj, options, _stack) {
109
- if (options === void 0) { options = { cyclesFix: true }; }
110
- if (_stack === void 0) { _stack = []; }
111
- var diffs = [];
112
- var isObjArray = Array.isArray(obj);
113
- var _loop_1 = function (key) {
114
- var objKey = obj[key];
115
- var path = isObjArray ? +key : key;
116
- if (!(key in newObj)) {
117
- diffs.push({
118
- type: 'REMOVE',
119
- path: [path],
120
- oldValue: obj[key]
121
- });
122
- return "continue";
123
- }
124
- var newObjKey = newObj[key];
125
- var areObjects = typeof objKey === 'object' && typeof newObjKey === 'object';
126
- if (objKey && newObjKey && areObjects && (!options.cyclesFix || !_stack.includes(objKey))) {
127
- var nestedDiffs = jsonDiff(objKey, newObjKey, options, options.cyclesFix ? _stack.concat([objKey]) : []);
128
- // eslint-disable-next-line prefer-spread
129
- diffs.push.apply(diffs, nestedDiffs.map(function (difference) {
130
- difference.path.unshift(path);
131
- return difference;
132
- }));
133
- }
134
- else if (objKey !== newObjKey &&
135
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
136
- //@ts-ignore
137
- !(areObjects && (isNaN(objKey) ? objKey + '' === newObjKey + '' : +objKey === +newObjKey))) {
138
- diffs.push({
139
- path: [path],
140
- type: 'CHANGE',
141
- value: newObjKey,
142
- oldValue: objKey
143
- });
144
- }
145
- };
146
- for (var key in obj) {
147
- _loop_1(key);
148
- }
149
- var isNewObjArray = Array.isArray(newObj);
150
- for (var key in newObj) {
151
- if (!(key in obj)) {
152
- diffs.push({
153
- type: 'CREATE',
154
- path: [isNewObjArray ? +key : key],
155
- value: newObj[key]
156
- });
157
- }
158
- }
159
- return diffs;
98
+ var jsonDiff = function (obj, newObj, options, _stack) {
99
+ if (options === void 0) { options = { cyclesFix: true }; }
100
+ if (_stack === void 0) { _stack = []; }
101
+ var diffs = [];
102
+ var isObjArray = Array.isArray(obj);
103
+ var _loop_1 = function (key) {
104
+ var objKey = obj[key];
105
+ var path = isObjArray ? +key : key;
106
+ if (!(key in newObj)) {
107
+ diffs.push({
108
+ type: 'REMOVE',
109
+ path: [path],
110
+ oldValue: obj[key]
111
+ });
112
+ return "continue";
113
+ }
114
+ var newObjKey = newObj[key];
115
+ var areObjects = typeof objKey === 'object' && typeof newObjKey === 'object';
116
+ if (objKey && newObjKey && areObjects && (!options.cyclesFix || !_stack.includes(objKey))) {
117
+ var nestedDiffs = jsonDiff(objKey, newObjKey, options, options.cyclesFix ? _stack.concat([objKey]) : []);
118
+ // eslint-disable-next-line prefer-spread
119
+ diffs.push.apply(diffs, nestedDiffs.map(function (difference) {
120
+ difference.path.unshift(path);
121
+ return difference;
122
+ }));
123
+ }
124
+ else if (objKey !== newObjKey &&
125
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
126
+ //@ts-ignore
127
+ !(areObjects && (isNaN(objKey) ? objKey + '' === newObjKey + '' : +objKey === +newObjKey))) {
128
+ diffs.push({
129
+ path: [path],
130
+ type: 'CHANGE',
131
+ value: newObjKey,
132
+ oldValue: objKey
133
+ });
134
+ }
135
+ };
136
+ for (var key in obj) {
137
+ _loop_1(key);
138
+ }
139
+ var isNewObjArray = Array.isArray(newObj);
140
+ for (var key in newObj) {
141
+ if (!(key in obj)) {
142
+ diffs.push({
143
+ type: 'CREATE',
144
+ path: [isNewObjArray ? +key : key],
145
+ value: newObj[key]
146
+ });
147
+ }
148
+ }
149
+ return diffs;
160
150
  };
161
151
 
162
- var getScopedEffectSignature = function (actionType, key) {
163
- return "type: ".concat(actionType, ", scoped: true").concat(key ? ",key:".concat(key) : '');
164
- };
165
- var HubFactory = function (_a) {
166
- var _b = _a === void 0 ? {} : _a, effects = _b.effects, _c = _b.sources, sources = _c === void 0 ? [] : _c;
167
- var dispatcher$ = new rxjs.ReplaySubject(1);
168
- var inputStream$ = rxjs.merge.apply(void 0, __spreadArray([dispatcher$], sources.map(function (source) { return source.pipe(operators.shareReplay(1)); }), false));
169
- var genericEffects = (effects === null || effects === void 0 ? void 0 : effects.reduce(function (result, effect) {
170
- return result.concat(inputStream$.pipe(effect));
171
- }, [])) || [];
172
- // Should we keep this in the stream with a scan operator instead?
173
- var scopedEffectsDict = {};
174
- var mergedScopedEffects = inputStream$.pipe(operators.filter(function (_a) {
175
- var type = _a.type, scopedEffects = _a.scopedEffects;
176
- var hasEffects = Boolean(scopedEffects && scopedEffects.effects.length);
177
- return (hasEffects &&
178
- scopedEffectsDict[getScopedEffectSignature(type, scopedEffects.key)] === undefined);
179
- }), operators.tap(function (_a) {
180
- var type = _a.type, _b = _a.scopedEffects, key = _b.key, effects = _b.effects;
181
- scopedEffectsDict[getScopedEffectSignature(type, key)] = effects;
182
- }), operators.map(function (_a) {
183
- var type = _a.type, _b = _a.scopedEffects, key = _b.key, effects = _b.effects;
184
- var signature = getScopedEffectSignature(type, key);
185
- var pipedEffects = effects.reduce(function (acc, effect) {
186
- return acc.concat(inputStream$.pipe(operators.filter(function (initialAction) {
187
- var _a;
188
- return getScopedEffectSignature(initialAction.type, (_a = initialAction.scopedEffects) === null || _a === void 0 ? void 0 : _a.key) ===
189
- signature;
190
- }), effect));
191
- }, []);
192
- return rxjs.merge.apply(void 0, pipedEffects);
193
- }), operators.mergeAll());
194
- var messages$ = rxjs.merge.apply(void 0, __spreadArray([inputStream$, mergedScopedEffects], genericEffects, false)).pipe(operators.share());
195
- var store = function (_a) {
196
- var reducer = _a.reducer, name = _a.name, debug = _a.debug, initialState = _a.initialState, _b = _a.storeValue, storeValue = _b === void 0 ? false : _b;
197
- var debugName = "[RX NAME] ".concat(name || 'undefined', "\n");
198
- var seedState = initialState !== undefined ? initialState : reducer();
199
- var state$ = messages$.pipe(operators.tap(function (action) {
200
- debug && console.log(debugName, '[ACTION]', action, '\n');
201
- }), operators.scan(reducer, seedState), operators.startWith(null, seedState), operators.pairwise(), operators.tap(function (_a) {
202
- var prevState = _a[0], newState = _a[1];
203
- if (debug) {
204
- if (prevState &&
205
- typeof prevState === 'object' &&
206
- newState &&
207
- typeof newState === 'object') {
208
- try {
209
- var reduceDiff = function (diff) {
210
- return diff.reduce(function (acc, change) {
211
- var _a;
212
- return (__assign(__assign({}, acc), (_a = {}, _a[change.path.join('|')] = change, _a)));
213
- }, {});
214
- };
215
- var difference = reduceDiff(jsonDiff(prevState, newState));
216
- console.log(debugName, '[DIFF]', Object.keys(difference).length ? difference : null, '\n', '[STATE]', newState, '\n');
217
- }
218
- catch (e) {
219
- console.log('[ERROR READING DIFF]', e, '\n', '[STATE]', newState);
220
- }
221
- }
222
- else {
223
- var hasDiff = prevState !== newState;
224
- console.log(debugName, '[DIFF]', hasDiff
225
- ? {
226
- oldValue: prevState,
227
- newValue: newState
228
- }
229
- : null, '\n', '[STATE]', newState);
230
- }
231
- }
232
- }), operators.map(function (pair) { return pair[1]; }));
233
- if (storeValue) {
234
- var replaySubject_1 = new rxjs.ReplaySubject(1);
235
- state$.subscribe(function (state) { return replaySubject_1.next(state); });
236
- return replaySubject_1;
237
- }
238
- return state$;
239
- };
240
- return {
241
- messages$: messages$,
242
- store: store,
243
- dispatch: function () {
244
- var actions = [];
245
- for (var _i = 0; _i < arguments.length; _i++) {
246
- actions[_i] = arguments[_i];
247
- }
248
- actions.forEach(function (action) {
249
- dispatcher$.next(action);
250
- });
251
- }
252
- };
253
- };
152
+ var ofTypes = function (types) { return function (dispatcher$) {
153
+ return dispatcher$.pipe(filter(function (_a) {
154
+ var type = _a.type;
155
+ return types.includes(type);
156
+ }));
157
+ }; };
254
158
 
255
- /**
256
- * @description helper method to create an action type string map for a combined reacatable
257
- */
258
- var combineActionTypeStringMaps = function (sourceReactables) {
259
- var result = Object.entries(sourceReactables).reduce(function (acc, _a) {
260
- var key = _a[0], _b = _a[1], actions$ = _b[2];
261
- return __assign(__assign({}, acc), createActionTypeStringMap(actions$.types, key));
262
- }, {});
263
- return result;
264
- };
265
- /**
266
- * @description creates an action type string map from existing string maps or an ActionMap,
267
- * if given a parent key it will append a prefix to the resulting strings
268
- */
269
- var createActionTypeStringMap = function (types, parentKey) {
270
- return Object.keys(types).reduce(function (acc, childKey) {
271
- var _a;
272
- var newKey = parentKey ? "[".concat(parentKey, "] - ").concat(childKey) : childKey;
273
- return __assign(__assign({}, acc), (_a = {}, _a[newKey] = newKey, _a));
274
- }, {});
159
+ /**
160
+ * @description helper method to create an action type string map for a combined reacatable
161
+ */
162
+ var combineActionTypeStringMaps = function (sourceReactables) {
163
+ var result = Object.entries(sourceReactables).reduce(function (acc, _a) {
164
+ var key = _a[0], _b = _a[1], actions$ = _b[2];
165
+ return __assign(__assign({}, acc), createActionTypeStringMap(actions$.types, key));
166
+ }, {});
167
+ return result;
275
168
  };
276
-
277
- var RxBuilder = function (_a) {
278
- var effects = _a.effects, _b = _a.sources, sources = _b === void 0 ? [] : _b, _c = _a.debug, debug = _c === void 0 ? false : _c, _d = _a.storeValue, storeValue = _d === void 0 ? false : _d, sliceConfig = __rest(_a, ["effects", "sources", "debug", "storeValue"]);
279
- var _e = createSlice(sliceConfig), reducer = _e.reducer, actions = _e.actions;
280
- // Check sources and see if need to add effects
281
- if (!Array.isArray(sources)) {
282
- sources = Object.entries(sources).map(function (_a) {
283
- var key = _a[0], obs$ = _a[1];
284
- return obs$.pipe(operators.map(function (value) { return ({ type: key, payload: value }); }));
285
- });
286
- }
287
- sources = sources.map(function (action$) {
288
- return action$.pipe(operators.map(function (action) {
289
- var _case = sliceConfig.reducers[action.type];
290
- if (_case && typeof _case !== 'function' && _case.effects) {
291
- var effects_1 = typeof _case.effects === 'function'
292
- ? _case.effects
293
- : (function () { return ({ effects: _case.effects }); });
294
- return __assign(__assign({}, action), { scopedEffects: effects_1(action.payload) });
295
- }
296
- return action;
297
- }));
298
- });
299
- var hub = HubFactory({ effects: effects, sources: sources });
300
- var actionsResult = Object.fromEntries(Object.entries(actions).map(function (_a) {
301
- var key = _a[0], actionCreator = _a[1];
302
- return [
303
- key,
304
- function (payload) {
305
- hub.dispatch(actionCreator(payload));
306
- },
307
- ];
308
- }));
309
- createActionTypeStringMap(actions);
310
- var actions$ = hub.messages$;
311
- actions$.types = createActionTypeStringMap(actions);
312
- actions$.ofTypes = function (types) { return actions$.pipe(ofTypes(types)); };
313
- var rx = [
314
- hub.store({ reducer: reducer, debug: debug, storeValue: storeValue, name: sliceConfig.name }),
315
- actionsResult,
316
- actions$,
317
- ];
318
- return rx;
169
+ /**
170
+ * @description creates an action type string map from existing string maps or an ActionMap,
171
+ * if given a parent key it will append a prefix to the resulting strings
172
+ */
173
+ var createActionTypeStringMap = function (types, parentKey) {
174
+ return Object.keys(types).reduce(function (acc, childKey) {
175
+ var _a;
176
+ var newKey = parentKey ? "[".concat(parentKey, "] - ").concat(childKey) : childKey;
177
+ return __assign(__assign({}, acc), (_a = {}, _a[newKey] = newKey, _a));
178
+ }, {});
319
179
  };
320
180
 
321
- var storeValue = function (reactable) {
322
- var replaySubject$ = new rxjs.ReplaySubject(1);
323
- var state$ = reactable[0], actions = reactable[1], actions$ = reactable[2];
324
- var subscription = state$.subscribe(function (state) { return replaySubject$.next(state); });
325
- var destroy = function () { return subscription.unsubscribe(); };
326
- return [replaySubject$, __assign(__assign({}, actions), { destroy: destroy }), actions$];
181
+ var getScopedEffectSignature = function (actionType, key) {
182
+ return "type: ".concat(actionType, ", scoped: true").concat(key ? ",key:".concat(key) : '');
183
+ };
184
+ var RxBuilder = function (_a) {
185
+ var _b = _a.sources, sources = _b === void 0 ? [] : _b, _c = _a.debug, debug = _c === void 0 ? false : _c, sliceConfig = __rest(_a, ["sources", "debug"]);
186
+ /**
187
+ * CREATE MAIN REDUCER AND ACTION CREATORS
188
+ */
189
+ var _d = createSlice(sliceConfig), reducer = _d.reducer, actionCreators = _d.actionCreators;
190
+ // Add effects to incoming source actions
191
+ sources = sources.map(function (action$) {
192
+ return action$.pipe(map(function (action) {
193
+ var _case = sliceConfig.reducers[action.type];
194
+ if (_case && typeof _case !== 'function' && _case.effects) {
195
+ var effects = typeof _case.effects === 'function'
196
+ ? _case.effects
197
+ : (function () { return ({ effects: _case.effects }); });
198
+ return __assign(__assign({}, action), { scopedEffects: effects(action.payload) });
199
+ }
200
+ return action;
201
+ }));
202
+ });
203
+ /**
204
+ * CREATE HUB AND STORE
205
+ */
206
+ // Teardown subject
207
+ var destroy$ = new Subject();
208
+ // Dispatcher for the UI to push state updates
209
+ var dispatcher$ = new ReplaySubject(1);
210
+ // All incoming actions
211
+ var incomingActions$ = merge.apply(void 0, __spreadArray([dispatcher$], sources.map(function (source) { return source.pipe(takeUntil(destroy$), shareReplay(1)); }), false));
212
+ // Dictionary of effects scoped to actions & key (if provided)
213
+ var scopedEffectsDict = {};
214
+ // Registers scoped effects to the dictionary.
215
+ var mergedScopedEffects$ = incomingActions$.pipe(
216
+ // Listen for scoped effects not yet registered in "scopedEffectsDict"
217
+ filter(function (_a) {
218
+ var type = _a.type, scopedEffects = _a.scopedEffects;
219
+ var hasEffects = Boolean(scopedEffects && scopedEffects.effects.length);
220
+ return (hasEffects &&
221
+ scopedEffectsDict[getScopedEffectSignature(type, scopedEffects.key)] === undefined);
222
+ }),
223
+ // Register the new scoped effect
224
+ tap(function (_a) {
225
+ var type = _a.type, _b = _a.scopedEffects, key = _b.key, effects = _b.effects;
226
+ scopedEffectsDict[getScopedEffectSignature(type, key)] = effects;
227
+ }),
228
+ // Once effects are registered, merge them into the `mergeScopedEffects$` stream for the store to receive.
229
+ map(function (_a) {
230
+ var type = _a.type, _b = _a.scopedEffects, key = _b.key, effects = _b.effects;
231
+ var signature = getScopedEffectSignature(type, key);
232
+ var pipedEffects = effects.reduce(function (acc, effect) {
233
+ return acc.concat(incomingActions$.pipe(filter(function (initialAction) {
234
+ var _a;
235
+ return getScopedEffectSignature(initialAction.type, (_a = initialAction.scopedEffects) === null || _a === void 0 ? void 0 : _a.key) ===
236
+ signature;
237
+ }), effect));
238
+ }, []);
239
+ return merge.apply(void 0, pipedEffects);
240
+ }), mergeAll());
241
+ var debugName = "[RX NAME] ".concat(sliceConfig.name || 'undefined', "\n");
242
+ var seedState = sliceConfig.initialState !== undefined ? sliceConfig.initialState : reducer();
243
+ // All actions received by the store
244
+ var mergedActions$ = merge(incomingActions$, mergedScopedEffects$).pipe(share());
245
+ // State updates
246
+ var stateEvents$ = mergedActions$.pipe(tap(function (action) {
247
+ debug &&
248
+ console.log(debugName, '[ACTION]', { type: action.type, payload: action.payload }, '\n');
249
+ }), scan(reducer, seedState), startWith(null, seedState), pairwise(), tap(function (_a) {
250
+ var prevState = _a[0], newState = _a[1];
251
+ // Debug Logging
252
+ if (debug) {
253
+ if (prevState &&
254
+ typeof prevState === 'object' &&
255
+ newState &&
256
+ typeof newState === 'object') {
257
+ try {
258
+ var reduceDiff = function (diff) {
259
+ return diff.reduce(function (acc, change) {
260
+ var _a;
261
+ return (__assign(__assign({}, acc), (_a = {}, _a[change.path.join('|')] = change, _a)));
262
+ }, {});
263
+ };
264
+ var difference = reduceDiff(jsonDiff(prevState, newState));
265
+ console.log(debugName, '[STATE]', newState, '\n', '[DIFF]', Object.keys(difference).length ? difference : null, '\n');
266
+ }
267
+ catch (e) {
268
+ console.log('[ERROR READING DIFF]', e, '\n', '[STATE]', newState);
269
+ }
270
+ }
271
+ else {
272
+ var hasDiff = prevState !== newState;
273
+ try {
274
+ console.log(debugName, '\n', '[STATE]', newState, '[DIFF]', hasDiff
275
+ ? {
276
+ oldValue: prevState,
277
+ newValue: newState
278
+ }
279
+ : null);
280
+ }
281
+ catch (e) {
282
+ console.log('[ERROR READING DIFF]', e, '\n', '[STATE]', newState);
283
+ }
284
+ }
285
+ }
286
+ }), map(function (pair) { return pair[1]; }));
287
+ var storedState$ = new ReplaySubject(1);
288
+ stateEvents$.pipe(takeUntil(destroy$)).subscribe(function (state) { return storedState$.next(state); });
289
+ // Action methods for the UI to invoke state changes
290
+ var actions = __assign(__assign({}, Object.fromEntries(Object.entries(actionCreators).map(function (_a) {
291
+ var key = _a[0], actionCreator = _a[1];
292
+ return [
293
+ key,
294
+ function (payload) {
295
+ dispatcher$.next(actionCreator(payload));
296
+ },
297
+ ];
298
+ }))), {
299
+ // Destroy method to teardown reactable
300
+ destroy: function () {
301
+ destroy$.next();
302
+ destroy$.complete();
303
+ } });
304
+ var types = createActionTypeStringMap(actions);
305
+ var actions$ = mergedActions$;
306
+ actions$.types = types;
307
+ actions$.ofTypes = function (types) { return actions$.pipe(ofTypes(types)); };
308
+ return [storedState$, actions, actions$];
327
309
  };
328
310
 
329
- var combine = function (sourceReactables) {
330
- var _a = Object.entries(sourceReactables).reduce(function (acc, _a) {
331
- var _b, _c;
332
- var key = _a[0], _d = _a[1], state$ = _d[0], actions = _d[1], actions$ = _d[2];
333
- return {
334
- states: __assign(__assign({}, acc.states), (_b = {}, _b[key] = state$, _b)),
335
- actions: __assign(__assign({}, acc.actions), (_c = {}, _c[key] = actions, _c)),
336
- actions$: actions$
337
- ? acc.actions$.concat(actions$.pipe(operators.map(function (action) { return (__assign(__assign({}, action), { type: "[".concat(key, "] - ").concat(action.type) })); })))
338
- : acc.actions$
339
- };
340
- }, {
341
- states: {},
342
- actions: {},
343
- actions$: []
344
- }), states = _a.states, actions = _a.actions, actions$ = _a.actions$;
345
- var states$ = rxjs.combineLatest(states);
346
- var actionTypes = combineActionTypeStringMaps(sourceReactables);
347
- var mergedActions$ = rxjs.merge.apply(void 0, actions$);
348
- mergedActions$.types = actionTypes;
349
- mergedActions$.ofTypes = function (types) { return mergedActions$.pipe(ofTypes(types)); };
350
- return [states$, actions, mergedActions$];
311
+ var combine = function (sourceReactables) {
312
+ var _a = Object.entries(sourceReactables).reduce(function (acc, _a) {
313
+ var _b, _c;
314
+ var key = _a[0], _d = _a[1], state$ = _d[0], actions = _d[1], actions$ = _d[2];
315
+ var destroy = function () {
316
+ actions.destroy();
317
+ acc.actions.destroy();
318
+ };
319
+ return {
320
+ states: __assign(__assign({}, acc.states), (_b = {}, _b[key] = state$, _b)),
321
+ actions: __assign(__assign({}, acc.actions), (_c = {}, _c[key] = actions, _c.destroy = destroy, _c)),
322
+ actions$: actions$
323
+ ? acc.actions$.concat(actions$.pipe(map(function (action) { return (__assign(__assign({}, action), { type: "[".concat(key, "] - ").concat(action.type) })); })))
324
+ : acc.actions$
325
+ };
326
+ }, {
327
+ states: {},
328
+ actions: {
329
+ destroy: function () {
330
+ }
331
+ },
332
+ actions$: []
333
+ }), states = _a.states, actions = _a.actions, actions$ = _a.actions$;
334
+ var states$ = combineLatest(states);
335
+ var actionTypes = combineActionTypeStringMaps(sourceReactables);
336
+ var mergedActions$ = merge.apply(void 0, actions$);
337
+ mergedActions$.types = actionTypes;
338
+ mergedActions$.ofTypes = function (types) { return mergedActions$.pipe(ofTypes(types)); };
339
+ return [states$, actions, mergedActions$];
351
340
  };
352
341
 
353
- exports.RxBuilder = RxBuilder;
354
- exports.combine = combine;
355
- exports.ofTypes = ofTypes;
356
- exports.storeValue = storeValue;
342
+ export { RxBuilder, combine, ofTypes };
343
+ //# sourceMappingURL=index.js.map