@buoy-gg/redux 2.1.11 → 2.1.13

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.
Files changed (63) hide show
  1. package/LICENSE +58 -0
  2. package/lib/commonjs/index.js +1 -179
  3. package/lib/commonjs/preset.js +1 -98
  4. package/lib/commonjs/redux/components/ReduxActionButton.js +1 -129
  5. package/lib/commonjs/redux/components/ReduxActionDetailContent.js +1 -380
  6. package/lib/commonjs/redux/components/ReduxActionDetailView.js +1 -401
  7. package/lib/commonjs/redux/components/ReduxActionInfoView.js +1 -838
  8. package/lib/commonjs/redux/components/ReduxActionItem.js +1 -366
  9. package/lib/commonjs/redux/components/ReduxDetailViewToggle.js +1 -134
  10. package/lib/commonjs/redux/components/ReduxIcon.js +1 -18
  11. package/lib/commonjs/redux/components/ReduxModal.js +1 -530
  12. package/lib/commonjs/redux/components/index.js +1 -52
  13. package/lib/commonjs/redux/hooks/index.js +1 -25
  14. package/lib/commonjs/redux/hooks/useAutoInstrumentRedux.js +1 -197
  15. package/lib/commonjs/redux/hooks/useReduxActions.js +1 -75
  16. package/lib/commonjs/redux/index.js +1 -49
  17. package/lib/commonjs/redux/utils/autoInstrument.js +1 -270
  18. package/lib/commonjs/redux/utils/buoyReduxMiddleware.js +1 -166
  19. package/lib/commonjs/redux/utils/createReduxHistoryAdapter.js +1 -146
  20. package/lib/commonjs/redux/utils/index.js +1 -111
  21. package/lib/commonjs/redux/utils/reduxActionStore.js +1 -358
  22. package/lib/module/index.js +1 -87
  23. package/lib/module/preset.js +1 -94
  24. package/lib/module/redux/components/ReduxActionButton.js +1 -126
  25. package/lib/module/redux/components/ReduxActionDetailContent.js +1 -376
  26. package/lib/module/redux/components/ReduxActionDetailView.js +1 -397
  27. package/lib/module/redux/components/ReduxActionInfoView.js +1 -833
  28. package/lib/module/redux/components/ReduxActionItem.js +1 -362
  29. package/lib/module/redux/components/ReduxDetailViewToggle.js +1 -129
  30. package/lib/module/redux/components/ReduxIcon.js +1 -8
  31. package/lib/module/redux/components/ReduxModal.js +1 -525
  32. package/lib/module/redux/components/index.js +1 -7
  33. package/lib/module/redux/hooks/index.js +1 -4
  34. package/lib/module/redux/hooks/useAutoInstrumentRedux.js +1 -193
  35. package/lib/module/redux/hooks/useReduxActions.js +1 -71
  36. package/lib/module/redux/index.js +1 -13
  37. package/lib/module/redux/utils/autoInstrument.js +1 -260
  38. package/lib/module/redux/utils/buoyReduxMiddleware.js +1 -157
  39. package/lib/module/redux/utils/createReduxHistoryAdapter.js +1 -142
  40. package/lib/module/redux/utils/index.js +1 -8
  41. package/lib/module/redux/utils/reduxActionStore.js +1 -354
  42. package/package.json +12 -12
  43. package/lib/typescript/index.d.ts.map +0 -1
  44. package/lib/typescript/preset.d.ts.map +0 -1
  45. package/lib/typescript/redux/components/ReduxActionButton.d.ts.map +0 -1
  46. package/lib/typescript/redux/components/ReduxActionDetailContent.d.ts.map +0 -1
  47. package/lib/typescript/redux/components/ReduxActionDetailView.d.ts.map +0 -1
  48. package/lib/typescript/redux/components/ReduxActionInfoView.d.ts.map +0 -1
  49. package/lib/typescript/redux/components/ReduxActionItem.d.ts.map +0 -1
  50. package/lib/typescript/redux/components/ReduxDetailViewToggle.d.ts.map +0 -1
  51. package/lib/typescript/redux/components/ReduxIcon.d.ts.map +0 -1
  52. package/lib/typescript/redux/components/ReduxModal.d.ts.map +0 -1
  53. package/lib/typescript/redux/components/index.d.ts.map +0 -1
  54. package/lib/typescript/redux/hooks/index.d.ts.map +0 -1
  55. package/lib/typescript/redux/hooks/useAutoInstrumentRedux.d.ts.map +0 -1
  56. package/lib/typescript/redux/hooks/useReduxActions.d.ts.map +0 -1
  57. package/lib/typescript/redux/index.d.ts.map +0 -1
  58. package/lib/typescript/redux/types/index.d.ts.map +0 -1
  59. package/lib/typescript/redux/utils/autoInstrument.d.ts.map +0 -1
  60. package/lib/typescript/redux/utils/buoyReduxMiddleware.d.ts.map +0 -1
  61. package/lib/typescript/redux/utils/createReduxHistoryAdapter.d.ts.map +0 -1
  62. package/lib/typescript/redux/utils/index.d.ts.map +0 -1
  63. package/lib/typescript/redux/utils/reduxActionStore.d.ts.map +0 -1
