@coaction/redux 1.5.0 → 2.0.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/README.md +2 -2
- package/dist/index.d.mts +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/index.js +121 -138
- package/dist/index.mjs +109 -136
- package/package.json +30 -38
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @coaction/redux
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
[](https://www.npmjs.com/package/@coaction/redux)
|
|
5
5
|

|
|
6
6
|
|
|
@@ -51,4 +51,4 @@ store.getState().dispatch(counterSlice.actions.increment());
|
|
|
51
51
|
|
|
52
52
|
## Documentation
|
|
53
53
|
|
|
54
|
-
You can find the documentation [here](https://github.com/
|
|
54
|
+
You can find the documentation [here](https://github.com/coactionjs/coaction).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { AnyAction,
|
|
2
|
-
export * from
|
|
1
|
+
import { AnyAction, Reducer, Store } from "@reduxjs/toolkit";
|
|
2
|
+
export * from "@reduxjs/toolkit";
|
|
3
3
|
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/coaction-redux/src/index.d.ts
|
|
4
7
|
declare const COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
5
8
|
type ReplaceStateAction<S> = {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
type: typeof COACTION_REDUX_REPLACE;
|
|
10
|
+
payload: S;
|
|
8
11
|
};
|
|
9
12
|
declare function replaceStateAction<S>(payload: S): ReplaceStateAction<S>;
|
|
10
13
|
declare const withCoactionReducer: <S, A extends AnyAction = AnyAction>(reducer: Reducer<S, A>) => Reducer<S, A | ReplaceStateAction<S>>;
|
|
11
14
|
type BoundReduxStore<S extends object, A extends AnyAction> = Store<S, A> & {
|
|
12
|
-
|
|
15
|
+
getState: () => BoundReduxState<S, A>;
|
|
13
16
|
};
|
|
14
17
|
type BoundReduxState<S extends object, A extends AnyAction> = S & {
|
|
15
|
-
|
|
18
|
+
dispatch: Store<S, A>['dispatch'];
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* Bind a redux toolkit store to coaction.
|
|
@@ -23,5 +26,8 @@ declare const bindRedux: <S extends object, A extends AnyAction = AnyAction>(red
|
|
|
23
26
|
*/
|
|
24
27
|
declare function adapt<T extends object, A extends AnyAction = AnyAction>(store: BoundReduxStore<T, A>): BoundReduxState<T, A>;
|
|
25
28
|
declare function adapt<T extends object>(store: Store<T>): T;
|
|
26
|
-
|
|
27
|
-
export { COACTION_REDUX_REPLACE,
|
|
29
|
+
declare namespace index_d_exports {
|
|
30
|
+
export { COACTION_REDUX_REPLACE, ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { COACTION_REDUX_REPLACE, ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { AnyAction,
|
|
2
|
-
export * from
|
|
1
|
+
import { AnyAction, Reducer, Store } from "@reduxjs/toolkit";
|
|
2
|
+
export * from "@reduxjs/toolkit";
|
|
3
3
|
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/coaction-redux/src/index.d.ts
|
|
4
7
|
declare const COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
5
8
|
type ReplaceStateAction<S> = {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
type: typeof COACTION_REDUX_REPLACE;
|
|
10
|
+
payload: S;
|
|
8
11
|
};
|
|
9
12
|
declare function replaceStateAction<S>(payload: S): ReplaceStateAction<S>;
|
|
10
13
|
declare const withCoactionReducer: <S, A extends AnyAction = AnyAction>(reducer: Reducer<S, A>) => Reducer<S, A | ReplaceStateAction<S>>;
|
|
11
14
|
type BoundReduxStore<S extends object, A extends AnyAction> = Store<S, A> & {
|
|
12
|
-
|
|
15
|
+
getState: () => BoundReduxState<S, A>;
|
|
13
16
|
};
|
|
14
17
|
type BoundReduxState<S extends object, A extends AnyAction> = S & {
|
|
15
|
-
|
|
18
|
+
dispatch: Store<S, A>['dispatch'];
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* Bind a redux toolkit store to coaction.
|
|
@@ -23,5 +26,8 @@ declare const bindRedux: <S extends object, A extends AnyAction = AnyAction>(red
|
|
|
23
26
|
*/
|
|
24
27
|
declare function adapt<T extends object, A extends AnyAction = AnyAction>(store: BoundReduxStore<T, A>): BoundReduxState<T, A>;
|
|
25
28
|
declare function adapt<T extends object>(store: Store<T>): T;
|
|
26
|
-
|
|
27
|
-
export { COACTION_REDUX_REPLACE,
|
|
29
|
+
declare namespace index_d_exports {
|
|
30
|
+
export { COACTION_REDUX_REPLACE, ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { COACTION_REDUX_REPLACE, ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
|
package/dist/index.js
CHANGED
|
@@ -1,147 +1,130 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#endregion
|
|
3
|
+
let coaction = require("coaction");
|
|
4
|
+
//#region packages/coaction-redux/src/index.ts
|
|
5
|
+
const COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
6
|
+
const isUnsafeKey = (key) => typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
7
|
+
const getOwnEnumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
8
|
+
const isArrayIndexKey = (key) => {
|
|
9
|
+
if (typeof key !== "string") return false;
|
|
10
|
+
const index = Number(key);
|
|
11
|
+
return Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === key;
|
|
9
12
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
__reExport(src_exports, require("@reduxjs/toolkit"));
|
|
43
|
-
var COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
44
|
-
function stripFunctions(value) {
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
return value.map((item) => stripFunctions(item));
|
|
47
|
-
}
|
|
48
|
-
if (typeof value === "object" && value !== null) {
|
|
49
|
-
const next = {};
|
|
50
|
-
for (const key of Object.keys(value)) {
|
|
51
|
-
const child = value[key];
|
|
52
|
-
if (typeof child === "function") {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
next[key] = stripFunctions(child);
|
|
56
|
-
}
|
|
57
|
-
return next;
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
13
|
+
const isObjectRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
14
|
+
function stripFunctions(value, visited = /* @__PURE__ */ new WeakMap()) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
if (visited.has(value)) return visited.get(value);
|
|
17
|
+
const next = [];
|
|
18
|
+
visited.set(value, next);
|
|
19
|
+
next.length = value.length;
|
|
20
|
+
for (let index = 0; index < value.length; index += 1) if (Object.prototype.hasOwnProperty.call(value, index)) next[index] = stripFunctions(value[index], visited);
|
|
21
|
+
const source = value;
|
|
22
|
+
const target = next;
|
|
23
|
+
for (const key of getOwnEnumerableKeys(value)) {
|
|
24
|
+
if (isArrayIndexKey(key) || isUnsafeKey(key)) continue;
|
|
25
|
+
const child = source[key];
|
|
26
|
+
if (typeof child === "function") continue;
|
|
27
|
+
target[key] = stripFunctions(child, visited);
|
|
28
|
+
}
|
|
29
|
+
return next;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object" && value !== null) {
|
|
32
|
+
if (!isObjectRecord(value)) return value;
|
|
33
|
+
if (visited.has(value)) return visited.get(value);
|
|
34
|
+
const next = {};
|
|
35
|
+
visited.set(value, next);
|
|
36
|
+
for (const key of getOwnEnumerableKeys(value)) {
|
|
37
|
+
if (isUnsafeKey(key)) continue;
|
|
38
|
+
const child = value[key];
|
|
39
|
+
if (typeof child === "function") continue;
|
|
40
|
+
next[key] = stripFunctions(child, visited);
|
|
41
|
+
}
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
60
45
|
}
|
|
61
46
|
function replaceStateAction(payload) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
return {
|
|
48
|
+
type: COACTION_REDUX_REPLACE,
|
|
49
|
+
payload
|
|
50
|
+
};
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
return reducer(state, action);
|
|
52
|
+
const withCoactionReducer = (reducer) => (state, action) => {
|
|
53
|
+
if (action.type === "@@coaction/redux/replace") return stripFunctions(action.payload);
|
|
54
|
+
return reducer(state, action);
|
|
72
55
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
const store = reduxStore;
|
|
131
|
-
store.getState = () => bindState(originalGetState());
|
|
132
|
-
return store;
|
|
56
|
+
/**
|
|
57
|
+
* Bind a redux toolkit store to coaction.
|
|
58
|
+
*/
|
|
59
|
+
const bindRedux = (reduxStore) => {
|
|
60
|
+
const originalGetState = reduxStore.getState.bind(reduxStore);
|
|
61
|
+
let isReduxUpdating = false;
|
|
62
|
+
let isCoactionUpdating = false;
|
|
63
|
+
const bindState = (0, coaction.createBinder)({
|
|
64
|
+
handleStore: (coactionStore, rawState, state, internal) => {
|
|
65
|
+
if (coactionStore.share === "client") throw new Error("client redux store cannot be updated");
|
|
66
|
+
const unsubscribe = reduxStore.subscribe(() => {
|
|
67
|
+
if (isCoactionUpdating) return;
|
|
68
|
+
isReduxUpdating = true;
|
|
69
|
+
try {
|
|
70
|
+
(0, coaction.replaceExternalStoreState)(coactionStore, internal, originalGetState(), { syncImmutable: false });
|
|
71
|
+
} finally {
|
|
72
|
+
isReduxUpdating = false;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const baseDestroy = coactionStore.destroy;
|
|
76
|
+
let destroyed = false;
|
|
77
|
+
coactionStore.destroy = () => {
|
|
78
|
+
if (destroyed) return;
|
|
79
|
+
destroyed = true;
|
|
80
|
+
unsubscribe();
|
|
81
|
+
baseDestroy();
|
|
82
|
+
};
|
|
83
|
+
internal.updateImmutable = (nextState) => {
|
|
84
|
+
if (isReduxUpdating) return;
|
|
85
|
+
isCoactionUpdating = true;
|
|
86
|
+
try {
|
|
87
|
+
reduxStore.dispatch(replaceStateAction(nextState));
|
|
88
|
+
} finally {
|
|
89
|
+
isCoactionUpdating = false;
|
|
90
|
+
}
|
|
91
|
+
internal.listeners.forEach((listener) => listener());
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
handleState: ((state) => {
|
|
95
|
+
return {
|
|
96
|
+
copyState: Object.defineProperties({}, {
|
|
97
|
+
...Object.getOwnPropertyDescriptors(state),
|
|
98
|
+
dispatch: {
|
|
99
|
+
enumerable: false,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: false,
|
|
102
|
+
value: reduxStore.dispatch.bind(reduxStore)
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
bind: (rawState) => rawState
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
const store = reduxStore;
|
|
110
|
+
store.getState = () => bindState(originalGetState());
|
|
111
|
+
return store;
|
|
133
112
|
};
|
|
134
113
|
function adapt(store) {
|
|
135
|
-
|
|
114
|
+
return store;
|
|
136
115
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
exports.COACTION_REDUX_REPLACE = COACTION_REDUX_REPLACE;
|
|
118
|
+
exports.adapt = adapt;
|
|
119
|
+
exports.bindRedux = bindRedux;
|
|
120
|
+
exports.replaceStateAction = replaceStateAction;
|
|
121
|
+
exports.withCoactionReducer = withCoactionReducer;
|
|
122
|
+
var _reduxjs_toolkit = require("@reduxjs/toolkit");
|
|
123
|
+
Object.keys(_reduxjs_toolkit).forEach(function(k) {
|
|
124
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return _reduxjs_toolkit[k];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
147
130
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,144 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createBinder, replaceExternalStoreState } from "coaction";
|
|
2
|
+
export * from "@reduxjs/toolkit";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region packages/coaction-redux/src/index.ts
|
|
5
|
+
const COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
6
|
+
const isUnsafeKey = (key) => typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
7
|
+
const getOwnEnumerableKeys = (value) => Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
8
|
+
const isArrayIndexKey = (key) => {
|
|
9
|
+
if (typeof key !== "string") return false;
|
|
10
|
+
const index = Number(key);
|
|
11
|
+
return Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === key;
|
|
8
12
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var COACTION_REDUX_REPLACE = "@@coaction/redux/replace";
|
|
42
|
-
function stripFunctions(value) {
|
|
43
|
-
if (Array.isArray(value)) {
|
|
44
|
-
return value.map((item) => stripFunctions(item));
|
|
45
|
-
}
|
|
46
|
-
if (typeof value === "object" && value !== null) {
|
|
47
|
-
const next = {};
|
|
48
|
-
for (const key of Object.keys(value)) {
|
|
49
|
-
const child = value[key];
|
|
50
|
-
if (typeof child === "function") {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
next[key] = stripFunctions(child);
|
|
54
|
-
}
|
|
55
|
-
return next;
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
13
|
+
const isObjectRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
14
|
+
function stripFunctions(value, visited = /* @__PURE__ */ new WeakMap()) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
if (visited.has(value)) return visited.get(value);
|
|
17
|
+
const next = [];
|
|
18
|
+
visited.set(value, next);
|
|
19
|
+
next.length = value.length;
|
|
20
|
+
for (let index = 0; index < value.length; index += 1) if (Object.prototype.hasOwnProperty.call(value, index)) next[index] = stripFunctions(value[index], visited);
|
|
21
|
+
const source = value;
|
|
22
|
+
const target = next;
|
|
23
|
+
for (const key of getOwnEnumerableKeys(value)) {
|
|
24
|
+
if (isArrayIndexKey(key) || isUnsafeKey(key)) continue;
|
|
25
|
+
const child = source[key];
|
|
26
|
+
if (typeof child === "function") continue;
|
|
27
|
+
target[key] = stripFunctions(child, visited);
|
|
28
|
+
}
|
|
29
|
+
return next;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object" && value !== null) {
|
|
32
|
+
if (!isObjectRecord(value)) return value;
|
|
33
|
+
if (visited.has(value)) return visited.get(value);
|
|
34
|
+
const next = {};
|
|
35
|
+
visited.set(value, next);
|
|
36
|
+
for (const key of getOwnEnumerableKeys(value)) {
|
|
37
|
+
if (isUnsafeKey(key)) continue;
|
|
38
|
+
const child = value[key];
|
|
39
|
+
if (typeof child === "function") continue;
|
|
40
|
+
next[key] = stripFunctions(child, visited);
|
|
41
|
+
}
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
58
45
|
}
|
|
59
46
|
function replaceStateAction(payload) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
return {
|
|
48
|
+
type: COACTION_REDUX_REPLACE,
|
|
49
|
+
payload
|
|
50
|
+
};
|
|
64
51
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return reducer(state, action);
|
|
52
|
+
const withCoactionReducer = (reducer) => (state, action) => {
|
|
53
|
+
if (action.type === "@@coaction/redux/replace") return stripFunctions(action.payload);
|
|
54
|
+
return reducer(state, action);
|
|
70
55
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
const store = reduxStore;
|
|
129
|
-
store.getState = () => bindState(originalGetState());
|
|
130
|
-
return store;
|
|
56
|
+
/**
|
|
57
|
+
* Bind a redux toolkit store to coaction.
|
|
58
|
+
*/
|
|
59
|
+
const bindRedux = (reduxStore) => {
|
|
60
|
+
const originalGetState = reduxStore.getState.bind(reduxStore);
|
|
61
|
+
let isReduxUpdating = false;
|
|
62
|
+
let isCoactionUpdating = false;
|
|
63
|
+
const bindState = createBinder({
|
|
64
|
+
handleStore: (coactionStore, rawState, state, internal) => {
|
|
65
|
+
if (coactionStore.share === "client") throw new Error("client redux store cannot be updated");
|
|
66
|
+
const unsubscribe = reduxStore.subscribe(() => {
|
|
67
|
+
if (isCoactionUpdating) return;
|
|
68
|
+
isReduxUpdating = true;
|
|
69
|
+
try {
|
|
70
|
+
replaceExternalStoreState(coactionStore, internal, originalGetState(), { syncImmutable: false });
|
|
71
|
+
} finally {
|
|
72
|
+
isReduxUpdating = false;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const baseDestroy = coactionStore.destroy;
|
|
76
|
+
let destroyed = false;
|
|
77
|
+
coactionStore.destroy = () => {
|
|
78
|
+
if (destroyed) return;
|
|
79
|
+
destroyed = true;
|
|
80
|
+
unsubscribe();
|
|
81
|
+
baseDestroy();
|
|
82
|
+
};
|
|
83
|
+
internal.updateImmutable = (nextState) => {
|
|
84
|
+
if (isReduxUpdating) return;
|
|
85
|
+
isCoactionUpdating = true;
|
|
86
|
+
try {
|
|
87
|
+
reduxStore.dispatch(replaceStateAction(nextState));
|
|
88
|
+
} finally {
|
|
89
|
+
isCoactionUpdating = false;
|
|
90
|
+
}
|
|
91
|
+
internal.listeners.forEach((listener) => listener());
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
handleState: ((state) => {
|
|
95
|
+
return {
|
|
96
|
+
copyState: Object.defineProperties({}, {
|
|
97
|
+
...Object.getOwnPropertyDescriptors(state),
|
|
98
|
+
dispatch: {
|
|
99
|
+
enumerable: false,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: false,
|
|
102
|
+
value: reduxStore.dispatch.bind(reduxStore)
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
bind: (rawState) => rawState
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
const store = reduxStore;
|
|
110
|
+
store.getState = () => bindState(originalGetState());
|
|
111
|
+
return store;
|
|
131
112
|
};
|
|
132
113
|
function adapt(store) {
|
|
133
|
-
|
|
114
|
+
return store;
|
|
134
115
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
__reExport(index_exports, src_exports);
|
|
138
|
-
export {
|
|
139
|
-
COACTION_REDUX_REPLACE,
|
|
140
|
-
adapt,
|
|
141
|
-
bindRedux,
|
|
142
|
-
replaceStateAction,
|
|
143
|
-
withCoactionReducer
|
|
144
|
-
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { COACTION_REDUX_REPLACE, adapt, bindRedux, replaceStateAction, withCoactionReducer };
|
package/package.json
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coaction/redux",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A Coaction integration tool for Redux Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"state",
|
|
7
6
|
"coaction",
|
|
8
7
|
"redux",
|
|
9
|
-
"redux-toolkit"
|
|
8
|
+
"redux-toolkit",
|
|
9
|
+
"state"
|
|
10
10
|
],
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
"homepage": "https://github.com/coactionjs/coaction/tree/main/packages/coaction-redux#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/coactionjs/coaction/issues"
|
|
14
|
+
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
+
"author": "unadlib",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/coactionjs/coaction.git",
|
|
20
|
+
"directory": "packages/coaction-redux"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
16
26
|
"main": "dist/index.js",
|
|
17
27
|
"module": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
18
29
|
"exports": {
|
|
19
30
|
".": {
|
|
20
31
|
"types": "./dist/index.d.ts",
|
|
@@ -24,44 +35,25 @@
|
|
|
24
35
|
},
|
|
25
36
|
"./package.json": "./package.json"
|
|
26
37
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"dist"
|
|
31
|
-
],
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "https://github.com/unadlib/coaction.git",
|
|
35
|
-
"directory": "packages/coaction-redux"
|
|
36
|
-
},
|
|
37
|
-
"bugs": {
|
|
38
|
-
"url": "https://github.com/unadlib/coaction/issues"
|
|
39
|
-
},
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"@reduxjs/toolkit": "^2.0.0",
|
|
42
|
-
"coaction": "^1.5.0"
|
|
43
|
-
},
|
|
44
|
-
"peerDependenciesMeta": {
|
|
45
|
-
"coaction": {
|
|
46
|
-
"optional": true
|
|
47
|
-
},
|
|
48
|
-
"@reduxjs/toolkit": {
|
|
49
|
-
"optional": true
|
|
50
|
-
}
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
51
41
|
},
|
|
52
42
|
"devDependencies": {
|
|
53
43
|
"@reduxjs/toolkit": "^2.10.1",
|
|
54
|
-
"coaction": "
|
|
44
|
+
"coaction": "2.0.0"
|
|
55
45
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@reduxjs/toolkit": "^2.0.0",
|
|
48
|
+
"coaction": "^2.0.0"
|
|
59
49
|
},
|
|
60
|
-
"
|
|
50
|
+
"authors": [
|
|
51
|
+
"Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
|
|
52
|
+
],
|
|
61
53
|
"scripts": {
|
|
62
54
|
"clean": "rm -rf dist",
|
|
63
55
|
"test": "vitest run test",
|
|
64
|
-
"build": "
|
|
65
|
-
"dev": "
|
|
56
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
57
|
+
"dev": "node ../../scripts/build-package.mjs --watch"
|
|
66
58
|
}
|
|
67
59
|
}
|