Registry / web-framework / redux-middleware-oneshot

redux-middleware-oneshot

JSON →
library0.1.1jsnpmunverified

Creates a Redux middleware that invokes a setup function exactly once, when the first action passes through the middleware chain, allowing you to dispatch actions from arbitrary event sources (e.g., event emitters, WebSocket listeners) in a clean and timely manner. Current version 0.1.1 is early stage with limited releases and no tests. Redux peer dependency supports versions 1.x–3.x. Differentiates from other middleware patterns by ensuring one-time initialization tied to the first Redux action.

npm install redux-middleware-oneshot
INSTALL
IMPORT
SIG · REDUX-MIDDLEWARE-O
R
redux-middleware-oneshot
web-frameworkjavascriptv0.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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]
Debug
Known issues
gotchaThe setup function only runs once, but only after the first action is dispatched. If no action is ever dispatched, the setup never initializes.
fix
Ensure at least one action is dispatched (e.g., an init action) to trigger the middleware initialization.
affects: >=0.0.0
gotchaNo tests exist in the package (as per README). Use with caution in production.
fix
Consider writing your own tests for the middleware behavior.
affects: =0.1.1
gotchaThe package has low download counts and no recent updates. It may be considered unmaintained in terms of active development.
fix
Evaluate alternatives or contribute to the package if needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: createOneShot is not a function
Using named import instead of default import: import { createOneShot } from 'redux-middleware-oneshot'
fix
Use 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
fix
Use 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
fix
Dispatch an initial dummy action to trigger the one-shot initialization: store.dispatch({ type: 'INIT' })
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
reduxrequiredpeer dependency for creating middleware, dispatching actions, and composing store enhancers
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
redux-middleware-oneshot — npm install redux-middleware-oneshot · libregistry