Skip to content

Commit

Permalink
Merge branch 'main' into test/pmndrs#903-add-spec-with-ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Oct 2, 2023
2 parents d1b1060 + 368478b commit 24da89c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
fail-fast: false
matrix:
typescript:
- 5.1.6
- 5.0.4
- 4.9.5
- 4.8.4
- 4.7.4
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ Basic typescript usage doesn't require anything special except for writing `crea
```ts
import { create } from 'zustand'
import { devtools, persist } from 'zustand/middleware'
import type {} from '@redux-devtools/extension' // required for devtools typing

interface BearState {
bears: number
Expand Down
77 changes: 7 additions & 70 deletions src/middleware/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,11 @@ import type {
StoreMutatorIdentifier,
} from '../vanilla.ts'

// Copy types to avoid import type { Config } from '@redux-devtools/extension'
// https://github.com/pmndrs/zustand/issues/1205
type Action<T = any> = {
type: T
}
type ActionCreator<A, P extends any[] = any[]> = {
(...args: P): A
}
type EnhancerOptions = {
name?: string
actionCreators?:
| ActionCreator<any>[]
| {
[key: string]: ActionCreator<any>
}
latency?: number
maxAge?: number
serialize?:
| boolean
| {
options?:
| undefined
| boolean
| {
date?: true
regex?: true
undefined?: true
error?: true
symbol?: true
map?: true
set?: true
function?: true | ((fn: (...args: any[]) => any) => string)
}
replacer?: (key: string, value: unknown) => any
reviver?: (key: string, value: unknown) => any
immutable?: any
refs?: any
}
actionSanitizer?: <A extends Action>(action: A, id: number) => A
stateSanitizer?: <S>(state: S, index: number) => S
actionsBlacklist?: string | string[]
actionsWhitelist?: string | string[]
actionsDenylist?: string | string[]
actionsAllowlist?: string | string[]
predicate?: <S, A extends Action>(state: S, action: A) => boolean
shouldRecordChanges?: boolean
pauseActionType?: string
autoPause?: boolean
shouldStartLocked?: boolean
shouldHotReload?: boolean
shouldCatchErrors?: boolean
features?: {
pause?: boolean
lock?: boolean
persist?: boolean
export?: boolean | 'custom'
import?: boolean | 'custom'
jump?: boolean
skip?: boolean
reorder?: boolean
dispatch?: boolean
test?: boolean
}
trace?: boolean | (<A extends Action>(action: A) => string)
traceLimit?: number
}
type Config = EnhancerOptions & {
type?: string
}
type Config = Parameters<
(Window extends { __REDUX_DEVTOOLS_EXTENSION__?: infer T }
? T
: any)['connect']
>[0]

declare module '../vanilla' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -124,6 +60,7 @@ type StoreDevtools<S> = S extends {
: never

export interface DevtoolsOptions extends Config {
name?: string
enabled?: boolean
anonymousActionType?: string
store?: string
Expand Down Expand Up @@ -236,7 +173,7 @@ const devtoolsImpl: DevtoolsImpl =
;(api.setState as NamedSet<S>) = (state, replace, nameOrAction) => {
const r = set(state, replace)
if (!isRecording) return r
const action: Action<unknown> =
const action: { type: unknown } =
nameOrAction === undefined
? { type: anonymousActionType || 'anonymous' }
: typeof nameOrAction === 'string'
Expand Down
4 changes: 2 additions & 2 deletions src/traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ export type UseBoundStoreWithEqualityFn<
type CreateWithEqualityFn = {
<T, Mos extends [StoreMutatorIdentifier, unknown][] = []>(
initializer: StateCreator<T, [], Mos>,
defaultEqualityFn: <U>(a: U, b: U) => boolean
defaultEqualityFn?: <U>(a: U, b: U) => boolean
): UseBoundStoreWithEqualityFn<Mutate<StoreApi<T>, Mos>>
<T>(): <Mos extends [StoreMutatorIdentifier, unknown][] = []>(
initializer: StateCreator<T, [], Mos>,
defaultEqualityFn: <U>(a: U, b: U) => boolean
defaultEqualityFn?: <U>(a: U, b: U) => boolean
) => UseBoundStoreWithEqualityFn<Mutate<StoreApi<T>, Mos>>
}

Expand Down

0 comments on commit 24da89c

Please sign in to comment.