acture-state-redux 1.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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Thor Whalen
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # acture-state-redux
2
+
3
+ > **acture is a development tool first.** This package is an *optional accelerator* — an agent can hand-write this integration into your project instead, with no `acture-*` dependency. Installing it is a deliberate, opt-in choice to reuse tested code rather than own it. See [`docs/positioning.md`](../../docs/positioning.md).
4
+
5
+ Reference state adapter binding [acture](https://npm.im/acture)'s `StateAdapter<S>` to [Redux Toolkit](https://redux-toolkit.js.org/). Implements `PatchCapableAdapter<S>` via Immer (already bundled with RTK).
6
+
7
+ ## Two forms
8
+
9
+ ### 1. Fresh single-slice store (greenfield)
10
+
11
+ ```ts
12
+ import { createReduxAdapter } from 'acture-state-redux';
13
+
14
+ interface AppState { count: number }
15
+
16
+ const state = createReduxAdapter<AppState>({ initialState: { count: 0 } });
17
+
18
+ state.setState((s) => { s.count += 1; });
19
+ state.setState((s) => ({ ...s, count: 0 }));
20
+
21
+ const { patches, inversePatches } = state.setStateWithPatches((draft) => {
22
+ draft.count = 42;
23
+ });
24
+ state.applyPatches(inversePatches);
25
+ ```
26
+
27
+ ### 2. Wrap an existing RTK store (strangler-fig)
28
+
29
+ ```ts
30
+ import { configureStore, createSlice } from '@reduxjs/toolkit';
31
+ import { wrapReduxStore } from 'acture-state-redux';
32
+
33
+ const slice = createSlice({
34
+ name: 'graph',
35
+ initialState: { nodes: {}, edges: {} },
36
+ reducers: {
37
+ replaceFromActure: (_s, action) => action.payload,
38
+ },
39
+ });
40
+
41
+ const store = configureStore({ reducer: { graph: slice.reducer } });
42
+
43
+ const adapter = wrapReduxStore(store, {
44
+ select: (root) => root.graph,
45
+ makeReplace: (next) => slice.actions.replaceFromActure(next),
46
+ });
47
+ ```
48
+
49
+ The host keeps its existing reducers, slices, and dispatch surfaces; acture treats one slice as its source of truth.
50
+
51
+ ## The `previous` argument
52
+
53
+ RTK's `store.subscribe(listener)` calls the listener with **no arguments** (unlike zustand which passes `(next, prev)`). The adapter tracks `previous` itself between callbacks; values are forwarded to acture's `subscribe(listener)` contract. Documented in [`docs/phase-1-reflection.md` §2](../../docs/phase-1-reflection.md).
54
+
55
+ ## What about `serializableCheck`?
56
+
57
+ `createReduxAdapter` ships with `serializableCheck: false` and `immutableCheck: false` because the adapter's payload IS the next state (already produced by Immer upstream of dispatch). For `wrapReduxStore` you control the store's middleware — keep `serializableCheck` on as long as your `makeReplace` action carries a plain object.
58
+
59
+ ## See also
60
+
61
+ - [`acture-state-adapter`](https://github.com/thorwhalen/acture/blob/main/.claude/skills/acture-state-adapter/SKILL.md) — the contract
62
+ - [`acture-state-zustand`](../state-zustand) — sibling adapter for zustand+immer
package/dist/index.cjs ADDED
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ var toolkit = require('@reduxjs/toolkit');
4
+ var immer = require('immer');
5
+
6
+ // src/index.ts
7
+ immer.enablePatches();
8
+ function createReduxAdapter(options) {
9
+ const actionType = options.actionType ?? "acture/setState";
10
+ const replace = toolkit.createAction(actionType);
11
+ const reducer = toolkit.createReducer(options.initialState, (builder) => {
12
+ builder.addCase(replace, (_state, action) => action.payload);
13
+ });
14
+ const store = toolkit.configureStore({
15
+ reducer,
16
+ // Our payload IS the next state, which IS the next store value —
17
+ // serializability and immutability are guaranteed by Immer upstream
18
+ // of dispatch. Disable RTK's defensive middleware so the action
19
+ // doesn't trip warnings for plain (already-immutable) objects.
20
+ middleware: (getDefault) => getDefault({ serializableCheck: false, immutableCheck: false })
21
+ });
22
+ return wrapAdapter(store, {
23
+ select: (s) => s,
24
+ makeReplace: (next) => replace(next)
25
+ });
26
+ }
27
+ function wrapReduxStore(store, slice) {
28
+ return wrapAdapter(store, slice);
29
+ }
30
+ function wrapAdapter(store, slice) {
31
+ let previous = slice.select(store.getState());
32
+ return {
33
+ store,
34
+ supportsPatches: true,
35
+ getState: () => slice.select(store.getState()),
36
+ setState(updater) {
37
+ const current = slice.select(store.getState());
38
+ const recipe = (draft) => updater(draft);
39
+ const result = immer.produceWithPatches(current, recipe);
40
+ const next = result[0];
41
+ store.dispatch(slice.makeReplace(next));
42
+ },
43
+ subscribe(listener) {
44
+ return store.subscribe(() => {
45
+ const next = slice.select(store.getState());
46
+ if (next === previous) return;
47
+ const prev = previous;
48
+ previous = next;
49
+ listener(next, prev);
50
+ });
51
+ },
52
+ setStateWithPatches(recipe) {
53
+ const current = slice.select(store.getState());
54
+ const result = immer.produceWithPatches(current, recipe);
55
+ const [next, patches, inversePatches] = result;
56
+ store.dispatch(slice.makeReplace(next));
57
+ return {
58
+ patches: patches.map(immerToActurePatch),
59
+ inversePatches: inversePatches.map(immerToActurePatch)
60
+ };
61
+ },
62
+ applyPatches(patches) {
63
+ const current = slice.select(store.getState());
64
+ const next = immer.applyPatches(
65
+ current,
66
+ patches.map(actureToImmerPatch)
67
+ );
68
+ store.dispatch(slice.makeReplace(next));
69
+ }
70
+ };
71
+ }
72
+ function immerToActurePatch(p) {
73
+ return {
74
+ op: p.op,
75
+ path: p.path,
76
+ value: "value" in p ? p.value : void 0
77
+ };
78
+ }
79
+ function actureToImmerPatch(p) {
80
+ return {
81
+ op: p.op,
82
+ path: p.path,
83
+ value: p.value
84
+ };
85
+ }
86
+
87
+ exports.createReduxAdapter = createReduxAdapter;
88
+ exports.wrapReduxStore = wrapReduxStore;
89
+ //# sourceMappingURL=index.cjs.map
90
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["enablePatches","createAction","createReducer","configureStore","produceWithPatches","immerApplyPatches"],"mappings":";;;;;;AAmCAA,mBAAA,EAAc;AAeP,SAAS,mBACd,OAAA,EAC+D;AAC/D,EAAA,MAAM,UAAA,GAAa,QAAQ,UAAA,IAAc,iBAAA;AACzC,EAAA,MAAM,OAAA,GAAUC,qBAAgB,UAAU,CAAA;AAE1C,EAAA,MAAM,OAAA,GAAUC,qBAAA,CAAiB,OAAA,CAAQ,YAAA,EAAc,CAAC,OAAA,KAAY;AAClE,IAAA,OAAA,CAAQ,QAAQ,OAAA,EAAS,CAAC,MAAA,EAAQ,MAAA,KAAW,OAAO,OAAO,CAAA;AAAA,EAC7D,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,CAAA,CAAE,KAAA,GAAQ;AAAA,GAClC;AACF;AAEA,SAAS,mBAAmB,CAAA,EAAsB;AAChD,EAAA,OAAO;AAAA,IACL,IAAI,CAAA,CAAE,EAAA;AAAA,IACN,MAAM,CAAA,CAAE,IAAA;AAAA,IACR,OAAO,CAAA,CAAE;AAAA,GACX;AACF","file":"index.cjs","sourcesContent":["/**\n * `acture-state-redux` — Redux Toolkit reference adapter.\n *\n * Wraps an RTK store as `PatchCapableAdapter<S>`. RTK bundles Immer, so\n * the patches story is identical to `acture-state-zustand` — same\n * `produceWithPatches` plumbing.\n *\n * Two forms:\n *\n * 1. **`createReduxAdapter({ initialState })`** — builds a fresh\n * single-slice RTK store and hands back the adapter. Use this when\n * acture is the dominant state owner (greenfield path).\n *\n * 2. **`wrapReduxStore(store, slice)`** — wraps an existing RTK store,\n * treating one slice as acture's state. The host supplies selectors\n * and a replace-action creator. Use this for the strangler-fig /\n * drop-in path.\n *\n * ## The `previous` quirk\n *\n * RTK's `store.subscribe(listener)` calls `listener()` with no args.\n * We track `previous` ourselves between callbacks. The acture\n * `StateAdapter` contract says adapters that can't track `previous`\n * cleanly may pass the same value as `current` — RTK's notification\n * isn't synchronous-with-action either, so by the time we read\n * getState() we already have the new value. Phase 1 reflection (§2)\n * flagged this as expected.\n */\n\nimport { configureStore, createAction, createReducer } from '@reduxjs/toolkit';\nimport type { Action, EnhancedStore } from '@reduxjs/toolkit';\nimport { enablePatches, produceWithPatches, applyPatches as immerApplyPatches } from 'immer';\nimport type { Patch as ImmerPatch } from 'immer';\nimport type { PatchCapableAdapter, Patch } from 'acture';\n\nenablePatches();\n\nexport interface CreateReduxAdapterOptions<S> {\n initialState: S;\n /** Optional action type prefix for the internal setState action.\n * Default `'acture/setState'`. Useful only if the same store also\n * hosts a slice that wants to react to this action. */\n actionType?: string;\n}\n\n/**\n * Build a `PatchCapableAdapter<S>` backed by a fresh single-slice RTK\n * store. Returns the adapter plus the underlying store (for devtools\n * integration).\n */\nexport function createReduxAdapter<S>(\n options: CreateReduxAdapterOptions<S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<S> } {\n const actionType = options.actionType ?? 'acture/setState';\n const replace = createAction<S>(actionType);\n\n const reducer = createReducer<S>(options.initialState, (builder) => {\n builder.addCase(replace, (_state, action) => action.payload);\n });\n\n const store = configureStore<S>({\n reducer,\n // Our payload IS the next state, which IS the next store value —\n // serializability and immutability are guaranteed by Immer upstream\n // of dispatch. Disable RTK's defensive middleware so the action\n // doesn't trip warnings for plain (already-immutable) objects.\n middleware: (getDefault) =>\n getDefault({ serializableCheck: false, immutableCheck: false }),\n });\n\n return wrapAdapter(store, {\n select: (s) => s,\n makeReplace: (next) => replace(next),\n });\n}\n\n/** Selector + action-creator pair binding the adapter to one slice of\n * an existing store. */\nexport interface ReduxAdapterSlice<RootState, S> {\n select: (root: RootState) => S;\n /** Returns the action that, when dispatched, replaces the slice\n * state with the provided next value. */\n makeReplace: (next: S) => Action;\n}\n\n/**\n * Wrap an existing RTK store and treat one slice as acture's state.\n * The host supplies a selector and an action creator for replacing\n * the slice in one shot.\n */\nexport function wrapReduxStore<RootState, S>(\n store: EnhancedStore<RootState>,\n slice: ReduxAdapterSlice<RootState, S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<RootState> } {\n return wrapAdapter(store, slice);\n}\n\n/* ───────────────────────── internals ──────────────────────────────── */\n\nfunction wrapAdapter<RootState, S>(\n store: EnhancedStore<RootState>,\n slice: ReduxAdapterSlice<RootState, S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<RootState> } {\n let previous: S = slice.select(store.getState());\n\n return {\n store,\n supportsPatches: true,\n getState: () => slice.select(store.getState()),\n\n setState(updater) {\n const current = slice.select(store.getState());\n // Immer's overloaded signature wants `Draft<S>` in the recipe;\n // acture's contract is `S`. Cast through `Function` to bridge.\n const recipe = (draft: S): S | void =>\n (updater as (s: S) => S | void)(draft);\n const result = (produceWithPatches as unknown as (\n base: S,\n recipe: (d: S) => S | void,\n ) => [S, unknown, unknown])(current, recipe);\n const next = result[0];\n store.dispatch(slice.makeReplace(next));\n },\n\n subscribe(listener) {\n return store.subscribe(() => {\n const next = slice.select(store.getState());\n if (next === previous) return; // RTK fires on any dispatch\n const prev = previous;\n previous = next;\n listener(next, prev);\n });\n },\n\n setStateWithPatches(recipe) {\n const current = slice.select(store.getState());\n const result = (produceWithPatches as unknown as (\n base: S,\n recipe: (d: S) => void,\n ) => [S, ImmerPatch[], ImmerPatch[]])(current, recipe);\n const [next, patches, inversePatches] = result;\n store.dispatch(slice.makeReplace(next));\n return {\n patches: patches.map(immerToActurePatch),\n inversePatches: inversePatches.map(immerToActurePatch),\n };\n },\n\n applyPatches(patches) {\n const current = slice.select(store.getState());\n const next = immerApplyPatches(\n current as object,\n patches.map(actureToImmerPatch),\n );\n store.dispatch(slice.makeReplace(next as S));\n },\n };\n}\n\nfunction immerToActurePatch(p: ImmerPatch): Patch {\n return {\n op: p.op as Patch['op'],\n path: p.path as readonly (string | number)[],\n value: 'value' in p ? p.value : undefined,\n };\n}\n\nfunction actureToImmerPatch(p: Patch): ImmerPatch {\n return {\n op: p.op,\n path: p.path as (string | number)[],\n value: p.value,\n };\n}\n\nexport type { PatchCapableAdapter } from 'acture';\n"]}
@@ -0,0 +1,66 @@
1
+ import { Action, EnhancedStore } from '@reduxjs/toolkit';
2
+ import { PatchCapableAdapter } from 'acture';
3
+ export { PatchCapableAdapter } from 'acture';
4
+
5
+ /**
6
+ * `acture-state-redux` — Redux Toolkit reference adapter.
7
+ *
8
+ * Wraps an RTK store as `PatchCapableAdapter<S>`. RTK bundles Immer, so
9
+ * the patches story is identical to `acture-state-zustand` — same
10
+ * `produceWithPatches` plumbing.
11
+ *
12
+ * Two forms:
13
+ *
14
+ * 1. **`createReduxAdapter({ initialState })`** — builds a fresh
15
+ * single-slice RTK store and hands back the adapter. Use this when
16
+ * acture is the dominant state owner (greenfield path).
17
+ *
18
+ * 2. **`wrapReduxStore(store, slice)`** — wraps an existing RTK store,
19
+ * treating one slice as acture's state. The host supplies selectors
20
+ * and a replace-action creator. Use this for the strangler-fig /
21
+ * drop-in path.
22
+ *
23
+ * ## The `previous` quirk
24
+ *
25
+ * RTK's `store.subscribe(listener)` calls `listener()` with no args.
26
+ * We track `previous` ourselves between callbacks. The acture
27
+ * `StateAdapter` contract says adapters that can't track `previous`
28
+ * cleanly may pass the same value as `current` — RTK's notification
29
+ * isn't synchronous-with-action either, so by the time we read
30
+ * getState() we already have the new value. Phase 1 reflection (§2)
31
+ * flagged this as expected.
32
+ */
33
+
34
+ interface CreateReduxAdapterOptions<S> {
35
+ initialState: S;
36
+ /** Optional action type prefix for the internal setState action.
37
+ * Default `'acture/setState'`. Useful only if the same store also
38
+ * hosts a slice that wants to react to this action. */
39
+ actionType?: string;
40
+ }
41
+ /**
42
+ * Build a `PatchCapableAdapter<S>` backed by a fresh single-slice RTK
43
+ * store. Returns the adapter plus the underlying store (for devtools
44
+ * integration).
45
+ */
46
+ declare function createReduxAdapter<S>(options: CreateReduxAdapterOptions<S>): PatchCapableAdapter<S> & {
47
+ readonly store: EnhancedStore<S>;
48
+ };
49
+ /** Selector + action-creator pair binding the adapter to one slice of
50
+ * an existing store. */
51
+ interface ReduxAdapterSlice<RootState, S> {
52
+ select: (root: RootState) => S;
53
+ /** Returns the action that, when dispatched, replaces the slice
54
+ * state with the provided next value. */
55
+ makeReplace: (next: S) => Action;
56
+ }
57
+ /**
58
+ * Wrap an existing RTK store and treat one slice as acture's state.
59
+ * The host supplies a selector and an action creator for replacing
60
+ * the slice in one shot.
61
+ */
62
+ declare function wrapReduxStore<RootState, S>(store: EnhancedStore<RootState>, slice: ReduxAdapterSlice<RootState, S>): PatchCapableAdapter<S> & {
63
+ readonly store: EnhancedStore<RootState>;
64
+ };
65
+
66
+ export { type CreateReduxAdapterOptions, type ReduxAdapterSlice, createReduxAdapter, wrapReduxStore };
@@ -0,0 +1,66 @@
1
+ import { Action, EnhancedStore } from '@reduxjs/toolkit';
2
+ import { PatchCapableAdapter } from 'acture';
3
+ export { PatchCapableAdapter } from 'acture';
4
+
5
+ /**
6
+ * `acture-state-redux` — Redux Toolkit reference adapter.
7
+ *
8
+ * Wraps an RTK store as `PatchCapableAdapter<S>`. RTK bundles Immer, so
9
+ * the patches story is identical to `acture-state-zustand` — same
10
+ * `produceWithPatches` plumbing.
11
+ *
12
+ * Two forms:
13
+ *
14
+ * 1. **`createReduxAdapter({ initialState })`** — builds a fresh
15
+ * single-slice RTK store and hands back the adapter. Use this when
16
+ * acture is the dominant state owner (greenfield path).
17
+ *
18
+ * 2. **`wrapReduxStore(store, slice)`** — wraps an existing RTK store,
19
+ * treating one slice as acture's state. The host supplies selectors
20
+ * and a replace-action creator. Use this for the strangler-fig /
21
+ * drop-in path.
22
+ *
23
+ * ## The `previous` quirk
24
+ *
25
+ * RTK's `store.subscribe(listener)` calls `listener()` with no args.
26
+ * We track `previous` ourselves between callbacks. The acture
27
+ * `StateAdapter` contract says adapters that can't track `previous`
28
+ * cleanly may pass the same value as `current` — RTK's notification
29
+ * isn't synchronous-with-action either, so by the time we read
30
+ * getState() we already have the new value. Phase 1 reflection (§2)
31
+ * flagged this as expected.
32
+ */
33
+
34
+ interface CreateReduxAdapterOptions<S> {
35
+ initialState: S;
36
+ /** Optional action type prefix for the internal setState action.
37
+ * Default `'acture/setState'`. Useful only if the same store also
38
+ * hosts a slice that wants to react to this action. */
39
+ actionType?: string;
40
+ }
41
+ /**
42
+ * Build a `PatchCapableAdapter<S>` backed by a fresh single-slice RTK
43
+ * store. Returns the adapter plus the underlying store (for devtools
44
+ * integration).
45
+ */
46
+ declare function createReduxAdapter<S>(options: CreateReduxAdapterOptions<S>): PatchCapableAdapter<S> & {
47
+ readonly store: EnhancedStore<S>;
48
+ };
49
+ /** Selector + action-creator pair binding the adapter to one slice of
50
+ * an existing store. */
51
+ interface ReduxAdapterSlice<RootState, S> {
52
+ select: (root: RootState) => S;
53
+ /** Returns the action that, when dispatched, replaces the slice
54
+ * state with the provided next value. */
55
+ makeReplace: (next: S) => Action;
56
+ }
57
+ /**
58
+ * Wrap an existing RTK store and treat one slice as acture's state.
59
+ * The host supplies a selector and an action creator for replacing
60
+ * the slice in one shot.
61
+ */
62
+ declare function wrapReduxStore<RootState, S>(store: EnhancedStore<RootState>, slice: ReduxAdapterSlice<RootState, S>): PatchCapableAdapter<S> & {
63
+ readonly store: EnhancedStore<RootState>;
64
+ };
65
+
66
+ export { type CreateReduxAdapterOptions, type ReduxAdapterSlice, createReduxAdapter, wrapReduxStore };
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ import { createAction, createReducer, configureStore } from '@reduxjs/toolkit';
2
+ import { enablePatches, applyPatches, produceWithPatches } from 'immer';
3
+
4
+ // src/index.ts
5
+ enablePatches();
6
+ function createReduxAdapter(options) {
7
+ const actionType = options.actionType ?? "acture/setState";
8
+ const replace = createAction(actionType);
9
+ const reducer = createReducer(options.initialState, (builder) => {
10
+ builder.addCase(replace, (_state, action) => action.payload);
11
+ });
12
+ const store = configureStore({
13
+ reducer,
14
+ // Our payload IS the next state, which IS the next store value —
15
+ // serializability and immutability are guaranteed by Immer upstream
16
+ // of dispatch. Disable RTK's defensive middleware so the action
17
+ // doesn't trip warnings for plain (already-immutable) objects.
18
+ middleware: (getDefault) => getDefault({ serializableCheck: false, immutableCheck: false })
19
+ });
20
+ return wrapAdapter(store, {
21
+ select: (s) => s,
22
+ makeReplace: (next) => replace(next)
23
+ });
24
+ }
25
+ function wrapReduxStore(store, slice) {
26
+ return wrapAdapter(store, slice);
27
+ }
28
+ function wrapAdapter(store, slice) {
29
+ let previous = slice.select(store.getState());
30
+ return {
31
+ store,
32
+ supportsPatches: true,
33
+ getState: () => slice.select(store.getState()),
34
+ setState(updater) {
35
+ const current = slice.select(store.getState());
36
+ const recipe = (draft) => updater(draft);
37
+ const result = produceWithPatches(current, recipe);
38
+ const next = result[0];
39
+ store.dispatch(slice.makeReplace(next));
40
+ },
41
+ subscribe(listener) {
42
+ return store.subscribe(() => {
43
+ const next = slice.select(store.getState());
44
+ if (next === previous) return;
45
+ const prev = previous;
46
+ previous = next;
47
+ listener(next, prev);
48
+ });
49
+ },
50
+ setStateWithPatches(recipe) {
51
+ const current = slice.select(store.getState());
52
+ const result = produceWithPatches(current, recipe);
53
+ const [next, patches, inversePatches] = result;
54
+ store.dispatch(slice.makeReplace(next));
55
+ return {
56
+ patches: patches.map(immerToActurePatch),
57
+ inversePatches: inversePatches.map(immerToActurePatch)
58
+ };
59
+ },
60
+ applyPatches(patches) {
61
+ const current = slice.select(store.getState());
62
+ const next = applyPatches(
63
+ current,
64
+ patches.map(actureToImmerPatch)
65
+ );
66
+ store.dispatch(slice.makeReplace(next));
67
+ }
68
+ };
69
+ }
70
+ function immerToActurePatch(p) {
71
+ return {
72
+ op: p.op,
73
+ path: p.path,
74
+ value: "value" in p ? p.value : void 0
75
+ };
76
+ }
77
+ function actureToImmerPatch(p) {
78
+ return {
79
+ op: p.op,
80
+ path: p.path,
81
+ value: p.value
82
+ };
83
+ }
84
+
85
+ export { createReduxAdapter, wrapReduxStore };
86
+ //# sourceMappingURL=index.js.map
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["immerApplyPatches"],"mappings":";;;;AAmCA,aAAA,EAAc;AAeP,SAAS,mBACd,OAAA,EAC+D;AAC/D,EAAA,MAAM,UAAA,GAAa,QAAQ,UAAA,IAAc,iBAAA;AACzC,EAAA,MAAM,OAAA,GAAU,aAAgB,UAAU,CAAA;AAE1C,EAAA,MAAM,OAAA,GAAU,aAAA,CAAiB,OAAA,CAAQ,YAAA,EAAc,CAAC,OAAA,KAAY;AAClE,IAAA,OAAA,CAAQ,QAAQ,OAAA,EAAS,CAAC,MAAA,EAAQ,MAAA,KAAW,OAAO,OAAO,CAAA;AAAA,EAC7D,CAAC,CAAA;AAED,EAAA,MAAM,QAAQ,cAAA,CAAkB;AAAA,IAC9B,OAAA;AAAA;AA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,EAAA,OAAO;AAAA,IACL,IAAI,CAAA,CAAE,EAAA;AAAA,IACN,MAAM,CAAA,CAAE,IAAA;AAAA,IACR,OAAO,CAAA,CAAE;AAAA,GACX;AACF","file":"index.js","sourcesContent":["/**\n * `acture-state-redux` — Redux Toolkit reference adapter.\n *\n * Wraps an RTK store as `PatchCapableAdapter<S>`. RTK bundles Immer, so\n * the patches story is identical to `acture-state-zustand` — same\n * `produceWithPatches` plumbing.\n *\n * Two forms:\n *\n * 1. **`createReduxAdapter({ initialState })`** — builds a fresh\n * single-slice RTK store and hands back the adapter. Use this when\n * acture is the dominant state owner (greenfield path).\n *\n * 2. **`wrapReduxStore(store, slice)`** — wraps an existing RTK store,\n * treating one slice as acture's state. The host supplies selectors\n * and a replace-action creator. Use this for the strangler-fig /\n * drop-in path.\n *\n * ## The `previous` quirk\n *\n * RTK's `store.subscribe(listener)` calls `listener()` with no args.\n * We track `previous` ourselves between callbacks. The acture\n * `StateAdapter` contract says adapters that can't track `previous`\n * cleanly may pass the same value as `current` — RTK's notification\n * isn't synchronous-with-action either, so by the time we read\n * getState() we already have the new value. Phase 1 reflection (§2)\n * flagged this as expected.\n */\n\nimport { configureStore, createAction, createReducer } from '@reduxjs/toolkit';\nimport type { Action, EnhancedStore } from '@reduxjs/toolkit';\nimport { enablePatches, produceWithPatches, applyPatches as immerApplyPatches } from 'immer';\nimport type { Patch as ImmerPatch } from 'immer';\nimport type { PatchCapableAdapter, Patch } from 'acture';\n\nenablePatches();\n\nexport interface CreateReduxAdapterOptions<S> {\n initialState: S;\n /** Optional action type prefix for the internal setState action.\n * Default `'acture/setState'`. Useful only if the same store also\n * hosts a slice that wants to react to this action. */\n actionType?: string;\n}\n\n/**\n * Build a `PatchCapableAdapter<S>` backed by a fresh single-slice RTK\n * store. Returns the adapter plus the underlying store (for devtools\n * integration).\n */\nexport function createReduxAdapter<S>(\n options: CreateReduxAdapterOptions<S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<S> } {\n const actionType = options.actionType ?? 'acture/setState';\n const replace = createAction<S>(actionType);\n\n const reducer = createReducer<S>(options.initialState, (builder) => {\n builder.addCase(replace, (_state, action) => action.payload);\n });\n\n const store = configureStore<S>({\n reducer,\n // Our payload IS the next state, which IS the next store value —\n // serializability and immutability are guaranteed by Immer upstream\n // of dispatch. Disable RTK's defensive middleware so the action\n // doesn't trip warnings for plain (already-immutable) objects.\n middleware: (getDefault) =>\n getDefault({ serializableCheck: false, immutableCheck: false }),\n });\n\n return wrapAdapter(store, {\n select: (s) => s,\n makeReplace: (next) => replace(next),\n });\n}\n\n/** Selector + action-creator pair binding the adapter to one slice of\n * an existing store. */\nexport interface ReduxAdapterSlice<RootState, S> {\n select: (root: RootState) => S;\n /** Returns the action that, when dispatched, replaces the slice\n * state with the provided next value. */\n makeReplace: (next: S) => Action;\n}\n\n/**\n * Wrap an existing RTK store and treat one slice as acture's state.\n * The host supplies a selector and an action creator for replacing\n * the slice in one shot.\n */\nexport function wrapReduxStore<RootState, S>(\n store: EnhancedStore<RootState>,\n slice: ReduxAdapterSlice<RootState, S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<RootState> } {\n return wrapAdapter(store, slice);\n}\n\n/* ───────────────────────── internals ──────────────────────────────── */\n\nfunction wrapAdapter<RootState, S>(\n store: EnhancedStore<RootState>,\n slice: ReduxAdapterSlice<RootState, S>,\n): PatchCapableAdapter<S> & { readonly store: EnhancedStore<RootState> } {\n let previous: S = slice.select(store.getState());\n\n return {\n store,\n supportsPatches: true,\n getState: () => slice.select(store.getState()),\n\n setState(updater) {\n const current = slice.select(store.getState());\n // Immer's overloaded signature wants `Draft<S>` in the recipe;\n // acture's contract is `S`. Cast through `Function` to bridge.\n const recipe = (draft: S): S | void =>\n (updater as (s: S) => S | void)(draft);\n const result = (produceWithPatches as unknown as (\n base: S,\n recipe: (d: S) => S | void,\n ) => [S, unknown, unknown])(current, recipe);\n const next = result[0];\n store.dispatch(slice.makeReplace(next));\n },\n\n subscribe(listener) {\n return store.subscribe(() => {\n const next = slice.select(store.getState());\n if (next === previous) return; // RTK fires on any dispatch\n const prev = previous;\n previous = next;\n listener(next, prev);\n });\n },\n\n setStateWithPatches(recipe) {\n const current = slice.select(store.getState());\n const result = (produceWithPatches as unknown as (\n base: S,\n recipe: (d: S) => void,\n ) => [S, ImmerPatch[], ImmerPatch[]])(current, recipe);\n const [next, patches, inversePatches] = result;\n store.dispatch(slice.makeReplace(next));\n return {\n patches: patches.map(immerToActurePatch),\n inversePatches: inversePatches.map(immerToActurePatch),\n };\n },\n\n applyPatches(patches) {\n const current = slice.select(store.getState());\n const next = immerApplyPatches(\n current as object,\n patches.map(actureToImmerPatch),\n );\n store.dispatch(slice.makeReplace(next as S));\n },\n };\n}\n\nfunction immerToActurePatch(p: ImmerPatch): Patch {\n return {\n op: p.op as Patch['op'],\n path: p.path as readonly (string | number)[],\n value: 'value' in p ? p.value : undefined,\n };\n}\n\nfunction actureToImmerPatch(p: Patch): ImmerPatch {\n return {\n op: p.op,\n path: p.path as (string | number)[],\n value: p.value,\n };\n}\n\nexport type { PatchCapableAdapter } from 'acture';\n"]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "acture-state-redux",
3
+ "version": "1.0.0",
4
+ "description": "acture StateAdapter for Redux Toolkit (RTK). Wraps an RTK store as a PatchCapableAdapter via RTK's bundled Immer.",
5
+ "license": "Apache-2.0",
6
+ "author": "Thor Whalen",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/thorwhalen/acture.git",
10
+ "directory": "packages/state-redux"
11
+ },
12
+ "homepage": "https://github.com/thorwhalen/acture#readme",
13
+ "bugs": "https://github.com/thorwhalen/acture/issues",
14
+ "type": "module",
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "sideEffects": false,
32
+ "peerDependencies": {
33
+ "@reduxjs/toolkit": "^2.0.0",
34
+ "immer": "^10.0.0 || ^11.0.0",
35
+ "acture": "1.1.0"
36
+ },
37
+ "devDependencies": {
38
+ "@reduxjs/toolkit": "^2.5.0",
39
+ "immer": "^11.0.0",
40
+ "tsup": "^8.3.0",
41
+ "typescript": "^5.7.0",
42
+ "vitest": "^2.1.0",
43
+ "acture": "1.1.0"
44
+ },
45
+ "keywords": [
46
+ "acture",
47
+ "redux",
48
+ "redux-toolkit",
49
+ "rtk",
50
+ "state",
51
+ "command-dispatch"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "typecheck": "tsc --noEmit",
59
+ "test": "vitest run",
60
+ "clean": "rm -rf dist *.tsbuildinfo"
61
+ }
62
+ }