@octanejs/redux-toolkit 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dominic Gannaway
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @octanejs/redux-toolkit
2
+
3
+ [Redux Toolkit](https://redux-toolkit.js.org) and RTK Query for the
4
+ [octane](https://github.com/octanejs/octane) UI framework.
5
+
6
+ Redux Toolkit's store, reducer, middleware, selector, and RTK Query cache core
7
+ are framework-agnostic, so this package re-exports the real
8
+ `@reduxjs/toolkit@2.12.0` implementation. The React-specific RTK Query hooks,
9
+ `ApiProvider`, and dynamic-middleware dispatch-hook factory are ported onto
10
+ octane and `@octanejs/redux`.
11
+
12
+ Imports migrate by changing only the package name:
13
+
14
+ ```ts
15
+ // before
16
+ import { configureStore, createSlice } from '@reduxjs/toolkit';
17
+ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
18
+
19
+ // after
20
+ import { configureStore, createSlice } from '@octanejs/redux-toolkit';
21
+ import { createApi, fetchBaseQuery } from '@octanejs/redux-toolkit/query/react';
22
+ ```
23
+
24
+ The `/react` compatibility subpaths retain their upstream names even though
25
+ their implementation is Octane-backed. All four upstream entry points exist:
26
+
27
+ - `@octanejs/redux-toolkit`
28
+ - `@octanejs/redux-toolkit/react`
29
+ - `@octanejs/redux-toolkit/query`
30
+ - `@octanejs/redux-toolkit/query/react`
31
+
32
+ ## RTK Query
33
+
34
+ ```tsrx
35
+ import { ApiProvider } from '@octanejs/redux-toolkit/query/react';
36
+ import { api } from './api';
37
+
38
+ function Post(props) @{
39
+ const result = api.useGetPostQuery(props.id);
40
+ @if (result.isLoading) { <p>Loading…</p> }
41
+ @else if (result.isError) { <p>Failed</p> }
42
+ @else { <p>{result.data.title as string}</p> }
43
+ }
44
+
45
+ function App() @{
46
+ <ApiProvider api={api}>
47
+ <Post id={1} />
48
+ </ApiProvider>
49
+ }
50
+ ```
51
+
52
+ For an existing Redux store, configure `api.reducer` and `api.middleware` in
53
+ the normal way and use `Provider` from `@octanejs/redux`.
54
+
55
+ ## Status
56
+
57
+ Current scope, known divergences, and verification status are tracked in the
58
+ generated [bindings status table](../../docs/bindings-status.md), sourced from
59
+ this package's [`status.json`](./status.json).
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@octanejs/redux-toolkit",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "engines": {
8
+ "node": ">=22"
9
+ },
10
+ "description": "Redux Toolkit for the octane renderer — reuses Redux Toolkit and RTK Query core unchanged and ports the React hook adapters onto octane.",
11
+ "author": {
12
+ "name": "Dominic Gannaway",
13
+ "email": "dg@domgan.com"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/octanejs/octane.git",
21
+ "directory": "packages/redux-toolkit"
22
+ },
23
+ "main": "src/index.ts",
24
+ "module": "src/index.ts",
25
+ "types": "src/index.ts",
26
+ "files": [
27
+ "src",
28
+ "README.md"
29
+ ],
30
+ "exports": {
31
+ ".": "./src/index.ts",
32
+ "./react": "./src/react/index.ts",
33
+ "./query": "./src/query/index.ts",
34
+ "./query/react": "./src/query/react/index.ts"
35
+ },
36
+ "dependencies": {
37
+ "@reduxjs/toolkit": "^2.9.0",
38
+ "redux": "^5.0.1",
39
+ "reselect": "5.2.0",
40
+ "@octanejs/redux": "0.1.2"
41
+ },
42
+ "peerDependencies": {
43
+ "octane": "0.1.5"
44
+ },
45
+ "devDependencies": {
46
+ "@tsrx/react": "^0.2.37",
47
+ "esbuild": "^0.28.1",
48
+ "react": "^19.2.0",
49
+ "react-dom": "^19.2.0",
50
+ "react-redux": "9.3.0",
51
+ "vitest": "^4.1.9",
52
+ "octane": "0.1.5"
53
+ },
54
+ "scripts": {
55
+ "test": "vitest run --root ../.. --project redux-toolkit --project redux-toolkit-ssr"
56
+ }
57
+ }
@@ -0,0 +1,97 @@
1
+ // Port of @reduxjs/toolkit@2.12.0 dynamicMiddleware/react. The middleware core
2
+ // is reused verbatim; only the dispatch-hook factory swaps react-redux for the
3
+ // octane binding.
4
+ import type {
5
+ DynamicMiddlewareInstance,
6
+ GetDispatch,
7
+ GetState,
8
+ MiddlewareApiConfig,
9
+ TSHelpersExtractDispatchExtensions,
10
+ } from '@reduxjs/toolkit';
11
+ import { createDynamicMiddleware as createCoreDynamicMiddleware } from '@reduxjs/toolkit';
12
+ import type { Context } from 'octane';
13
+ import type { ReactReduxContextValue } from '@octanejs/redux';
14
+ import {
15
+ createDispatchHook,
16
+ ReactReduxContext,
17
+ useDispatch as useDefaultDispatch,
18
+ } from '@octanejs/redux';
19
+ import type { Action, Dispatch, Middleware, UnknownAction } from 'redux';
20
+
21
+ export type UseDispatchWithMiddlewareHook<
22
+ Middlewares extends Middleware<any, State, DispatchType>[] = [],
23
+ State = any,
24
+ DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
25
+ > = () => TSHelpersExtractDispatchExtensions<Middlewares> & DispatchType;
26
+
27
+ export type CreateDispatchWithMiddlewareHook<
28
+ State = any,
29
+ DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
30
+ > = {
31
+ <
32
+ Middlewares extends [
33
+ Middleware<any, State, DispatchType>,
34
+ ...Middleware<any, State, DispatchType>[],
35
+ ],
36
+ >(
37
+ ...middlewares: Middlewares
38
+ ): UseDispatchWithMiddlewareHook<Middlewares, State, DispatchType>;
39
+ withTypes<MiddlewareConfig extends MiddlewareApiConfig>(): CreateDispatchWithMiddlewareHook<
40
+ GetState<MiddlewareConfig>,
41
+ GetDispatch<MiddlewareConfig>
42
+ >;
43
+ };
44
+
45
+ type ActionFromDispatch<DispatchType extends Dispatch<Action>> =
46
+ DispatchType extends Dispatch<infer DispatchedAction> ? DispatchedAction : never;
47
+
48
+ type OctaneDynamicMiddlewareInstance<
49
+ State = any,
50
+ DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
51
+ > = DynamicMiddlewareInstance<State, DispatchType> & {
52
+ createDispatchWithMiddlewareHookFactory: (
53
+ context?: Context<ReactReduxContextValue<State, ActionFromDispatch<DispatchType>> | null>,
54
+ ) => CreateDispatchWithMiddlewareHook<State, DispatchType>;
55
+ createDispatchWithMiddlewareHook: CreateDispatchWithMiddlewareHook<State, DispatchType>;
56
+ };
57
+
58
+ export const createDynamicMiddleware = <
59
+ State = any,
60
+ DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
61
+ >(): OctaneDynamicMiddlewareInstance<State, DispatchType> => {
62
+ const instance = createCoreDynamicMiddleware<State, DispatchType>();
63
+ const createDispatchWithMiddlewareHookFactory = (
64
+ context: Context<ReactReduxContextValue<
65
+ State,
66
+ ActionFromDispatch<DispatchType>
67
+ > | null> = ReactReduxContext as Context<ReactReduxContextValue<
68
+ State,
69
+ ActionFromDispatch<DispatchType>
70
+ > | null>,
71
+ ) => {
72
+ const useDispatch =
73
+ context === ReactReduxContext
74
+ ? useDefaultDispatch
75
+ : createDispatchHook<State, ActionFromDispatch<DispatchType>>(context as any);
76
+
77
+ function createDispatchWithMiddlewareHook<
78
+ Middlewares extends Middleware<any, State, DispatchType>[],
79
+ >(...middlewares: Middlewares) {
80
+ instance.addMiddleware(...middlewares);
81
+ return useDispatch;
82
+ }
83
+ createDispatchWithMiddlewareHook.withTypes = () => createDispatchWithMiddlewareHook;
84
+ return createDispatchWithMiddlewareHook as CreateDispatchWithMiddlewareHook<
85
+ State,
86
+ DispatchType
87
+ >;
88
+ };
89
+
90
+ const createDispatchWithMiddlewareHook = createDispatchWithMiddlewareHookFactory();
91
+
92
+ return {
93
+ ...instance,
94
+ createDispatchWithMiddlewareHookFactory,
95
+ createDispatchWithMiddlewareHook,
96
+ };
97
+ };
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ // Redux Toolkit's root entry is framework-agnostic. Keep the real upstream
2
+ // implementation and its full runtime/type surface.
3
+ export * from '@reduxjs/toolkit';
@@ -0,0 +1,3 @@
1
+ // RTK Query's core entry is UI-agnostic. The generated octane hooks live at
2
+ // the compatibility subpath `@octanejs/redux-toolkit/query/react`.
3
+ export * from '@reduxjs/toolkit/query';
@@ -0,0 +1,32 @@
1
+ // Port of RTK Query's ApiProvider. It owns an isolated Toolkit store and uses
2
+ // @octanejs/redux's Provider; query hooks can also use a caller-supplied context.
3
+ import { useContext, useEffect, useState } from 'octane';
4
+ import { configureStore } from '@reduxjs/toolkit';
5
+ import { Provider, ReactReduxContext } from '@octanejs/redux';
6
+ import { setupListeners } from '@reduxjs/toolkit/query';
7
+
8
+ export function ApiProvider(props) @{
9
+ const context = props.context || ReactReduxContext;
10
+ const existingContext = useContext(context);
11
+ if (existingContext) {
12
+ throw new Error('Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.');
13
+ }
14
+
15
+ const [store] = useState(
16
+ () => configureStore({
17
+ reducer: {
18
+ [props.api.reducerPath]: props.api.reducer,
19
+ },
20
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(props.api.middleware),
21
+ }),
22
+ );
23
+
24
+ useEffect(
25
+ () => props.setupListeners === false
26
+ ? undefined
27
+ : setupListeners(store.dispatch, props.setupListeners),
28
+ [props.setupListeners, store.dispatch],
29
+ );
30
+
31
+ <Provider store={store} context={context}>{props.children}</Provider>
32
+ }
@@ -0,0 +1,10 @@
1
+ import type { Context } from 'octane';
2
+ import type { ReactReduxContextValue } from '@octanejs/redux';
3
+ import type { Api, setupListeners } from '@reduxjs/toolkit/query';
4
+
5
+ export declare function ApiProvider(props: {
6
+ children?: unknown;
7
+ api: Api<any, {}, any, any>;
8
+ setupListeners?: Parameters<typeof setupListeners>[1] | false;
9
+ context?: Context<ReactReduxContextValue | null>;
10
+ }): unknown;