Skip to content

Commit

Permalink
chore: show deprecated message only in DEV (pmndrs#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Jan 10, 2023
1 parent a1d4034 commit f607260
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/middleware/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ const persistImpl: PersistImpl = (config, baseOptions) => {
'serialize' in baseOptions ||
'deserialize' in baseOptions
) {
console.warn(
'[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Please use `storage` option instead.'
)
if (__DEV__) {
console.warn(
'[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Please use `storage` option instead.'
)
}
return oldImpl(config, baseOptions)
}
return newImpl(config, baseOptions)
Expand Down
8 changes: 5 additions & 3 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ export const create = (<T>(createState: StateCreator<T, [], []> | undefined) =>
* @deprecated Use `import { create } from 'zustand'`
*/
export default ((createState: any) => {
console.warn(
"[DEPRECATED] default export is deprecated, instead import { create } from'zustand'"
)
if (__DEV__) {
console.warn(
"[DEPRECATED] default export is deprecated, instead import { create } from'zustand'"
)
}
return create(createState)
}) as Create
8 changes: 5 additions & 3 deletions src/shallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export function shallow<T>(objA: T, objB: T) {
* @deprecated Use `import { shallow } from 'zustand/shallow'`
*/
export default ((objA, objB) => {
console.warn(
"[DEPRECATED] default export is deprecated, instead import { shallow } from'zustand/shallow'"
)
if (__DEV__) {
console.warn(
"[DEPRECATED] default export is deprecated, instead import { shallow } from'zustand/shallow'"
)
}
return shallow(objA, objB)
}) as typeof shallow
8 changes: 5 additions & 3 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export const createStore = ((createState) =>
* @deprecated Use `import { createStore } from ...`
*/
export default ((createState) => {
console.warn(
'[DEPRECATED] default export is deprecated, instead import { createStore } ...'
)
if (__DEV__) {
console.warn(
'[DEPRECATED] default export is deprecated, instead import { createStore } ...'
)
}
return createStore(createState)
}) as CreateStore

Expand Down

0 comments on commit f607260

Please sign in to comment.