Dynandux comes with middleware for debugging that collects the dispatched actions in a global array.
Then from the debugger, you can access the dispatched actions with stats and the current state.
Still we don't have a UI debugger like Redux, but we are working to make it happen. Feel free to contribute. But still, you can do a lot of things with dynaduxDebugMiddleware!
A significant benefit of not using a plugin debugger, but only this middleware is the performance. Plugging debuggers are crashing on a significant amount of data since they scan your state.
With this middleware, the only CPU effort is what you expand from the global array.
dynaduxDebugMiddleware
collects the dispatches in an array that you can manipulate it, providing few methods.
- The State Before and After dispatched
- An array of the dispatched actions, you can filter, etc
- Access, iterate and investigate previous states programmatically or manually
- Elapsed time of the prior dispatch
- A timestamp for each dispatch
- Set a previous state
- Travel in the time applying states
import {createStore, dynaduxDebugMiddleware} from "dynadux";
const store = createStore({
initialState: {...},
middlewares: [
dynaduxDebugMiddleware({
debuggerStoreName: 'debug_myStore', // Required, empty string means disabled debugger.
}),
],
reducers: {...},
});
Enable the middleware be localStorage
value
import {createStore, dynaduxDebugMiddleware} from "dynadux";
const STORE_DEBUG_MODE = !!localStorage.getItem('_debug_appStore');
const store = createStore({
initialState: {...},
middlewares: [
STORE_DEBUG_MODE && dynaduxDebugMiddleware({
debuggerStoreName: 'debug_myStore',
}),
],
reducers: {...},
});
Tip:
middlewares
acceptsfalse
,null
andundefined
values.
Note: Put the dynaduxDebugMiddleware
as last middleware to collect all the changes of the dispatch.
import {createStore, dynaduxDebugMiddleware} from "dynadux";
const store = createStore({
initialState: {...},
middlewares: [
dynaduxDebugMiddleware({
debuggerStoreName: 'debug_myStore', // Required
consoleDispatch: true, // Optional Consoles a dispatch (on after of dispatch) default: true
consolePayload: false, // Optional Console the payload, default: false
consoleState: false, // Optional Console the before and after version of the state, default: false
consoleMethog: 'debug', // Optional The console method to be used. Options 'log' or 'debug', default: 'debug'
consoleFilter: (action: string, payload: any) => true, // Optional Console filter with callback
}),
],
reducers: {...},
});
With the above config, the dynaduxDebugMiddleware
creates the debugger on the global variable name debug_myStore
.
This middleware, like many other debugging tools, should not be on production since it would lead to a memory leak.
interface IDynaduxDebugMiddlewareConfig {
debuggerStoreName: string; // Required, otherwise the middleware will be not loaded.
consoleDispatch?: boolean; // On After dispatch, default: true
consolePayload?: boolean; // Console the payload, default: false
consoleMethod?: 'log' | 'debug'; // Default: debug
}
The debuggerStoreName
is required. However, if you assign an empty string, this is an indication to do not load the debugger, and the performance will not be affected.
So the flag if the debugger will be loaded is if the debuggerStoreName
is an empty string or not.
In this way, you can always include the debugger on production and switch activation, providing a debuggerStoreName
or not.
Open the console and type the value of the debuggerStoreName
,for instance debug_myStore
.
You will get something like this:
Open the console and type debug_myStore.list
You will get something like this:
list
returns a preview of the collected log items.
Same as list
, including the payloads.
Open the console and type debug_myStore.log
You will get something like this:
In log
are the collected dispatched items by the debugger middleware.
You can access the history item by the index shown in the description.
For instance, type to access the log:
debug_myStore.log[3]
or
debug_myStore.log[3].after.cart
Get the currently active state.
dynaduxDebugMiddleware
provides the search
method where you can search for a text in the description of the log item non-case sensitive.
For instance:
debug_myStore.search('add_todo')
Since the log
is the array, you can use all javascript Array's methods.
For instance:
debug_myStore.log.filter(log => log.action === 'ADD_TODO')
or filter even more
debug_myStore.log.filter(log => log.action === 'ADD_TODO').filter(log => log.payload > 1)
Manually dispatch an action from debugger's console.
debug_myStore.dispatch('ADD_TODO', {id: '445', label: 'Drink a Debug beer'})
It is useful for debugging to get back in time, at a specific point, to see how the app was then. Traveling in time is helpful for animation implementations also!
debug_myStore.set(1)
You can travel in time with the methods debug_myStore.prev()
and debug_myStore.next()
.
To run back to now debug_myStore.now()
.
Every time the app is dispatching something, time is reset to now.
Ones you reached this point, you are mastering the Dynadux! It is so simple!
You can go further reading the Advanced but is not mandatory.
- FAQ Frequently asked questions
- React How to use it in react
- Sections Create sections for applications or big components
- Examples Live examples. Examples compared to redux's implementations
- Advanced Dispached promises, boost up your app and more.
- Terminology Terminology of dynadux, (is small!).
- History, Undo/Redo Middleware for History, Undo/Redo and Restore Points.
- React Dynadux Provider for Dynadux App Stores
- Change Log Changes of Dynadux per semver version
- 🏠 Home, Contents