@reactables/core 1.3.0-alpha.3 → 1.3.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/Helpers/RxBuilder.d.ts +3 -3
- package/dist/Helpers/RxBuilder.test.d.ts +1 -0
- package/dist/Helpers/combine.d.ts +3 -2
- package/dist/Helpers/createActionTypeStringMap.d.ts +30 -0
- package/dist/Helpers/storeValue.d.ts +1 -3
- package/dist/Models/Reactable.d.ts +10 -1
- package/dist/Models/index.d.ts +1 -1
- package/dist/index.js +36 -9
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { SliceConfig, Cases } from './createSlice';
|
|
3
|
-
import { Reactable } from '../Models/Reactable';
|
|
3
|
+
import { Reactable, ActionCreatorTypeFromReducer } from '../Models/Reactable';
|
|
4
4
|
import { Effect } from '../Models/Effect';
|
|
5
5
|
import { Action } from '../Models/Action';
|
|
6
6
|
export interface EffectsAndSources {
|
|
@@ -11,7 +11,7 @@ export interface EffectsAndSources {
|
|
|
11
11
|
}
|
|
12
12
|
export interface RxConfig<T, S extends Cases<T>> extends SliceConfig<T, S>, EffectsAndSources {
|
|
13
13
|
debug?: boolean;
|
|
14
|
-
/**@deprecated Use storeValue
|
|
14
|
+
/**@deprecated Use storeValue modifier instead to add store value behaviour to reactable */
|
|
15
15
|
storeValue?: boolean;
|
|
16
16
|
}
|
|
17
|
-
export declare const RxBuilder: <T, S extends Cases<T>>({ effects, sources, debug, storeValue, ...sliceConfig }: RxConfig<T, S>) => Reactable<T, { [K in keyof S]: (
|
|
17
|
+
export declare const RxBuilder: <T, S extends Cases<T>>({ effects, sources, debug, storeValue, ...sliceConfig }: RxConfig<T, S>) => Reactable<T, { [K in keyof S]: ActionCreatorTypeFromReducer<S[K]>; }, { [K_2 in keyof S]: import("../Models/Action").ActionCreator<unknown>; } extends infer T_1 extends Record<string, unknown> ? { [K_1 in keyof T_1 as `${string & K_1}`]: `${string & K_1}`; } : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Observable, ObservedValueOf } from 'rxjs';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Reactable } from '../Models';
|
|
3
|
+
import { ActionObservableWithTypes } from '../Models/Reactable';
|
|
4
|
+
export declare const combine: <T extends Record<string, Reactable<unknown, unknown, Record<string, string>>>>(sourceReactables: T) => [Observable<{ [K in keyof T]: ObservedValueOf<T[K][0]>; }>, { [K_1 in keyof T]: T[K_1][1]; }, ActionObservableWithTypes<{ [K_4 in ({ [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; } extends infer T_1 ? { [K_2 in keyof T_1]: { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] extends Record<string, any> ? { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] : never; } : never)[keyof T] extends infer T_2 ? T_2 extends ({ [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; } extends infer T_1 ? { [K_2 in keyof T_1]: { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] extends Record<string, any> ? { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] : never; } : never)[keyof T] ? T_2 extends any ? keyof T_2 : never : never : never]: ({ [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; } extends infer T_1 ? { [K_2 in keyof T_1]: { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] extends Record<string, any> ? { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] : never; } : never)[keyof T] extends infer T_3 ? T_3 extends ({ [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; } extends infer T_1 ? { [K_2 in keyof T_1]: { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] extends Record<string, any> ? { [K_3 in keyof T]: T[K_3] extends Reactable<unknown, unknown, infer P extends Record<string, string>> ? { [Pkey in keyof P as `[${K_3 & string}] - ${Pkey & string}`]: `[${K_3 & string}] - ${Pkey & string}`; } : never; }[K_2] : never; } : never)[keyof T] ? T_3 extends { [k in K_4]?: any; } ? T_3[K_4] : never : never : never; }>];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Reactable } from '../Models';
|
|
2
|
+
type ExpandedMap<T extends Record<string, Reactable<unknown, unknown>>> = {
|
|
3
|
+
[K in keyof T]: T[K] extends Reactable<unknown, unknown, infer P> ? {
|
|
4
|
+
[Pkey in keyof P as `[${K & string}] - ${Pkey & string}`]: `[${K & string}] - ${Pkey & string}`;
|
|
5
|
+
} : never;
|
|
6
|
+
};
|
|
7
|
+
type Merge<U> = {
|
|
8
|
+
[K in U extends any ? keyof U : never]: U extends {
|
|
9
|
+
[k in K]?: any;
|
|
10
|
+
} ? U[K] : never;
|
|
11
|
+
};
|
|
12
|
+
type FlattenedEntries<T> = Merge<{
|
|
13
|
+
[K in keyof T]: T[K] extends Record<string, any> ? T[K] : never;
|
|
14
|
+
}[keyof T]>;
|
|
15
|
+
type CombinedActionStringMap<T extends Record<string, Reactable<unknown, unknown>>> = FlattenedEntries<ExpandedMap<T>>;
|
|
16
|
+
/**
|
|
17
|
+
* @description helper method to create an action type string map for a combined reacatable
|
|
18
|
+
*/
|
|
19
|
+
export declare const combineActionTypeStringMaps: <T extends Record<string, Reactable<unknown, unknown, Record<string, string>>>>(sourceReactables: T) => CombinedActionStringMap<T>;
|
|
20
|
+
export type ActionTypeString<S extends Record<string, unknown>, Z extends string> = Z extends undefined ? {
|
|
21
|
+
[K in keyof S as `${string & K}`]: `${string & K}`;
|
|
22
|
+
} : {
|
|
23
|
+
[K in keyof S as `[${Z}] - ${string & K}`]: `[${Z}] - ${string & K}`;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @description creates an action type string map from existing string maps or an ActionMap,
|
|
27
|
+
* if given a parent key it will append a prefix to the resulting strings
|
|
28
|
+
*/
|
|
29
|
+
export declare const createActionTypeStringMap: <S extends Record<string, unknown>, Z extends string = undefined>(types: S, parentKey?: Z) => ActionTypeString<S, Z>;
|
|
30
|
+
export {};
|
|
@@ -2,6 +2,4 @@ import { Reactable } from '../Models';
|
|
|
2
2
|
export interface DestroyAction {
|
|
3
3
|
destroy: () => void;
|
|
4
4
|
}
|
|
5
|
-
export declare const storeValue: <T, S>(reactable: Reactable<T, S &
|
|
6
|
-
destroy?: () => void;
|
|
7
|
-
}>) => Reactable<T, S & DestroyAction>;
|
|
5
|
+
export declare const storeValue: <T, S, U extends Record<string, string> = Record<string, string>>(reactable: Reactable<T, S, U>) => Reactable<T, S & DestroyAction, U>;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { Action } from './Action';
|
|
3
|
-
export type
|
|
3
|
+
export type ActionCreatorTypeFromReducer<T> = T extends (state: any) => unknown ? () => void : T extends (state: any, action: Action<infer P>) => unknown ? (payload: P) => void : T extends {
|
|
4
|
+
reducer: (state: any) => unknown;
|
|
5
|
+
} ? () => void : T extends {
|
|
6
|
+
reducer: (state: any, action: Action<infer P>) => unknown;
|
|
7
|
+
} ? (payload: P) => void : never;
|
|
8
|
+
export type ActionObservableWithTypes<T extends Record<string, string>> = Observable<Action<unknown>> & {
|
|
9
|
+
types?: T;
|
|
10
|
+
ofTypes?: (types: Array<keyof T>) => Observable<Action<unknown>>;
|
|
11
|
+
};
|
|
12
|
+
export type Reactable<T, S = ActionMap, U extends Record<string, string> = Record<string, string>> = [Observable<T>, S, ActionObservableWithTypes<U>?];
|
|
4
13
|
export interface ActionMap {
|
|
5
14
|
[key: string | number]: (payload?: unknown) => void | ActionMap;
|
|
6
15
|
}
|
package/dist/Models/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Action, ScopedEffects } from './Action';
|
|
2
2
|
export { Effect } from './Effect';
|
|
3
3
|
export { Hub, Reducer, HubConfig, StoreConfig, Dispatcher } from './Hub';
|
|
4
|
-
export { Reactable, ActionMap } from './Reactable';
|
|
4
|
+
export { Reactable, ActionMap, ActionObservableWithTypes } from './Reactable';
|
package/dist/index.js
CHANGED
|
@@ -252,6 +252,28 @@ var HubFactory = function (_a) {
|
|
|
252
252
|
};
|
|
253
253
|
};
|
|
254
254
|
|
|
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
|
+
}, {});
|
|
275
|
+
};
|
|
276
|
+
|
|
255
277
|
var RxBuilder = function (_a) {
|
|
256
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"]);
|
|
257
279
|
var _e = createSlice(sliceConfig), reducer = _e.reducer, actions = _e.actions;
|
|
@@ -284,23 +306,24 @@ var RxBuilder = function (_a) {
|
|
|
284
306
|
},
|
|
285
307
|
];
|
|
286
308
|
}));
|
|
287
|
-
|
|
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 = [
|
|
288
314
|
hub.store({ reducer: reducer, debug: debug, storeValue: storeValue, name: sliceConfig.name }),
|
|
289
315
|
actionsResult,
|
|
290
|
-
|
|
316
|
+
actions$,
|
|
291
317
|
];
|
|
318
|
+
return rx;
|
|
292
319
|
};
|
|
293
320
|
|
|
294
321
|
var storeValue = function (reactable) {
|
|
295
322
|
var replaySubject$ = new rxjs.ReplaySubject(1);
|
|
296
323
|
var state$ = reactable[0], actions = reactable[1], actions$ = reactable[2];
|
|
297
324
|
var subscription = state$.subscribe(function (state) { return replaySubject$.next(state); });
|
|
298
|
-
var destroy = function () {
|
|
299
|
-
|
|
300
|
-
subscription.unsubscribe();
|
|
301
|
-
};
|
|
302
|
-
actions.destroy = destroy;
|
|
303
|
-
return [replaySubject$, actions, actions$];
|
|
325
|
+
var destroy = function () { return subscription.unsubscribe(); };
|
|
326
|
+
return [replaySubject$, __assign(__assign({}, actions), { destroy: destroy }), actions$];
|
|
304
327
|
};
|
|
305
328
|
|
|
306
329
|
var combine = function (sourceReactables) {
|
|
@@ -320,7 +343,11 @@ var combine = function (sourceReactables) {
|
|
|
320
343
|
actions$: []
|
|
321
344
|
}), states = _a.states, actions = _a.actions, actions$ = _a.actions$;
|
|
322
345
|
var states$ = rxjs.combineLatest(states);
|
|
323
|
-
|
|
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$];
|
|
324
351
|
};
|
|
325
352
|
|
|
326
353
|
exports.RxBuilder = RxBuilder;
|
package/package.json
CHANGED