Skip to content
Myr

devtools: deprecate passing name directly instead of an object (#731)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Devansh Jethmalani · committed by GitHub · parent 5b3b963 · Browse files · 1 file+93 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+93 added−29 removed

  • other:+93 added−29 removed

1 file+93 added−29 removed

modified:src/middleware/devtools.ts+93 added-29 removed
39 unmodified lines
40 */41 devtools?: DevtoolsType42}4344export const devtools =45 <46 S extends State,47 CustomSetState extends SetState<S>,48 CustomGetState extends GetState<S>,49 CustomStoreApi extends StoreApi<S>50 >(51 fn: (set: NamedSet<S>, get: CustomGetState, api: CustomStoreApi) => S,52 options?:53 | string54 | {55 name?: string56 anonymousActionType?: string57 serialize?: {58 options:59 | boolean60 | {61 date?: boolean62 regex?: boolean63 undefined?: boolean64 nan?: boolean65 infinity?: boolean66 error?: boolean67 symbol?: boolean68 map?: boolean69 set?: boolean70 }44/**45 * @deprecated Passing `name` as directly will be not allowed in next major.46 * Pass the `name` in an object `{ name: ... }` instead47 */48export function devtools<49 S extends State,50 CustomSetState extends SetState<S>,51 CustomGetState extends GetState<S>,52 CustomStoreApi extends StoreApi<S>53>(54 fn: (set: NamedSet<S>, get: CustomGetState, api: CustomStoreApi) => S,55 options?: string56): (57 set: CustomSetState,58 get: CustomGetState,59 api: CustomStoreApi &60 StoreApiWithDevtools<S> & {61 dispatch?: unknown62 dispatchFromDevtools?: boolean63 }64) => S65export function devtools<66 S extends State,67 CustomSetState extends SetState<S>,68 CustomGetState extends GetState<S>,69 CustomStoreApi extends StoreApi<S>70>(71 fn: (set: NamedSet<S>, get: CustomGetState, api: CustomStoreApi) => S,72 options?: {73 name?: string74 anonymousActionType?: string75 serialize?: {76 options:77 | boolean78 | {79 date?: boolean80 regex?: boolean81 undefined?: boolean82 nan?: boolean83 infinity?: boolean84 error?: boolean85 symbol?: boolean86 map?: boolean87 set?: boolean88 }89 }90 }91): (92 set: CustomSetState,93 get: CustomGetState,94 api: CustomStoreApi &95 StoreApiWithDevtools<S> & {96 dispatch?: unknown97 dispatchFromDevtools?: boolean98 }99) => S100export function devtools<101 S extends State,102 CustomSetState extends SetState<S>,103 CustomGetState extends GetState<S>,104 CustomStoreApi extends StoreApi<S>105>(106 fn: (set: NamedSet<S>, get: CustomGetState, api: CustomStoreApi) => S,107 options?:108 | string109 | {110 name?: string111 anonymousActionType?: string112 serialize?: {113 options:114 | boolean115 | {116 date?: boolean117 regex?: boolean118 undefined?: boolean119 nan?: boolean120 infinity?: boolean121 error?: boolean122 symbol?: boolean123 map?: boolean124 set?: boolean125 }126 }73 ) =>74 (127 }128) {129 return (130 set: CustomSetState,131 get: CustomGetState,132 api: CustomStoreApi &133 StoreApiWithDevtools<S> & {134 dispatch?: unknown135 dispatchFromDevtools?: boolean136 }137 ): S => {138 let didWarnAboutNameDeprecation = false139 if (typeof options === 'string' && !didWarnAboutNameDeprecation) {140 console.warn(141 '[zustand devtools middleware]: passing `name` as directly will be not allowed in next major' +142 'pass the `name` in an object `{ name: ... }` instead'143 )144 didWarnAboutNameDeprecation = true145 }146 const devtoolsOptions =147 options === undefined148 ? { name: undefined, anonymousActionType: undefined }149 : typeof options === 'string'
185 unmodified lines
335 })336337 return initialState338 }339}340341const parseJsonThen = <T>(stringified: string, f: (parsed: T) => void) => {342 let parsed: T | undefined343 try {
9 unmodified lines