@fluid-topics/ft-wc-utils 1.4.4 → 1.4.5
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.
|
@@ -16,6 +16,7 @@ export declare class FtReduxStore<State = any, CR extends SliceCaseReducers<Stat
|
|
|
16
16
|
readonly commands: FtCommandQueue;
|
|
17
17
|
private constructor();
|
|
18
18
|
clear(): void;
|
|
19
|
+
clearKeeping(...keys: Array<keyof State>): void;
|
|
19
20
|
setState(state: Partial<State>): void;
|
|
20
21
|
get dispatch(): Dispatch<A>;
|
|
21
22
|
[Symbol.observable](): Observable<any>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { configureStore, createSlice } from "@reduxjs/toolkit";
|
|
2
|
-
import { isFtReduxStore } from "./models";
|
|
1
|
+
import { configureStore, createSlice, } from "@reduxjs/toolkit";
|
|
2
|
+
import { isFtReduxStore, } from "./models";
|
|
3
3
|
import { FtCommandQueue } from "./FtCommandQueue";
|
|
4
4
|
import { WithEventBus } from "../events";
|
|
5
|
+
import { deepCopy } from "../helpers";
|
|
5
6
|
if (!window.ftReduxStores) {
|
|
6
7
|
window.ftReduxStores = {};
|
|
7
8
|
}
|
|
@@ -19,18 +20,22 @@ export class FtReduxStore extends WithEventBus {
|
|
|
19
20
|
}
|
|
20
21
|
const reduxSlice = createSlice({
|
|
21
22
|
...options,
|
|
22
|
-
reducers: (_a = options.reducers) !== null && _a !== void 0 ? _a : {}
|
|
23
|
+
reducers: (_a = options.reducers) !== null && _a !== void 0 ? _a : {},
|
|
23
24
|
});
|
|
24
25
|
const reduxStore = configureStore({
|
|
25
26
|
reducer: (state, action) => {
|
|
26
27
|
if (action.type === "CLEAR_FT_REDUX_STORE") {
|
|
27
|
-
|
|
28
|
+
const initialState = deepCopy(reduxSlice.getInitialState());
|
|
29
|
+
for (const key of action.keeping) {
|
|
30
|
+
initialState[key] = (state !== null && state !== void 0 ? state : initialState)[key];
|
|
31
|
+
}
|
|
32
|
+
return initialState;
|
|
28
33
|
}
|
|
29
34
|
else if (typeof action.type === "string" && action.type.startsWith("DEFAULT_VALUE_SETTER__")) {
|
|
30
35
|
return { ...state, ...(action.overwrites) };
|
|
31
36
|
}
|
|
32
37
|
return reduxSlice.reducer(state, action);
|
|
33
|
-
}
|
|
38
|
+
},
|
|
34
39
|
});
|
|
35
40
|
return window.ftReduxStores[options.name] = new FtReduxStore(reduxSlice, reduxStore, options.eventBus);
|
|
36
41
|
}
|
|
@@ -58,17 +63,20 @@ export class FtReduxStore extends WithEventBus {
|
|
|
58
63
|
this.setState({ [actionName]: deepCopy(stateFieldValue) });
|
|
59
64
|
};
|
|
60
65
|
}
|
|
61
|
-
}
|
|
66
|
+
},
|
|
62
67
|
});
|
|
63
68
|
this.eventBus = eventBus !== null && eventBus !== void 0 ? eventBus : this.eventBus;
|
|
64
69
|
}
|
|
65
70
|
clear() {
|
|
66
|
-
this.reduxStore.dispatch({ type: "CLEAR_FT_REDUX_STORE" });
|
|
71
|
+
this.reduxStore.dispatch({ type: "CLEAR_FT_REDUX_STORE", keeping: [] });
|
|
72
|
+
}
|
|
73
|
+
clearKeeping(...keys) {
|
|
74
|
+
this.reduxStore.dispatch({ type: "CLEAR_FT_REDUX_STORE", keeping: keys });
|
|
67
75
|
}
|
|
68
76
|
setState(state) {
|
|
69
77
|
this.reduxStore.dispatch({
|
|
70
78
|
type: "DEFAULT_VALUE_SETTER__" + Object.keys(state).join("_"),
|
|
71
|
-
overwrites: state
|
|
79
|
+
overwrites: state,
|
|
72
80
|
});
|
|
73
81
|
}
|
|
74
82
|
// Implement Store
|
|
@@ -102,7 +110,7 @@ export class FtReduxStore extends WithEventBus {
|
|
|
102
110
|
}
|
|
103
111
|
export function clearAllStores() {
|
|
104
112
|
var _a;
|
|
105
|
-
for (
|
|
113
|
+
for (const store of Object.values((_a = window.ftReduxStores) !== null && _a !== void 0 ? _a : {})) {
|
|
106
114
|
if (isFtReduxStore(store)) {
|
|
107
115
|
store.clear();
|
|
108
116
|
}
|
package/build/redux/models.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export type DefaultValueSetterAction<State = any> = {
|
|
|
23
23
|
type: string;
|
|
24
24
|
overwrites: Partial<State>;
|
|
25
25
|
};
|
|
26
|
-
export type DefaultClearStoreAction = {
|
|
26
|
+
export type DefaultClearStoreAction<State = any> = {
|
|
27
27
|
type: "CLEAR_FT_REDUX_STORE";
|
|
28
|
+
keeping: Array<keyof State>;
|
|
28
29
|
};
|
|
29
30
|
declare const emptyReducers: {};
|
|
30
31
|
export type EmptyReducers = typeof emptyReducers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-wc-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Internal web components tools",
|
|
5
5
|
"author": "Fluid Topics <devtopics@antidot.net>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"mark.js": "8.11.1",
|
|
25
25
|
"moment": "2.29.4"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "efdc859657751cd9e7af2736f3783341ffd6aae4"
|
|
28
28
|
}
|