@@ -1,197 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useAutoInstrumentRedux = useAutoInstrumentRedux;
7
- exports.useReduxAvailability = useReduxAvailability;
8
- var _react = require("react");
9
- var _autoInstrument = require("../utils/autoInstrument");
10
- /**
11
- * React hook for auto-instrumenting Redux stores
12
- *
13
- * This hook automatically patches the Redux store when the component mounts,
14
- * providing zero-config action capture for the Redux DevTools.
15
- *
16
- * Usage:
17
- * - The hook attempts to use react-redux's useStore() to get the store
18
- * - If successful, it instruments the store automatically
19
- * - If react-redux is not available or not in a Provider, it fails gracefully
20
- *
21
- * @example
22
- * ```tsx
23
- * function ReduxDevTools() {
24
- * const { isInstrumented, error } = useAutoInstrumentRedux();
25
- *
26
- * if (error) {
27
- * return <Text>Redux not available: {error}</Text>;
28
- * }
29
- *
30
- * return <ReduxActionList />;
31
- * }
32
- * ```
33
- */
34
-
35
- // ============================================
36
- // Safe Module Loading
37
- // ============================================
38
-
39
- /**
40
- * Safely attempt to load react-redux and get useStore hook
41
- */
42
- function getReactReduxUseStore() {
43
- try {
44
- // Dynamic require to handle cases where react-redux isn't installed
45
- // eslint-disable-next-line @typescript-eslint/no-var-requires
46
- const reactRedux = require("react-redux");
47
- return reactRedux.useStore;
48
- } catch {
49
- // react-redux not available
50
- return null;
51
- }
52
- }
53
-
54
- // ============================================
55
- // Hook Types
56
- // ============================================
57
-
58
- // ============================================
59
- // Main Hook
60
- // ============================================
61
-
62
- /**
63
- * Hook to automatically instrument Redux store for DevTools
64
- *
65
- * This provides zero-config Redux action capture by:
66
- * 1. Using react-redux's useStore() to get the Redux store
67
- * 2. Automatically patching store.dispatch to capture actions
68
- * 3. Cleaning up when the component unmounts
69
- */
70
- function useAutoInstrumentRedux(options = {}) {
71
- const {
72
- autoStart = true,
73
- ...instrumentOptions
74
- } = options;
75
- const [isInstrumented, setIsInstrumented] = (0, _react.useState)(false);
76
- const [isLoading, setIsLoading] = (0, _react.useState)(true);
77
- const [error, setError] = (0, _react.useState)(null);
78
- const [store, setStore] = (0, _react.useState)(null);
79
- const cleanupRef = (0, _react.useRef)(null);
80
-
81
- // Check if react-redux is available
82
- const useStoreHook = getReactReduxUseStore();
83
- const isReactReduxAvailable = useStoreHook !== null;
84
-
85
- // Try to get the store using react-redux's useStore
86
- // This must be called unconditionally due to hooks rules
87
- let reduxStore = null;
88
- let storeError = null;
89
- if (useStoreHook) {
90
- try {
91
- // eslint-disable-next-line react-hooks/rules-of-hooks
92
- reduxStore = useStoreHook();
93
- } catch (e) {
94
- // Not inside a Provider or other error
95
- storeError = e instanceof Error ? e.message : "Failed to access Redux store. Make sure your app is wrapped in a Redux Provider.";
96
- }
97
- } else {
98
- storeError = "react-redux is not installed or not available";
99
- }
100
-
101
- // Function to start instrumentation
102
- const startInstrumentation = (0, _react.useCallback)(() => {
103
- if (!reduxStore) {
104
- setError(storeError || "No Redux store available");
105
- setIsLoading(false);
106
- return;
107
- }
108
-
109
- // Check if already instrumented
110
- if ((0, _autoInstrument.isStoreInstrumented)(reduxStore)) {
111
- setIsInstrumented(true);
112
- setStore(reduxStore);
113
- setIsLoading(false);
114
- setError(null);
115
- return;
116
- }
117
- try {
118
- // Instrument the store
119
- const cleanup = (0, _autoInstrument.instrumentStore)(reduxStore, instrumentOptions);
120
- cleanupRef.current = cleanup;
121
- setIsInstrumented(true);
122
- setStore(reduxStore);
123
- setError(null);
124
- } catch (e) {
125
- setError(e instanceof Error ? e.message : "Failed to instrument Redux store");
126
- setIsInstrumented(false);
127
- } finally {
128
- setIsLoading(false);
129
- }
130
- }, [reduxStore, storeError, instrumentOptions]);
131
-
132
- // Function to stop instrumentation
133
- const stopInstrumentation = (0, _react.useCallback)(() => {
134
- if (cleanupRef.current) {
135
- cleanupRef.current();
136
- cleanupRef.current = null;
137
- }
138
- if (store) {
139
- (0, _autoInstrument.uninstrumentStore)(store);
140
- }
141
- setIsInstrumented(false);
142
- setStore(null);
143
- }, [store]);
144
-
145
- // Auto-start instrumentation on mount
146
- (0, _react.useEffect)(() => {
147
- if (autoStart) {
148
- startInstrumentation();
149
- } else {
150
- setIsLoading(false);
151
- }
152
-
153
- // Cleanup on unmount
154
- return () => {
155
- // Note: We intentionally DON'T uninstrument on unmount
156
- // This allows actions to continue being captured even when
157
- // the DevTools modal is closed. The instrumentation persists
158
- // for the lifetime of the app, similar to network/storage tools.
159
- };
160
- }, [autoStart, startInstrumentation]);
161
- return {
162
- isInstrumented,
163
- isLoading,
164
- error,
165
- isReactReduxAvailable,
166
- startInstrumentation,
167
- stopInstrumentation,
168
- store
169
- };
170
- }
171
-
172
- /**
173
- * Lightweight hook to just check if Redux is available
174
- * without auto-instrumenting
175
- */
176
- function useReduxAvailability() {
177
- const useStoreHook = getReactReduxUseStore();
178
- if (!useStoreHook) {
179
- return {
180
- isAvailable: false,
181
- error: "react-redux is not installed"
182
- };
183
- }
184
- try {
185
- // eslint-disable-next-line react-hooks/rules-of-hooks
186
- const store = useStoreHook();
187
- return {
188
- isAvailable: store !== null && store !== undefined,
189
- error: null
190
- };
191
- } catch (e) {
192
- return {
193
- isAvailable: false,
194
- error: e instanceof Error ? e.message : "Not inside a Redux Provider"
195
- };
196
- }
197
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useAutoInstrumentRedux=useAutoInstrumentRedux,exports.useReduxAvailability=useReduxAvailability;var _react=require("react"),_autoInstrument=require("../utils/autoInstrument");function getReactReduxUseStore(){try{return require("react-redux").useStore}catch{return null}}function useAutoInstrumentRedux(e={}){const{autoStart:t=!0,...r}=e,[u,n]=(0,_react.useState)(!1),[a,s]=(0,_react.useState)(!0),[l,i]=(0,_react.useState)(null),[o,c]=(0,_react.useState)(null),d=(0,_react.useRef)(null),x=getReactReduxUseStore(),R=null!==x;let m=null,f=null;if(x)try{m=x()}catch(e){f=e instanceof Error?e.message:"Failed to access Redux store. Make sure your app is wrapped in a Redux Provider."}else f="react-redux is not installed or not available";const v=(0,_react.useCallback)(()=>{if(!m)return i(f||"No Redux store available"),void s(!1);if((0,_autoInstrument.isStoreInstrumented)(m))return n(!0),c(m),s(!1),void i(null);try{const e=(0,_autoInstrument.instrumentStore)(m,r);d.current=e,n(!0),c(m),i(null)}catch(e){i(e instanceof Error?e.message:"Failed to instrument Redux store"),n(!1)}finally{s(!1)}},[m,f,r]),_=(0,_react.useCallback)(()=>{d.current&&(d.current(),d.current=null),o&&(0,_autoInstrument.uninstrumentStore)(o),n(!1),c(null)},[o]);return(0,_react.useEffect)(()=>(t?v():s(!1),()=>{}),[t,v]),{isInstrumented:u,isLoading:a,error:l,isReactReduxAvailable:R,startInstrumentation:v,stopInstrumentation:_,store:o}}function useReduxAvailability(){const e=getReactReduxUseStore();if(!e)return{isAvailable:!1,error:"react-redux is not installed"};try{return{isAvailable:null!=e(),error:null}}catch(e){return{isAvailable:!1,error:e instanceof Error?e.message:"Not inside a Redux Provider"}}}
@@ -1,75 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useReduxActions = useReduxActions;
7
- var _react = require("react");
8
- var _reduxActionStore = require("../utils/reduxActionStore");
9
- /**
10
- * Hook for consuming Redux actions from the store
11
- */
12
-
13
- function useReduxActions() {
14
- const [actions, setActions] = (0, _react.useState)(() => _reduxActionStore.reduxActionStore.getActions());
15
- const [filter, setFilter] = (0, _react.useState)({});
16
- const [isEnabled, setIsEnabled] = (0, _react.useState)(() => _reduxActionStore.reduxActionStore.getEnabled());
17
- const [selectedAction, setSelectedAction] = (0, _react.useState)(null);
18
-
19
- // Subscribe to store changes
20
- (0, _react.useEffect)(() => {
21
- const unsubscribe = _reduxActionStore.reduxActionStore.subscribe(newActions => {
22
- setActions(newActions);
23
- });
24
- return () => {
25
- unsubscribe();
26
- };
27
- }, []);
28
-
29
- // Filter actions based on current filter
30
- const filteredActions = (0, _react.useMemo)(() => {
31
- return _reduxActionStore.reduxActionStore.filterActions(filter);
32
- }, [actions, filter]);
33
-
34
- // Get stats
35
- const stats = (0, _react.useMemo)(() => {
36
- return _reduxActionStore.reduxActionStore.getStats();
37
- }, [actions]);
38
-
39
- // Get unique action types
40
- const actionTypes = (0, _react.useMemo)(() => {
41
- return _reduxActionStore.reduxActionStore.getUniqueActionTypes();
42
- }, [actions]);
43
-
44
- // Clear actions
45
- const clearActions = (0, _react.useCallback)(() => {
46
- _reduxActionStore.reduxActionStore.clearActions();
47
- setSelectedAction(null);
48
- }, []);
49
-
50
- // Toggle capture
51
- const toggleCapture = (0, _react.useCallback)(() => {
52
- const newEnabled = !isEnabled;
53
- _reduxActionStore.reduxActionStore.setEnabled(newEnabled);
54
- setIsEnabled(newEnabled);
55
- }, [isEnabled]);
56
-
57
- // Get action by ID
58
- const getActionById = (0, _react.useCallback)(id => {
59
- return _reduxActionStore.reduxActionStore.getActionById(id);
60
- }, []);
61
- return {
62
- actions,
63
- filteredActions,
64
- filter,
65
- setFilter,
66
- stats,
67
- clearActions,
68
- isEnabled,
69
- toggleCapture,
70
- actionTypes,
71
- getActionById,
72
- selectedAction,
73
- setSelectedAction
74
- };
75
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useReduxActions=useReduxActions;var _react=require("react"),_reduxActionStore=require("../utils/reduxActionStore");function useReduxActions(){const[e,t]=(0,_react.useState)(()=>_reduxActionStore.reduxActionStore.getActions()),[r,o]=(0,_react.useState)({}),[c,u]=(0,_react.useState)(()=>_reduxActionStore.reduxActionStore.getEnabled()),[n,i]=(0,_react.useState)(null);(0,_react.useEffect)(()=>{const e=_reduxActionStore.reduxActionStore.subscribe(e=>{t(e)});return()=>{e()}},[]);const s=(0,_react.useMemo)(()=>_reduxActionStore.reduxActionStore.filterActions(r),[e,r]),a=(0,_react.useMemo)(()=>_reduxActionStore.reduxActionStore.getStats(),[e]),d=(0,_react.useMemo)(()=>_reduxActionStore.reduxActionStore.getUniqueActionTypes(),[e]),A=(0,_react.useCallback)(()=>{_reduxActionStore.reduxActionStore.clearActions(),i(null)},[]),S=(0,_react.useCallback)(()=>{const e=!c;_reduxActionStore.reduxActionStore.setEnabled(e),u(e)},[c]),l=(0,_react.useCallback)(e=>_reduxActionStore.reduxActionStore.getActionById(e),[]);return{actions:e,filteredActions:s,filter:r,setFilter:o,stats:a,clearActions:A,isEnabled:c,toggleCapture:S,actionTypes:d,getActionById:l,selectedAction:n,setSelectedAction:i}}
@@ -1,49 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _types = require("./types");
7
- Object.keys(_types).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _types[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _types[key];
14
- }
15
- });
16
- });
17
- var _utils = require("./utils");
18
- Object.keys(_utils).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _utils[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _utils[key];
25
- }
26
- });
27
- });
28
- var _hooks = require("./hooks");
29
- Object.keys(_hooks).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _hooks[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _hooks[key];
36
- }
37
- });
38
- });
39
- var _components = require("./components");
40
- Object.keys(_components).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _components[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _components[key];
47
- }
48
- });
49
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _types=require("./types");Object.keys(_types).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in exports&&exports[e]===_types[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _types[e]}}))});var _utils=require("./utils");Object.keys(_utils).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in exports&&exports[e]===_utils[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _utils[e]}}))});var _hooks=require("./hooks");Object.keys(_hooks).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in exports&&exports[e]===_hooks[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _hooks[e]}}))});var _components=require("./components");Object.keys(_components).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in exports&&exports[e]===_components[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _components[e]}}))});
@@ -1,270 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getActiveStore = getActiveStore;
7
- exports.instrumentStore = instrumentStore;
8
- exports.isAutoInstrumentActive = isAutoInstrumentActive;
9
- exports.isStoreInstrumented = isStoreInstrumented;
10
- exports.isTimeTravelEnabled = isTimeTravelEnabled;
11
- exports.jumpToState = jumpToState;
12
- exports.replayAction = replayAction;
13
- exports.uninstrumentStore = uninstrumentStore;
14
- var _reduxActionStore = require("./reduxActionStore");
15
- var _buoyReduxMiddleware = require("./buoyReduxMiddleware");
16
- /**
17
- * Auto-instrumentation for Redux stores
18
- *
19
- * This module provides zero-config Redux DevTools integration by automatically
20
- * patching the store's dispatch method when the DevTools component mounts.
21
- *
22
- * Similar to how @buoy-gg/network patches globalThis.fetch, this patches
23
- * store.dispatch to capture all Redux actions without requiring manual
24
- * middleware configuration.
25
- */
26
-
27
- // ============================================
28
- // Store Tracking
29
- // ============================================
30
-
31
- /** Symbol to mark stores that have been instrumented */
32
- const INSTRUMENTED_SYMBOL = Symbol.for("@@buoy/instrumented");
33
-
34
- /** Symbol to store original dispatch reference */
35
- const ORIGINAL_DISPATCH_SYMBOL = Symbol.for("@@buoy/originalDispatch");
36
-
37
- /** Symbol to store original reducer reference */
38
- const ORIGINAL_REDUCER_SYMBOL = Symbol.for("@@buoy/originalReducer");
39
-
40
- /** Reference to the active store for time-travel operations */
41
- let activeStore = null;
42
-
43
- /** Track if store has been enhanced for time-travel */
44
- let timeTravelEnabled = false;
45
-
46
- // ============================================
47
- // Type Definitions
48
- // ============================================
49
-
50
- // ============================================
51
- // Core Instrumentation
52
- // ============================================
53
-
54
- /**
55
- * Check if a store has already been instrumented
56
- */
57
- function isStoreInstrumented(store) {
58
- return store[INSTRUMENTED_SYMBOL] === true;
59
- }
60
-
61
- /**
62
- * Instrument a Redux store for action capture
63
- *
64
- * This function patches store.dispatch to capture all actions without
65
- * requiring the user to configure middleware manually.
66
- *
67
- * @param store - The Redux store to instrument
68
- * @param options - Configuration options
69
- * @returns Cleanup function to restore original dispatch
70
- */
71
- function instrumentStore(store, options = {}) {
72
- const instrumentedStore = store;
73
-
74
- // Skip if middleware is already handling action capture
75
- // This prevents duplicate recording when both mechanisms are active
76
- if ((0, _buoyReduxMiddleware.isMiddlewareActive)()) {
77
- activeStore = store;
78
- return () => {};
79
- }
80
-
81
- // Skip if already instrumented
82
- if (instrumentedStore[INSTRUMENTED_SYMBOL]) {
83
- // Update active store reference even if already instrumented
84
- activeStore = store;
85
- return () => {};
86
- }
87
- const {
88
- enableTimeTravel = false,
89
- maxActions = 200,
90
- ignoreActions = []
91
- } = options;
92
-
93
- // Configure store
94
- _reduxActionStore.reduxActionStore.setMaxActions(maxActions);
95
-
96
- // Store original dispatch
97
- const originalDispatch = store.dispatch.bind(store);
98
- instrumentedStore[ORIGINAL_DISPATCH_SYMBOL] = originalDispatch;
99
-
100
- // Create instrumented dispatch
101
- const instrumentedDispatch = action => {
102
- // Skip if action is not a plain object with a type property
103
- // This filters out thunk functions, promises, and other non-action dispatches
104
- if (typeof action !== "object" || action === null || typeof action.type !== "string") {
105
- return originalDispatch(action);
106
- }
107
- const actionType = action.type;
108
-
109
- // Don't record devtools internal actions
110
- if (actionType.startsWith("@@buoy/")) {
111
- return originalDispatch(action);
112
- }
113
-
114
- // Don't record Redux internal actions
115
- if (actionType.startsWith("@@redux/")) {
116
- return originalDispatch(action);
117
- }
118
-
119
- // Check ignore list
120
- if (ignoreActions.includes(actionType)) {
121
- return originalDispatch(action);
122
- }
123
-
124
- // Capture timing and state
125
- const startTime = performance.now();
126
- const prevState = store.getState();
127
- const result = originalDispatch(action);
128
- const nextState = store.getState();
129
- const duration = performance.now() - startTime;
130
-
131
- // Record the action
132
- _reduxActionStore.reduxActionStore.addAction(action, prevState, nextState, duration);
133
- return result;
134
- };
135
-
136
- // Replace dispatch
137
- store.dispatch = instrumentedDispatch;
138
- instrumentedStore[INSTRUMENTED_SYMBOL] = true;
139
- activeStore = store;
140
-
141
- // Enable time-travel if requested and store supports replaceReducer
142
- if (enableTimeTravel && typeof store.replaceReducer === "function") {
143
- enableTimeTravelSupport(store);
144
- }
145
-
146
- // Return cleanup function
147
- return () => {
148
- uninstrumentStore(store);
149
- };
150
- }
151
-
152
- /**
153
- * Remove instrumentation from a store
154
- */
155
- function uninstrumentStore(store) {
156
- const instrumentedStore = store;
157
- if (!instrumentedStore[INSTRUMENTED_SYMBOL]) {
158
- return;
159
- }
160
-
161
- // Restore original dispatch
162
- const originalDispatch = instrumentedStore[ORIGINAL_DISPATCH_SYMBOL];
163
- if (originalDispatch) {
164
- store.dispatch = originalDispatch;
165
- }
166
-
167
- // Restore original reducer if time-travel was enabled
168
- const originalReducer = instrumentedStore[ORIGINAL_REDUCER_SYMBOL];
169
- if (originalReducer && typeof store.replaceReducer === "function") {
170
- store.replaceReducer(originalReducer);
171
- timeTravelEnabled = false;
172
- }
173
-
174
- // Clean up symbols
175
- delete instrumentedStore[INSTRUMENTED_SYMBOL];
176
- delete instrumentedStore[ORIGINAL_DISPATCH_SYMBOL];
177
- delete instrumentedStore[ORIGINAL_REDUCER_SYMBOL];
178
-
179
- // Clear active store reference
180
- if (activeStore === store) {
181
- activeStore = null;
182
- }
183
- }
184
-
185
- // ============================================
186
- // Time-Travel Support
187
- // ============================================
188
-
189
- /**
190
- * Enable time-travel support by wrapping the store's reducer
191
- *
192
- * This uses store.replaceReducer to inject our time-travel wrapper
193
- * dynamically, without requiring users to manually wrap their reducer.
194
- */
195
- function enableTimeTravelSupport(store) {
196
- const instrumentedStore = store;
197
-
198
- // Get current reducer by dispatching a probe action
199
- // Note: This is a workaround since there's no store.getReducer()
200
- // We'll wrap whatever reducer is currently active
201
- const currentState = store.getState();
202
-
203
- // Create a time-travel enabled reducer wrapper
204
- const timeTravelReducer = (state = currentState, action) => {
205
- // Handle jump to state action
206
- if (action.type === _buoyReduxMiddleware.BUOY_JUMP_TO_STATE) {
207
- return action.payload;
208
- }
209
-
210
- // Get the result from the original dispatch flow
211
- // Since we've already wrapped dispatch, we need to be careful here
212
- // The state will be updated by the store's internal reducer
213
- return state;
214
- };
215
-
216
- // Store reference (we can't actually get the original reducer directly)
217
- // This approach has limitations - full time-travel works better with
218
- // the explicit withBuoyDevTools wrapper
219
- instrumentedStore[ORIGINAL_REDUCER_SYMBOL] = timeTravelReducer;
220
- timeTravelEnabled = true;
221
- }
222
-
223
- /**
224
- * Jump to a specific state (time-travel)
225
- *
226
- * For full time-travel support, users should use withBuoyDevTools.
227
- * This limited version attempts to work with auto-instrumentation.
228
- */
229
- function jumpToState(state) {
230
- if (activeStore) {
231
- activeStore.dispatch({
232
- type: _buoyReduxMiddleware.BUOY_JUMP_TO_STATE,
233
- payload: state
234
- });
235
- } else {
236
- console.warn("[BuoyRedux] Cannot jump to state - no store instrumented");
237
- }
238
- }
239
-
240
- /**
241
- * Replay an action (dispatch it again)
242
- */
243
- function replayAction(action) {
244
- if (activeStore) {
245
- activeStore.dispatch(action);
246
- } else {
247
- console.warn("[BuoyRedux] Cannot replay action - no store instrumented");
248
- }
249
- }
250
-
251
- /**
252
- * Get the currently active (instrumented) store
253
- */
254
- function getActiveStore() {
255
- return activeStore;
256
- }
257
-
258
- /**
259
- * Check if auto-instrumentation is active
260
- */
261
- function isAutoInstrumentActive() {
262
- return activeStore !== null && isStoreInstrumented(activeStore);
263
- }
264
-
265
- /**
266
- * Check if time-travel support is enabled
267
- */
268
- function isTimeTravelEnabled() {
269
- return timeTravelEnabled;
270
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getActiveStore=getActiveStore,exports.instrumentStore=instrumentStore,exports.isAutoInstrumentActive=isAutoInstrumentActive,exports.isStoreInstrumented=isStoreInstrumented,exports.isTimeTravelEnabled=isTimeTravelEnabled,exports.jumpToState=jumpToState,exports.replayAction=replayAction,exports.uninstrumentStore=uninstrumentStore;var _reduxActionStore=require("./reduxActionStore"),_buoyReduxMiddleware=require("./buoyReduxMiddleware");const INSTRUMENTED_SYMBOL=Symbol.for("@@buoy/instrumented"),ORIGINAL_DISPATCH_SYMBOL=Symbol.for("@@buoy/originalDispatch"),ORIGINAL_REDUCER_SYMBOL=Symbol.for("@@buoy/originalReducer");let activeStore=null,timeTravelEnabled=!1;function isStoreInstrumented(e){return!0===e[INSTRUMENTED_SYMBOL]}function instrumentStore(e,t={}){const r=e;if((0,_buoyReduxMiddleware.isMiddlewareActive)())return activeStore=e,()=>{};if(r[INSTRUMENTED_SYMBOL])return activeStore=e,()=>{};const{enableTimeTravel:n=!1,maxActions:o=200,ignoreActions:i=[]}=t;_reduxActionStore.reduxActionStore.setMaxActions(o);const u=e.dispatch.bind(e);return r[ORIGINAL_DISPATCH_SYMBOL]=u,e.dispatch=t=>{if("object"!=typeof t||null===t||"string"!=typeof t.type)return u(t);const r=t.type;if(r.startsWith("@@buoy/"))return u(t);if(r.startsWith("@@redux/"))return u(t);if(i.includes(r))return u(t);const n=performance.now(),o=e.getState(),a=u(t),c=e.getState(),s=performance.now()-n;return _reduxActionStore.reduxActionStore.addAction(t,o,c,s),a},r[INSTRUMENTED_SYMBOL]=!0,activeStore=e,n&&"function"==typeof e.replaceReducer&&enableTimeTravelSupport(e),()=>{uninstrumentStore(e)}}function uninstrumentStore(e){const t=e;if(!t[INSTRUMENTED_SYMBOL])return;const r=t[ORIGINAL_DISPATCH_SYMBOL];r&&(e.dispatch=r);const n=t[ORIGINAL_REDUCER_SYMBOL];n&&"function"==typeof e.replaceReducer&&(e.replaceReducer(n),timeTravelEnabled=!1),delete t[INSTRUMENTED_SYMBOL],delete t[ORIGINAL_DISPATCH_SYMBOL],delete t[ORIGINAL_REDUCER_SYMBOL],activeStore===e&&(activeStore=null)}function enableTimeTravelSupport(e){const t=e,r=e.getState();t[ORIGINAL_REDUCER_SYMBOL]=(e=r,t)=>t.type===_buoyReduxMiddleware.BUOY_JUMP_TO_STATE?t.payload:e,timeTravelEnabled=!0}function jumpToState(e){activeStore?activeStore.dispatch({type:_buoyReduxMiddleware.BUOY_JUMP_TO_STATE,payload:e}):console.warn("[BuoyRedux] Cannot jump to state - no store instrumented")}function replayAction(e){activeStore?activeStore.dispatch(e):console.warn("[BuoyRedux] Cannot replay action - no store instrumented")}function getActiveStore(){return activeStore}function isAutoInstrumentActive(){return null!==activeStore&&isStoreInstrumented(activeStore)}function isTimeTravelEnabled(){return timeTravelEnabled}