Skip to content

Commit

Permalink
Inline what was being imported from redux (#2402)
Browse files Browse the repository at this point in the history
* Inline what was being imported from `redux`

* try with never

* Prepare files for TS 4.0+ typedefs

* Replace `typescript-tuple` in TS 4.0+ typedefs

* switch to ts 4.2

* upgrade dtslint

* remove node 14 from CI

* workaround the need for notNeededPackages.json

* Revert "upgrade dtslint"

This reverts commit feffee0.

* patch ts versions pkg

* start testing testing-utils only using TS 4.2

* unify the dtslint version used by the packages

* remove redundant setting

* bump node version on the CI

* reuse type helper in `cps`

* Try those types

* add changeset
  • Loading branch information
Andarist committed Jan 2, 2024
1 parent b93a536 commit 3867c02
Show file tree
Hide file tree
Showing 26 changed files with 4,194 additions and 123 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-lemons-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@redux-saga/core': minor
'redux-saga': minor
---

Removed a dependency on Redux to decouple the project from the exact Redux version. This should fix the compatibility with recently released Redux 5.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile --non-interactive
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node: ['14', '16']
node: ['20']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Use Node.js 16
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: yarn

- name: Install Dependencies
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"real-world": "yarn --cwd examples/real-world start",
"changeset": "changeset",
"prerelease": "yarn build",
"release": "changeset publish"
"release": "changeset publish",
"postinstall": "patch-package"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -71,6 +72,7 @@
"mitt": "^1.1.2",
"normalizr": "^3.4.1",
"npm-run-all": "^4.0.2",
"patch-package": "^8.0.0",
"prettier": "^2.8.0",
"prop-types": "^15.6.2",
"react": "^16.10.2",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"module": "../dist/redux-saga-effects.esm.js",
"types": "./effects.d.ts",
"typesVersions": {
">=4.2": {
"*": [
"../types/ts4.2/*"
]
},
">=3.6": {
"*": [
"../types/ts3.6/*"
Expand Down
13 changes: 9 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
],
"exports": {
"./effects": {
"types": "./types/ts3.6/effects.d.ts",
"types": "./types/ts4.2/effects.d.ts",
"module": "./dist/redux-saga-effects.esm.js",
"default": "./dist/redux-saga-effects.cjs.js"
},
".": {
"types": "./types/ts3.6/index.d.ts",
"types": "./types/ts4.2/index.d.ts",
"module": "./dist/redux-saga-core.esm.js",
"import": "./import-condition-proxy.mjs",
"default": "./dist/redux-saga-core.cjs.js"
Expand All @@ -27,7 +27,7 @@
"scripts": {
"test": "yarn test:types && yarn test:jest",
"test:jest": "jest",
"test:types": "dtslint types",
"test:types": "dtslint types/ts4.2",
"clean": "rimraf dist",
"prebuild": "yarn clean",
"build": "rollup -c",
Expand Down Expand Up @@ -67,7 +67,6 @@
"@redux-saga/is": "^1.1.3",
"@redux-saga/symbols": "^1.1.3",
"@redux-saga/types": "^1.2.1",
"redux": "^4.0.4",
"typescript-tuple": "^2.2.1"
},
"devDependencies": {
Expand All @@ -81,6 +80,7 @@
"jest": "^23.5.0",
"lerna-alias": "^3.0.2",
"mitt": "^1.1.2",
"redux": "^4.0.4",
"rimraf": "^3.0.0",
"rollup": "^1.23.1",
"rollup-plugin-alias": "^1.4.0",
Expand All @@ -91,6 +91,11 @@
},
"types": "./index.d.ts",
"typesVersions": {
">=4.2": {
"*": [
"./types/ts4.2/*"
]
},
">=3.6": {
"*": [
"./types/ts3.6/*"
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/internal/runSaga.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as is from '@redux-saga/is'
import { compose } from 'redux'
import proc from './proc'
import { stdChannel } from './channel'
import { immediately } from './scheduler'
import nextSagaId from './uid'
import { check, logError, noop, wrapSagaDispatch, identity, getMetaInfo } from './utils'
import { check, logError, noop, wrapSagaDispatch, identity, getMetaInfo, compose } from './utils'

const RUN_SAGA_SIGNATURE = 'runSaga(options, saga, ...args)'
const NON_GENERATOR_ERR = `${RUN_SAGA_SIGNATURE}: saga argument must be a Generator function!`
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/internal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,19 @@ export function getMetaInfo(fn) {
export function getLocation(instrumented) {
return instrumented[SAGA_LOCATION]
}

export function compose(...funcs) {
if (funcs.length === 0) {
return (arg) => arg
}

if (funcs.length === 1) {
return funcs[0]
}

return funcs.reduce(
(a, b) =>
(...args) =>
a(b(...args)),
)
}
5 changes: 2 additions & 3 deletions packages/core/types/effects.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Action, AnyAction } from 'redux'
import { Last, Reverse } from 'typescript-tuple'

import {
Expand All @@ -16,7 +15,7 @@ import {
ActionMatchingPattern,
} from '@redux-saga/types'

import { FlushableChannel, PuttableChannel, TakeableChannel } from './index'
import { FlushableChannel, PuttableChannel, TakeableChannel, Action, AnyAction } from './index'

export { ActionPattern, Effect, Pattern, SimpleEffect, StrictEffect }

Expand Down Expand Up @@ -1349,7 +1348,7 @@ export type RaceEffectDescriptor<T> = CombinatorEffectDescriptor<T>
/**
* [H, ...T] -> T
*/
export type Tail<L extends any[]> = ((...l: L) => any) extends ((h: any, ...t: infer T) => any) ? T : never
export type Tail<L extends any[]> = ((...l: L) => any) extends (h: any, ...t: infer T) => any ? T : never
/**
* [...A, B] -> A
*/
Expand Down
28 changes: 26 additions & 2 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
// TypeScript Version: 3.2
import { Action, Middleware } from 'redux'
import { Saga, Buffer, Channel, END as EndType, Predicate, SagaIterator, Task, NotUndefined } from '@redux-saga/types'
import { ForkEffect } from './effects'

export { Saga, SagaIterator, Buffer, Channel, Task }

export type Action<T extends string = string> = {
type: T
}

export interface AnyAction extends Action {
[extraProps: string]: any
}

export interface UnknownAction extends Action {
[extraProps: string]: unknown
}

interface Dispatch<A extends Action = UnknownAction> {
<T extends A>(action: T, ...extraArgs: any[]): T
}

interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
dispatch: D
getState(): S
}

export interface Middleware<_DispatchExt = {}, S = any, D extends Dispatch = Dispatch> {
(api: MiddlewareAPI<D, S>): (next: (action: never) => unknown) => (action: unknown) => unknown
}

/**
* Used by the middleware to dispatch monitoring events. Actually the middleware
* dispatches 6 events:
Expand Down Expand Up @@ -129,7 +153,7 @@ export interface SagaMiddlewareOptions<C extends object = {}> {
* If provided, the middleware will use this channel instead of the default `stdChannel` for
* take and put effects.
*/
channel?: MulticastChannel<Action>;
channel?: MulticastChannel<Action>
}

export interface SagaMiddleware<C extends object = {}> extends Middleware {
Expand Down
71 changes: 25 additions & 46 deletions packages/core/types/ts3.6/effects.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Action, AnyAction } from 'redux'
import { Last, Reverse } from 'typescript-tuple'

import {
Expand All @@ -17,7 +16,7 @@ import {
SagaIterator,
} from '@redux-saga/types'

import { FlushableChannel, PuttableChannel, TakeableChannel } from './index'
import { FlushableChannel, PuttableChannel, TakeableChannel, Action, AnyAction } from './index'

export { ActionPattern, Effect, Pattern, SimpleEffect, StrictEffect }

Expand Down Expand Up @@ -186,10 +185,7 @@ export function takeEvery<P extends ActionPattern, Fn extends (...args: any[]) =
worker: Fn,
...args: HelperWorkerParameters<ActionMatchingPattern<P>, Fn>
): ForkEffect<never>
export function takeEvery<A extends Action>(
pattern: ActionPattern<A>,
worker: (action: A) => any,
): ForkEffect<never>
export function takeEvery<A extends Action>(pattern: ActionPattern<A>, worker: (action: A) => any): ForkEffect<never>
export function takeEvery<A extends Action, Fn extends (...args: any[]) => any>(
pattern: ActionPattern<A>,
worker: Fn,
Expand All @@ -200,10 +196,7 @@ export function takeEvery<A extends Action, Fn extends (...args: any[]) => any>(
* You can also pass in a channel as argument and the behaviour is the same as
* `takeEvery(pattern, saga, ...args)`.
*/
export function takeEvery<T>(
channel: TakeableChannel<T>,
worker: (item: T) => any,
): ForkEffect<never>
export function takeEvery<T>(channel: TakeableChannel<T>, worker: (item: T) => any): ForkEffect<never>
export function takeEvery<T, Fn extends (...args: any[]) => any>(
channel: TakeableChannel<T>,
worker: Fn,
Expand Down Expand Up @@ -270,10 +263,7 @@ export function takeLatest<P extends ActionPattern, Fn extends (...args: any[])
worker: Fn,
...args: HelperWorkerParameters<ActionMatchingPattern<P>, Fn>
): ForkEffect<never>
export function takeLatest<A extends Action>(
pattern: ActionPattern<A>,
worker: (action: A) => any,
): ForkEffect<never>
export function takeLatest<A extends Action>(pattern: ActionPattern<A>, worker: (action: A) => any): ForkEffect<never>
export function takeLatest<A extends Action, Fn extends (...args: any[]) => any>(
pattern: ActionPattern<A>,
worker: Fn,
Expand All @@ -284,10 +274,7 @@ export function takeLatest<A extends Action, Fn extends (...args: any[]) => any>
* You can also pass in a channel as argument and the behaviour is the same as
* `takeLatest(pattern, saga, ...args)`.
*/
export function takeLatest<T>(
channel: TakeableChannel<T>,
worker: (item: T) => any,
): ForkEffect<never>
export function takeLatest<T>(channel: TakeableChannel<T>, worker: (item: T) => any): ForkEffect<never>
export function takeLatest<T, Fn extends (...args: any[]) => any>(
channel: TakeableChannel<T>,
worker: Fn,
Expand Down Expand Up @@ -348,10 +335,7 @@ export function takeLeading<P extends ActionPattern, Fn extends (...args: any[])
worker: Fn,
...args: HelperWorkerParameters<ActionMatchingPattern<P>, Fn>
): ForkEffect<never>
export function takeLeading<A extends Action>(
pattern: ActionPattern<A>,
worker: (action: A) => any,
): ForkEffect<never>
export function takeLeading<A extends Action>(pattern: ActionPattern<A>, worker: (action: A) => any): ForkEffect<never>
export function takeLeading<A extends Action, Fn extends (...args: any[]) => any>(
pattern: ActionPattern<A>,
worker: Fn,
Expand All @@ -362,10 +346,7 @@ export function takeLeading<A extends Action, Fn extends (...args: any[]) => any
* You can also pass in a channel as argument and the behaviour is the same as
* `takeLeading(pattern, saga, ...args)`.
*/
export function takeLeading<T>(
channel: TakeableChannel<T>,
worker: (item: T) => any,
): ForkEffect<never>
export function takeLeading<T>(channel: TakeableChannel<T>, worker: (item: T) => any): ForkEffect<never>
export function takeLeading<T, Fn extends (...args: any[]) => any>(
channel: TakeableChannel<T>,
worker: Fn,
Expand Down Expand Up @@ -481,7 +462,7 @@ export interface ChannelPutEffectDescriptor<T> {
*/
export function call<Fn extends (...args: any[]) => any>(
fn: Fn,
...args: Parameters<Fn>,
...args: Parameters<Fn>
): CallEffect<SagaReturnType<Fn>>
/**
* Same as `call([context, fn], ...args)` but supports passing a `fn` as string.
Expand Down Expand Up @@ -525,15 +506,17 @@ export type CallEffect<RT = any> = SimpleEffect<'CALL', CallEffectDescriptor<RT>

export interface CallEffectDescriptor<RT> {
context: any
fn: ((...args: any[]) => SagaIterator<RT> | Promise<RT> | RT)
fn: (...args: any[]) => SagaIterator<RT> | Promise<RT> | RT
args: any[]
}

export type SagaReturnType<S extends Function> =
S extends (...args: any[]) => SagaIterator<infer RT> ? RT :
S extends (...args: any[]) => Promise<infer RT> ? RT :
S extends (...args: any[]) => infer RT ? RT :
never;
export type SagaReturnType<S extends Function> = S extends (...args: any[]) => SagaIterator<infer RT>
? RT
: S extends (...args: any[]) => Promise<infer RT>
? RT
: S extends (...args: any[]) => infer RT
? RT
: never

/**
* Alias for `call([context, fn], ...args)`.
Expand All @@ -553,7 +536,11 @@ type Cast<A, B> = A extends B ? A : B
type AnyFunction = (...args: any[]) => any

type RequireCpsCallback<Fn extends (...args: any[]) => any> = Last<Parameters<Fn>> extends CpsCallback<any> ? Fn : never
type RequireCpsNamedCallback<Ctx, Name extends keyof Ctx> = Last<Parameters<Cast<Ctx[Name], AnyFunction>>> extends CpsCallback<any> ? Name : never
type RequireCpsNamedCallback<Ctx, Name extends keyof Ctx> = Last<
Parameters<Cast<Ctx[Name], AnyFunction>>
> extends CpsCallback<any>
? Name
: never

/**
* Creates an Effect description that instructs the middleware to invoke `fn` as
Expand Down Expand Up @@ -666,7 +653,7 @@ export type CpsEffect<RT> = SimpleEffect<'CPS', CallEffectDescriptor<RT>>
*/
export function fork<Fn extends (...args: any[]) => any>(
fn: Fn,
...args: Parameters<Fn>,
...args: Parameters<Fn>
): ForkEffect<SagaReturnType<Fn>>
/**
* Same as `fork([context, fn], ...args)` but supports passing a `fn` as string.
Expand Down Expand Up @@ -1169,11 +1156,7 @@ export function throttle<A extends Action, Fn extends (...args: any[]) => any>(
* You can also pass in a channel as argument and the behaviour is the same as
* `throttle(ms, pattern, saga, ...args)`.
*/
export function throttle<T>(
ms: number,
channel: TakeableChannel<T>,
worker: (item: T) => any,
): ForkEffect<never>
export function throttle<T>(ms: number, channel: TakeableChannel<T>, worker: (item: T) => any): ForkEffect<never>
export function throttle<T, Fn extends (...args: any[]) => any>(
ms: number,
channel: TakeableChannel<T>,
Expand Down Expand Up @@ -1264,11 +1247,7 @@ export function debounce<A extends Action, Fn extends (...args: any[]) => any>(
* You can also pass in a channel as argument and the behaviour is the same as
* `debounce(ms, pattern, saga, ...args)`.
*/
export function debounce<T>(
ms: number,
channel: TakeableChannel<T>,
worker: (item: T) => any,
): ForkEffect<never>
export function debounce<T>(ms: number, channel: TakeableChannel<T>, worker: (item: T) => any): ForkEffect<never>
export function debounce<T, Fn extends (...args: any[]) => any>(
ms: number,
channel: TakeableChannel<T>,
Expand Down Expand Up @@ -1400,7 +1379,7 @@ export type RaceEffectDescriptor<T> = CombinatorEffectDescriptor<T>
/**
* [H, ...T] -> T
*/
export type Tail<L extends any[]> = ((...l: L) => any) extends ((h: any, ...t: infer T) => any) ? T : never
export type Tail<L extends any[]> = ((...l: L) => any) extends (h: any, ...t: infer T) => any ? T : never
/**
* [...A, B] -> A
*/
Expand Down

0 comments on commit 3867c02

Please sign in to comment.