{"library":"redux-listener-middleware","title":"redux-listener-middleware","description":"A Redux middleware that listens for and reacts on Flux actions, allowing side-effects and async operations without thunks. Current stable version is 0.2.0, with a small set of releases. It differentiates itself by using rule-based filtering (regex or function) and action transformation before listener invocation, providing a centralized way to handle async flows while keeping reducers pure. Unlike redux-thunk, actions remain plain objects, and listeners are decoupled from action creators. Active development appears to have stalled.","language":"javascript","status":"maintenance","last_verified":"Sat Apr 25","install":{"commands":["npm install redux-listener-middleware"],"cli":null},"imports":["import listen from 'redux-listener-middleware'","const middleware = listen()","middleware.createListener((action, dispatch) => { ... })"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createStore, applyMiddleware } from 'redux';\nimport listen from 'redux-listener-middleware';\n\nconst middleware = listen();\n\nmiddleware.createListener((action, dispatch) => {\n  console.log('Received action:', action.type);\n  if (action.meta && action.meta.async) {\n    fetch(action.payload.url)\n      .then(res => res.json())\n      .then(data => dispatch({ type: action.type + '_SUCCESS', payload: data }))\n      .catch(err => dispatch({ type: action.type + '_FAIL', payload: err }));\n  }\n}).addRule(/^FETCH_/, (action) => ({ ...action, payload: { url: `/api/${action.type.slice(6).toLowerCase()}` } }));\n\nconst reducer = (state = {}, action) => {\n  switch (action.type) {\n    case 'FETCH_USER_SUCCESS':\n      return { ...state, user: action.payload };\n    default:\n      return state;\n  }\n};\n\nconst store = createStore(reducer, applyMiddleware(middleware));\n\ndispatch({ type: 'FETCH_USER', meta: { async: true } });","lang":"javascript","description":"Shows setup of middleware, listener with rule that transforms actions before async fetch, and dispatching.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}