Registry /
web-framework / redux-middleware-oneshot
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import createOneShot from 'redux-middleware-oneshot';
✗ const createOneShot = require('redux-middleware-oneshot');
Package provides a default export and is ESM-compatible, though CJS require() may work depending on bundler.
createOneShot
✓ import createOneShot from 'redux-middleware-oneshot';
✗ import { createOneShot } from 'redux-middleware-oneshot';
The function is exported as default, not as a named export. Using named import will result in undefined.
applyMiddleware usage
✓ import { applyMiddleware, createStore } from 'redux';
const middleware = createOneShot(dispatch => { ... });
const store = createStore(reducer, applyMiddleware(middleware));
✗ const store = applyMiddleware(createOneShot(...))(createStore)(reducer);
Standard Redux middleware composition. Some developers mistakenly call createOneShot inside applyMiddleware inline incorrectly.
Demonstrates creating a one-shot middleware that listens to a custom event emitter and dispatches Redux actions from it.
import { createStore, applyMiddleware } from 'redux';
import createOneShot from 'redux-middleware-oneshot';
// Example reducer
const reducer = (state = [], action) => {
if (action.type === 'ADD') {
return [...state, action.payload];
}
return state;
};
// Create middleware that dispatches an action from a simulated event emitter
const emitter = {
listeners: [],
on(event, cb) { this.listeners.push(cb); },
emit(event, data) { this.listeners.forEach(l => l(data)); }
};
const myMiddleware = createOneShot((dispatch) => {
// This runs exactly once when first action goes through
emitter.on('data', (value) => {
dispatch({ type: 'ADD', payload: value });
});
});
const store = createStore(reducer, applyMiddleware(myMiddleware));
// Trigger first action to initialize
store.dispatch({ type: '__INIT__' });
// Later, emit an event - it will be dispatched
emitter.emit('data', 42);
console.log(store.getState()); // [42]
Errors
Common errors & fixes
TypeError: createOneShot is not a function
Using named import instead of default import: import { createOneShot } from 'redux-middleware-oneshot'
fixUse default import: import createOneShot from 'redux-middleware-oneshot'
Uncaught ReferenceError: dispatch is not defined
Forgetting that the setup function receives dispatch as an argument and trying to use dispatch from outer scope
fixUse the dispatch parameter provided to the callback: createOneShot(dispatch => { ... }) The middleware does not dispatch any actions
The setup function never runs because no initial action has been dispatched through the store
fixDispatch an initial dummy action to trigger the one-shot initialization: store.dispatch({ type: 'INIT' }) Audit
Dependencies
reduxrequiredpeer dependency for creating middleware, dispatching actions, and composing store enhancers