@coaction/redux 1.4.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @coaction/redux
2
2
 
3
- ![Node CI](https://github.com/unadlib/coaction/workflows/Node%20CI/badge.svg)
3
+ ![Node CI](https://github.com/coactionjs/coaction/workflows/Node%20CI/badge.svg)
4
4
  [![npm](https://img.shields.io/npm/v/@coaction/redux.svg)](https://www.npmjs.com/package/@coaction/redux)
5
5
  ![license](https://img.shields.io/npm/l/@coaction/redux)
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/unadlib/coaction).
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, Store, Reducer } from '@reduxjs/toolkit';
2
- export * from '@reduxjs/toolkit';
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
- type: typeof COACTION_REDUX_REPLACE;
7
- payload: S;
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
- getState: () => BoundReduxState<S, A>;
15
+ getState: () => BoundReduxState<S, A>;
13
16
  };
14
17
  type BoundReduxState<S extends object, A extends AnyAction> = S & {
15
- dispatch: Store<S, A>['dispatch'];
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, type ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
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, Store, Reducer } from '@reduxjs/toolkit';
2
- export * from '@reduxjs/toolkit';
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
- type: typeof COACTION_REDUX_REPLACE;
7
- payload: S;
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
- getState: () => BoundReduxState<S, A>;
15
+ getState: () => BoundReduxState<S, A>;
13
16
  };
14
17
  type BoundReduxState<S extends object, A extends AnyAction> = S & {
15
- dispatch: Store<S, A>['dispatch'];
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, type ReplaceStateAction, adapt, bindRedux, replaceStateAction, withCoactionReducer };
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,146 +1,130 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
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
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- COACTION_REDUX_REPLACE: () => COACTION_REDUX_REPLACE,
25
- adapt: () => adapt,
26
- bindRedux: () => bindRedux,
27
- replaceStateAction: () => replaceStateAction,
28
- withCoactionReducer: () => withCoactionReducer
29
- });
30
- module.exports = __toCommonJS(index_exports);
31
-
32
- // src/index.ts
33
- var src_exports = {};
34
- __export(src_exports, {
35
- COACTION_REDUX_REPLACE: () => COACTION_REDUX_REPLACE,
36
- adapt: () => adapt,
37
- bindRedux: () => bindRedux,
38
- replaceStateAction: () => replaceStateAction,
39
- withCoactionReducer: () => withCoactionReducer
40
- });
41
- var import_coaction = require("coaction");
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
- return {
63
- type: COACTION_REDUX_REPLACE,
64
- payload
65
- };
47
+ return {
48
+ type: COACTION_REDUX_REPLACE,
49
+ payload
50
+ };
66
51
  }
67
- var withCoactionReducer = (reducer) => (state, action) => {
68
- if (action.type === COACTION_REDUX_REPLACE) {
69
- return stripFunctions(action.payload);
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
- var bindRedux = (reduxStore) => {
74
- const originalGetState = reduxStore.getState.bind(reduxStore);
75
- let isReduxUpdating = false;
76
- let isCoactionUpdating = false;
77
- const bindState = (0, import_coaction.createBinder)({
78
- handleStore: (coactionStore, rawState, state, internal) => {
79
- if (coactionStore.share === "client") {
80
- throw new Error("client redux store cannot be updated");
81
- }
82
- const unsubscribe = reduxStore.subscribe(() => {
83
- if (isCoactionUpdating) {
84
- return;
85
- }
86
- isReduxUpdating = true;
87
- try {
88
- coactionStore.setState(reduxStore.getState());
89
- } finally {
90
- isReduxUpdating = false;
91
- }
92
- });
93
- const baseDestroy = coactionStore.destroy;
94
- coactionStore.destroy = () => {
95
- unsubscribe();
96
- baseDestroy();
97
- };
98
- internal.updateImmutable = (nextState) => {
99
- if (isReduxUpdating) {
100
- return;
101
- }
102
- isCoactionUpdating = true;
103
- try {
104
- reduxStore.dispatch(replaceStateAction(nextState));
105
- } finally {
106
- isCoactionUpdating = false;
107
- }
108
- };
109
- },
110
- handleState: ((state) => {
111
- const copyState = Object.defineProperties(
112
- {},
113
- {
114
- ...Object.getOwnPropertyDescriptors(state),
115
- dispatch: {
116
- enumerable: false,
117
- configurable: true,
118
- writable: false,
119
- value: reduxStore.dispatch.bind(reduxStore)
120
- }
121
- }
122
- );
123
- return {
124
- copyState,
125
- bind: (rawState) => rawState
126
- };
127
- })
128
- });
129
- const store = reduxStore;
130
- store.getState = () => bindState(originalGetState());
131
- 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;
132
112
  };
133
113
  function adapt(store) {
134
- return store;
114
+ return store;
135
115
  }
136
-
137
- // index.ts
138
- __reExport(index_exports, src_exports, module.exports);
139
- // Annotate the CommonJS export names for ESM import in node:
140
- 0 && (module.exports = {
141
- COACTION_REDUX_REPLACE,
142
- adapt,
143
- bindRedux,
144
- replaceStateAction,
145
- withCoactionReducer
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
+ });
146
130
  });
