redux-observable
Advanced tools
Comparing version 2.0.0 to 3.0.0-rc.1
{ | ||
"name": "redux-observable", | ||
"version": "2.0.0", | ||
"version": "3.0.0-rc.1", | ||
"description": "RxJS based middleware for Redux. Compose and cancel async actions and more.", | ||
"module": "./dist/esm/index.js", | ||
"main": "./dist/cjs/index.js", | ||
"es2015": "./dist/es2015/index.js", | ||
"main": "dist/cjs/redux-observable.cjs", | ||
"module": "dist/redux-observable.legacy-esm.js", | ||
"types": "dist/redux-observable.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"types": "./dist/redux-observable.d.ts", | ||
"import": "./dist/redux-observable.mjs", | ||
"default": "./dist/cjs/redux-observable.cjs" | ||
} | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"lint": "eslint . --ext .ts", | ||
"build": "npm run build:esm && npm run build:es2015 && npm run build:cjs && npm run build:types && npm run build:umd && npm run build:umd:min", | ||
"build:esm": "tsc -p configs/tsconfig.esm.json", | ||
"build:es2015": "tsc -p configs/tsconfig.es2015.json", | ||
"build:cjs": "tsc -p configs/tsconfig.cjs.json", | ||
"build:types": "tsc -p configs/tsconfig.types.json", | ||
"build:umd": "cross-env NODE_ENV=development webpack -o dist/redux-observable.js", | ||
"build:umd:min": "cross-env NODE_ENV=production webpack -o dist/redux-observable.min.js", | ||
"build:tests": "rimraf temp && tsc -p configs/tsconfig.test.json", | ||
"clean": "rimraf temp dist", | ||
"check": "npm run lint && npm run test", | ||
"test": "npm run lint && npm run build && npm run build:tests && mocha temp", | ||
"shipit": "npm run clean && npm run build && npm run lint && npm test && scripts/publish.sh", | ||
"docs:clean": "rimraf _book", | ||
"docs:prepare": "gitbook install", | ||
"docs:build": "npm run docs:prepare && gitbook build -g redux-observable/redux-observable && cp logo/favicon.ico _book/gitbook/images", | ||
"docs:watch": "gitbook serve", | ||
"docs:publish": "npm run docs:clean && npm run docs:build && cp CNAME _book && cd _book && git init && git commit --allow-empty -m 'update book' && git checkout -b gh-pages && touch .nojekyll && git add . && git commit -am 'update book' && git push git@github.com:redux-observable/redux-observable gh-pages --force" | ||
"build": "tsup" | ||
}, | ||
"typings": "./dist/types/index.d.ts", | ||
"files": [ | ||
@@ -68,42 +59,22 @@ "dist", | ||
"peerDependencies": { | ||
"redux": ">=4 <5" | ||
"redux": ">=5 <6" | ||
}, | ||
"dependencies": { | ||
"rxjs": "^7.0.0", | ||
"tslib": "~2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^3.5.2", | ||
"@types/mocha": "^2.2.48", | ||
"@types/node": "^14.14.3", | ||
"@types/sinon": "^4.3.1", | ||
"@typescript-eslint/eslint-plugin": "~4.22.0", | ||
"@typescript-eslint/parser": "~4.22.0", | ||
"babel-polyfill": "^6.13.0", | ||
"chai": "^4.1.2", | ||
"conventional-changelog-cli": "1.3.3", | ||
"cross-env": "^5.0.0", | ||
"eslint": "^6.5.1", | ||
"esm": "^3.2.25", | ||
"gitbook-cli": "^2.3.0", | ||
"gitbook-plugin-addcssjs": "^1.0.2", | ||
"gitbook-plugin-anker-enable": "^0.0.4", | ||
"gitbook-plugin-edit-link": "^2.0.2", | ||
"gitbook-plugin-github": "^2.0.0", | ||
"gitbook-plugin-prism": "^2.0.1", | ||
"gitbook-plugin-theme-default": "^1.0.5", | ||
"json-server": "^0.10.0", | ||
"mocha": "^3.5.3", | ||
"npm": "^7.12.0", | ||
"redux": "^4.0.0", | ||
"rimraf": "^2.5.4", | ||
"rxjs": "^7.0.0", | ||
"sinon": "^4.5.0", | ||
"ts-loader": "^6.2.0", | ||
"tslib": "~2.1.0", | ||
"typescript": "~4.2.2", | ||
"webpack": "^4.29.3", | ||
"webpack-cli": "^3.2.3", | ||
"webpack-rxjs-externals": "~2.0.0" | ||
"@types/chai": "^4.3.11", | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.10.4", | ||
"@types/sinon": "^17.0.2", | ||
"@typescript-eslint/eslint-plugin": "^6.14.0", | ||
"@typescript-eslint/parser": "^6.14.0", | ||
"chai": "^4.3.10", | ||
"conventional-changelog-cli": "^4.1.0", | ||
"eslint": "^8.55.0", | ||
"eslint-plugin-rxjs": "^5.0.3", | ||
"mocha": "^10.2.0", | ||
"redux": "^5.0.0", | ||
"rxjs": "^7.8.1", | ||
"sinon": "^17.0.1", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
@@ -14,46 +14,2 @@ <img title="logo" src="logo/logo-small.gif" width="16.5%"> | ||
> Note: this project is quite stable, but is currently in maintenance mode. Critical fixes will still be released, but for now no additional features or changes will be considered as the maintainer [@jayphelps](https://github.com/jayphelps) is not actively working on any apps that use redux-observable (or any UI apps at all, actually.) If you would like to become a maintainer, please reach out to [@jayphelps](https://github.com/jayphelps). There is some [ongoing discussion](https://github.com/redux-observable/redux-observable/issues/738) around a potential 2.0.0 release (based on the current alpha) if you'd like to join in. | ||
## Install | ||
This has peer dependencies of `rxjs@6.x.x` and `redux@4.x.x`, which will have to be installed as well. | ||
```bash | ||
npm install --save redux-observable | ||
``` | ||
> Note: current stable version `redux-observable` doesn't work with `rxjs@7.x.x`, it works with `rxjs@6.x.x`. If you still want to use `rxjs@7.x.x`, upgrade to `redux-observable@2.0.0-rc.2`. | ||
##### UMD | ||
We publish a UMD build inside our npm package. You can use it via the [unpkg](https://unpkg.com/) CDN: | ||
[https://unpkg.com/redux-observable@latest/dist/redux-observable.min.js](https://unpkg.com/redux-observable@latest/dist/redux-observable.min.js) | ||
## Watch an introduction | ||
[![Watch a video on redux-observable](http://img.youtube.com/vi/AslncyG8whg/0.jpg)](https://www.youtube.com/watch?v=AslncyG8whg) | ||
## Documentation | ||
### [https://redux-observable.js.org](https://redux-observable.js.org) | ||
## Discuss | ||
[![Join the chat at https://gitter.im/redux-observable/redux-observable](https://badges.gitter.im/redux-observable/redux-observable.svg)](https://gitter.im/redux-observable/redux-observable?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Everyone is welcome on our [Gitter channel](https://gitter.im/redux-observable/redux-observable?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)! | ||
## Custom Emoji | ||
##### Save this: | ||
<img src="https://cloud.githubusercontent.com/assets/762949/18562188/905876f6-7b37-11e6-8677-f9dd091490f6.gif" width="22" height="22" /> | ||
Add the redux-observable spinning logo to your Slack channel! [Slack Instructions](https://get.slack.help/hc/en-us/articles/206870177-Create-custom-emoji) | ||
*** | ||
*redux-observable is a community-driven, entirely volunteer project and is not officially affiliated with or sponsored by any company. | ||
:shipit: | ||
> Note: this project is quite stable, but is currently in maintenance mode. Critical fixes will still be released, but for now no additional features or changes will be considered as the maintainer [@jayphelps](https://github.com/jayphelps) is not actively working on any apps that use redux-observable (or any UI apps at all, actually.) If you would like to become a maintainer, please reach out to [@jayphelps](https://github.com/jayphelps). |
@@ -1,4 +0,3 @@ | ||
import { Action } from 'redux'; | ||
import { merge } from 'rxjs'; | ||
import { Epic } from './epic'; | ||
import type { Epic } from './epic'; | ||
@@ -8,12 +7,24 @@ /** | ||
*/ | ||
export function combineEpics<T extends Action, O extends T = T, S = void, D = any>(...epics: Epic<T, O, S, D>[]): Epic<T, O, S, D> { | ||
const merger = (...args: Parameters<Epic>) => merge( | ||
...epics.map(epic => { | ||
const output$ = epic(...args); | ||
if (!output$) { | ||
throw new TypeError(`combineEpics: one of the provided Epics "${epic.name || '<anonymous>'}" does not return a stream. Double check you\'re not missing a return statement!`); | ||
} | ||
return output$; | ||
}) | ||
); | ||
export function combineEpics< | ||
Input = unknown, | ||
Output extends Input = Input, | ||
State = void, | ||
Dependencies = any | ||
>( | ||
...epics: Epic<Input, Output, State, Dependencies>[] | ||
): Epic<Input, Output, State, Dependencies> { | ||
const merger: Epic<Input, Output, State, Dependencies> = (...args) => | ||
merge( | ||
...epics.map((epic) => { | ||
const output$ = epic(...args); | ||
if (!output$) { | ||
throw new TypeError( | ||
`combineEpics: one of the provided Epics "${ | ||
epic.name || '<anonymous>' | ||
}" does not return a stream. Double check you're not missing a return statement!` | ||
); | ||
} | ||
return output$; | ||
}) | ||
); | ||
@@ -25,7 +36,11 @@ // Technically the `name` property on Function's are supposed to be read-only. | ||
Object.defineProperty(merger, 'name', { | ||
value: `combineEpics(${epics.map(epic => epic.name || '<anonymous>').join(', ')})`, | ||
value: `combineEpics(${epics | ||
.map((epic) => epic.name || '<anonymous>') | ||
.join(', ')})`, | ||
}); | ||
} catch (e) {} | ||
} catch (e) { | ||
// noop | ||
} | ||
return merger; | ||
} |
@@ -1,6 +0,6 @@ | ||
import { Action, Middleware, MiddlewareAPI, Dispatch } from 'redux'; | ||
import type { Dispatch, Middleware, MiddlewareAPI } from 'redux'; | ||
import { Subject, from, queueScheduler } from 'rxjs'; | ||
import { map, mergeMap, observeOn, subscribeOn } from 'rxjs/operators'; | ||
import { StateObservable } from './StateObservable'; | ||
import { Epic } from './epic'; | ||
import type { Epic } from './epic'; | ||
import { warn } from './utils/console'; | ||
@@ -13,17 +13,19 @@ | ||
export interface EpicMiddleware< | ||
T extends Action, | ||
O extends T = T, | ||
S = void, | ||
D = any | ||
Input = unknown, | ||
Output extends Input = Input, | ||
State = void, | ||
Dependencies = any | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
> extends Middleware<{}, S, Dispatch<any>> { | ||
run(rootEpic: Epic<T, O, S, D>): void; | ||
> extends Middleware<{}, State> { | ||
run(rootEpic: Epic<Input, Output, State, Dependencies>): void; | ||
} | ||
export function createEpicMiddleware< | ||
T extends Action, | ||
O extends T = T, | ||
S = void, | ||
D = any | ||
>(options: Options<D> = {}): EpicMiddleware<T, O, S, D> { | ||
Input = unknown, | ||
Output extends Input = Input, | ||
State = void, | ||
Dependencies = any | ||
>( | ||
options: Options<Dependencies> = {} | ||
): EpicMiddleware<Input, Output, State, Dependencies> { | ||
// This isn't great. RxJS doesn't publicly export the constructor for | ||
@@ -34,3 +36,5 @@ // QueueScheduler nor QueueAction, so we reach in. We need to do this because | ||
const QueueScheduler: any = queueScheduler.constructor; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call | ||
const uniqueQueueScheduler: typeof queueScheduler = new QueueScheduler( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
(queueScheduler as any).schedulerActionCtor | ||
@@ -45,6 +49,8 @@ ); | ||
const epic$ = new Subject<Epic<T, O, S, D>>(); | ||
let store: MiddlewareAPI<Dispatch<any>, S>; | ||
const epic$ = new Subject<Epic<Input, Output, State, Dependencies>>(); | ||
let store: MiddlewareAPI<Dispatch<any>, State>; | ||
const epicMiddleware: EpicMiddleware<T, O, S, D> = _store => { | ||
const epicMiddleware: EpicMiddleware<Input, Output, State, Dependencies> = ( | ||
_store | ||
) => { | ||
if (process.env.NODE_ENV !== 'production' && store) { | ||
@@ -57,4 +63,4 @@ // https://github.com/redux-observable/redux-observable/issues/389 | ||
store = _store; | ||
const actionSubject$ = new Subject<T>(); | ||
const stateSubject$ = new Subject<S>(); | ||
const actionSubject$ = new Subject<Input>(); | ||
const stateSubject$ = new Subject<State>(); | ||
const action$ = actionSubject$ | ||
@@ -69,3 +75,3 @@ .asObservable() | ||
const result$ = epic$.pipe( | ||
map(epic => { | ||
map((epic) => { | ||
const output$ = epic(action$, state$, options.dependencies!); | ||
@@ -75,4 +81,5 @@ | ||
throw new TypeError( | ||
`Your root Epic "${epic.name || | ||
'<anonymous>'}" does not return a stream. Double check you\'re not missing a return statement!` | ||
`Your root Epic "${ | ||
epic.name || '<anonymous>' | ||
}" does not return a stream. Double check you're not missing a return statement!` | ||
); | ||
@@ -83,3 +90,3 @@ } | ||
}), | ||
mergeMap(output$ => | ||
mergeMap((output$) => | ||
from(output$).pipe( | ||
@@ -94,4 +101,4 @@ subscribeOn(uniqueQueueScheduler), | ||
return next => { | ||
return action => { | ||
return (next) => { | ||
return (action) => { | ||
// Downstream middleware gets the action first, | ||
@@ -105,3 +112,3 @@ // which includes their reducers, so state is | ||
stateSubject$.next(store.getState()); | ||
actionSubject$.next(action); | ||
actionSubject$.next(action as Input); | ||
@@ -113,3 +120,3 @@ return result; | ||
epicMiddleware.run = rootEpic => { | ||
epicMiddleware.run = (rootEpic) => { | ||
if (process.env.NODE_ENV !== 'production' && !store) { | ||
@@ -116,0 +123,0 @@ warn( |
@@ -1,9 +0,8 @@ | ||
import { Action } from 'redux'; | ||
import { Observable } from 'rxjs'; | ||
import { StateObservable } from './StateObservable'; | ||
import type { Observable } from 'rxjs'; | ||
import type { StateObservable } from './StateObservable'; | ||
export declare interface Epic< | ||
Input extends Action = any, | ||
Input = unknown, | ||
Output extends Input = Input, | ||
State = any, | ||
State = void, | ||
Dependencies = any | ||
@@ -10,0 +9,0 @@ > { |
@@ -1,8 +0,7 @@ | ||
export { createEpicMiddleware, EpicMiddleware } from './createEpicMiddleware'; | ||
export { StateObservable } from './StateObservable'; | ||
export { Epic } from './epic'; | ||
export { combineEpics } from './combineEpics'; | ||
export { createEpicMiddleware, type EpicMiddleware } from './createEpicMiddleware'; | ||
export type { Epic } from './epic'; | ||
export { ofType } from './operators'; | ||
// eslint-disable-next-line camelcase | ||
export { resetDeprecationsSeen as __FOR_TESTING__resetDeprecationsSeen } from './utils/console'; |
@@ -1,10 +0,6 @@ | ||
import { Action } from 'redux'; | ||
import { OperatorFunction } from 'rxjs'; | ||
import { isAction, type Action } from 'redux'; | ||
import type { OperatorFunction } from 'rxjs'; | ||
import { filter } from 'rxjs/operators'; | ||
import { warn } from './utils/console'; | ||
const keyHasType = (type: unknown, key: unknown) => { | ||
return type === key || (typeof key === 'function' && type === key.toString()); | ||
}; | ||
/** | ||
@@ -18,5 +14,5 @@ * Inferring the types of this is a bit challenging, and only works in newer | ||
// All possible actions your app can dispatch | ||
Input extends Action, | ||
Input, | ||
// The types you want to filter for | ||
Type extends Input['type'], | ||
Type extends string, | ||
// The resulting actions that match the above types | ||
@@ -31,3 +27,3 @@ Output extends Input = Extract<Input, Action<Type>> | ||
} | ||
if (types.some(key => key === null || key === undefined)) { | ||
if (types.some((key) => key === null || key === undefined)) { | ||
warn('ofType was called with one or more undefined or null values!'); | ||
@@ -39,7 +35,9 @@ } | ||
len === 1 | ||
? (action): action is Output => keyHasType(action.type, types[0]) | ||
? (action): action is Output => isAction(action) && action.type === types[0] | ||
: (action): action is Output => { | ||
for (let i = 0; i < len; i++) { | ||
if (keyHasType(action.type, types[i])) { | ||
return true; | ||
if (isAction(action)) { | ||
for (let i = 0; i < len; i++) { | ||
if (action.type === types[i]) { | ||
return true; | ||
} | ||
} | ||
@@ -46,0 +44,0 @@ } |
@@ -8,3 +8,3 @@ import { Observable, Subject } from 'rxjs'; | ||
constructor(input$: Observable<S>, initialState: S) { | ||
super(subscriber => { | ||
super((subscriber) => { | ||
const subscription = this.__notifier.subscribe(subscriber); | ||
@@ -18,3 +18,3 @@ if (subscription && !subscription.closed) { | ||
this.value = initialState; | ||
input$.subscribe(value => { | ||
input$.subscribe((value) => { | ||
// We only want to update state$ if it has actually changed since | ||
@@ -21,0 +21,0 @@ // redux requires reducers use immutability patterns. |
@@ -6,5 +6,6 @@ let deprecationsSeen: { [key: string]: boolean } = {}; | ||
const consoleWarn = (typeof console === 'object' && typeof console.warn === 'function') | ||
? (...args: any[]) => console.warn(...args) | ||
: () => { }; | ||
const consoleWarn = | ||
typeof console === 'object' && typeof console.warn === 'function' | ||
? console.warn.bind(console) | ||
: () => {}; | ||
@@ -11,0 +12,0 @@ export const deprecate = (msg: string): void => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
4043793
1
16
31183
12
2
18
15
+ Addedredux@5.0.1(transitive)
- Removedrxjs@^7.0.0
- Removedtslib@~2.1.0
- Removed@babel/runtime@7.26.0(transitive)
- Removedredux@4.2.1(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedrxjs@7.8.1(transitive)
- Removedtslib@2.1.0(transitive)