{"library":"redux-observable-middleware","title":"Redux Observable Middleware","description":"Redux Observable Middleware is a lightweight Redux middleware designed for integrating RxJS-like observables directly into Redux action creators. It is currently in an early stage of development, with the latest stable version being `0.2.0`, published 10 years ago. While there isn't a defined release cadence, its purpose is to simplify handling asynchronous data streams by automatically subscribing to any object with a `subscribe` method found within an action's `observable` property. This package dispatches specific lifecycle actions (`_ON_NEXT`, `_ON_ERROR`, `_ON_COMPLETED` or custom types) as the observable emits values, completes, or errors. This approach differs from more comprehensive solutions like `redux-observable`, which utilizes \"epics\" for side effects, offering a simpler, direct method for incorporating observables into the Redux data flow.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install redux-observable-middleware"],"cli":null},"imports":["import observableMiddleware from 'redux-observable-middleware';","import * as Redux from 'redux';","import * as Rx from 'rxjs';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as Redux from 'redux';\nimport * as Rx from 'rxjs';\nimport observableMiddleware from 'redux-observable-middleware';\n\nconst ACTION_TYPE = 'INTERVAL';\n\nfunction reducer(state = null, action) {\n  console.log('Action received:', action.type, action.data || action.err);\n  switch (action.type) {\n    case `${ACTION_TYPE}_ON_NEXT`:\n      return action.data;\n    case `${ACTION_TYPE}_ON_ERROR`:\n      console.error('Observable error:', action.err);\n      return state; // Or handle error appropriately\n    case `${ACTION_TYPE}_ON_COMPLETED`:\n      console.log('Observable completed.');\n      return state;\n    default:\n      return state;\n  }\n}\n\nconst store = Redux.createStore(reducer, Redux.applyMiddleware(observableMiddleware));\n\nstore.subscribe(() => {\n  console.log('Current state:', store.getState());\n});\n\nconsole.log('Dispatching observable action...');\nstore.dispatch({\n  type: ACTION_TYPE,\n  observable: Rx.interval(1000).pipe(Rx.take(5))\n});","lang":"javascript","description":"This quickstart demonstrates how to integrate an RxJS observable into a Redux action using `redux-observable-middleware`. It sets up a basic Redux store with the middleware, dispatches an action containing an observable that emits values every second, and logs the state changes as the observable progresses through its `ON_NEXT`, `ON_ERROR`, and `ON_COMPLETED` lifecycle actions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}