package/dist/index.mjs CHANGED
@@ -1,143 +1,117 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
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
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
-
19
- // index.ts
20
- var index_exports = {};
21
- __export(index_exports, {
22
- COACTION_REDUX_REPLACE: () => COACTION_REDUX_REPLACE,
23
- adapt: () => adapt,
24
- bindRedux: () => bindRedux,
25
- replaceStateAction: () => replaceStateAction,
26
- withCoactionReducer: () => withCoactionReducer
27
- });
28
-
29
- // src/index.ts
30
- var src_exports = {};
31
- __export(src_exports, {
32
- COACTION_REDUX_REPLACE: () => COACTION_REDUX_REPLACE,
33
- adapt: () => adapt,
34
- bindRedux: () => bindRedux,
35
- replaceStateAction: () => replaceStateAction,
36
- withCoactionReducer: () => withCoactionReducer
37
- });
38
- __reExport(src_exports, toolkit_star);
39
- import { createBinder } from "coaction";
40
- import * as toolkit_star from "@reduxjs/toolkit";
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
- return {
61
- type: COACTION_REDUX_REPLACE,
62
- payload
63
- };
47
+ return {
48
+ type: COACTION_REDUX_REPLACE,
49
+ payload
50
+ };
64
51
  }
65
- var withCoactionReducer = (reducer) => (state, action) => {
66
- if (action.type === COACTION_REDUX_REPLACE) {
67
- return stripFunctions(action.payload);
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
- var bindRedux = (reduxStore) => {
72
- const originalGetState = reduxStore.getState.bind(reduxStore);
73
- let isReduxUpdating = false;
74
- let isCoactionUpdating = false;
75
- const bindState = createBinder({
76
- handleStore: (coactionStore, rawState, state, internal) => {
77
- if (coactionStore.share === "client") {
78
- throw new Error("client redux store cannot be updated");
79
- }
80
- const unsubscribe = reduxStore.subscribe(() => {
81
- if (isCoactionUpdating) {
82
- return;
83
- }
84
- isReduxUpdating = true;
85
- try {
86
- coactionStore.setState(reduxStore.getState());
87
- } finally {
88
- isReduxUpdating = false;
89
- }
90
- });
91
- const baseDestroy = coactionStore.destroy;
92
- coactionStore.destroy = () => {
93
- unsubscribe();
94
- baseDestroy();
95
- };
96
- internal.updateImmutable = (nextState) => {
97
- if (isReduxUpdating) {
98
- return;
99
- }
100
- isCoactionUpdating = true;
101
- try {
102
- reduxStore.dispatch(replaceStateAction(nextState));
103
- } finally {
104
- isCoactionUpdating = false;
105
- }
106
- };
107
- },
108
- handleState: ((state) => {
109
- const copyState = Object.defineProperties(
110
- {},
111
- {
112
- ...Object.getOwnPropertyDescriptors(state),
113
- dispatch: {
114
- enumerable: false,
115
- configurable: true,
116
- writable: false,
117
- value: reduxStore.dispatch.bind(reduxStore)
118
- }
119
- }
120
- );
121
- return {
122
- copyState,
123
- bind: (rawState) => rawState
124
- };
125
- })
126
- });
127
- const store = reduxStore;
128
- store.getState = () => bindState(originalGetState());
129
- 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;
130
112
  };
131
113
  function adapt(store) {
132
- return store;
114
+ return store;
133
115
  }
134
-
135
- // index.ts
136
- __reExport(index_exports, src_exports);
137
- export {
138
- COACTION_REDUX_REPLACE,
139
- adapt,
140
- bindRedux,
141
- replaceStateAction,
142
- withCoactionReducer
143
- };
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": "1.4.1",
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
- "authors": [
12
- "Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
13
- ],
14
- "homepage": "https://github.com/unadlib/coaction/tree/main/packages/coaction-redux#readme",
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
- "types": "dist/index.d.ts",
28
- "sideEffects": false,
29
- "files": [
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.4.1"
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": "1.4.1"
44
+ "coaction": "2.0.0"
55
45
  },
56
- "publishConfig": {
57
- "access": "public",
58
- "provenance": true
46
+ "peerDependencies": {
47
+ "@reduxjs/toolkit": "^2.0.0",
48
+ "coaction": "^2.0.0"
59
49
  },
60
- "author": "unadlib",
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": "tsup index.ts --format cjs,esm --dts --clean --out-dir dist",
65
- "dev": "tsup index.ts --format cjs,esm --dts --watch --out-dir dist"
56
+ "build": "node ../../scripts/build-package.mjs",
57
+ "dev": "node ../../scripts/build-package.mjs --watch"
66
58
  }
67
59
  }