From a6288423630c9afbce609cddee56653916ba88f6 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sat, 28 Jan 2023 17:05:01 -0500 Subject: [PATCH 1/2] Remove legacy `isMinified` check --- src/index.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3929a923d8..23e2293666 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,6 @@ import combineReducers from './combineReducers' import bindActionCreators from './bindActionCreators' import applyMiddleware from './applyMiddleware' import compose from './compose' -import warning from './utils/warning' import __DO_NOT_USE__ActionTypes from './utils/actionTypes' // types @@ -38,26 +37,6 @@ export { MiddlewareAPI, Middleware } from './types/middleware' // actions export { Action, AnyAction } from './types/actions' -/* - * This is a dummy function to check if the function name has been altered by minification. - * If the function has been minified and NODE_ENV !== 'production', warn the user. - */ -function isCrushed() {} - -if ( - process.env.NODE_ENV !== 'production' && - typeof isCrushed.name === 'string' && - isCrushed.name !== 'isCrushed' -) { - warning( - 'You are currently using minified code outside of NODE_ENV === "production". ' + - 'This means that you are running a slower development build of Redux. ' + - 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + - 'or setting mode to production in webpack (https://webpack.js.org/configuration/mode/) ' + - 'to ensure you have the correct code for your production build.' - ) -} - export { createStore, combineReducers, From 37350b2dd79e5deee1bc6bed7b2af53907d0319c Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sat, 28 Jan 2023 17:36:07 -0500 Subject: [PATCH 2/2] Port `createStore` deprecation from 4.x branch --- src/createStore.ts | 174 +++++++++++++++++++++++++++++++++++---------- src/index.ts | 3 +- 2 files changed, 140 insertions(+), 37 deletions(-) diff --git a/src/createStore.ts b/src/createStore.ts index 4c333868c3..807e87d9cb 100644 --- a/src/createStore.ts +++ b/src/createStore.ts @@ -15,55 +15,65 @@ import isPlainObject from './utils/isPlainObject' import { kindOf } from './utils/kindOf' /** - * Creates a Redux store that holds the state tree. - * The only way to change the data in the store is to call `dispatch()` on it. + * @deprecated * - * There should only be a single store in your app. To specify how different - * parts of the state tree respond to actions, you may combine several reducers - * into a single reducer function by using `combineReducers`. + * **We recommend using the `configureStore` method + * of the `@reduxjs/toolkit` package**, which replaces `createStore`. * - * @param reducer A function that returns the next state tree, given - * the current state tree and the action to handle. + * Redux Toolkit is our recommended approach for writing Redux logic today, + * including store setup, reducers, data fetching, and more. * - * @param preloadedState The initial state. You may optionally specify it - * to hydrate the state from the server in universal apps, or to restore a - * previously serialized user session. - * If you use `combineReducers` to produce the root reducer function, this must be - * an object with the same shape as `combineReducers` keys. + * **For more details, please read this Redux docs page:** + * **https://redux.js.org/introduction/why-rtk-is-redux-today** * - * @param enhancer The store enhancer. You may optionally specify it - * to enhance the store with third-party capabilities such as middleware, - * time travel, persistence, etc. The only store enhancer that ships with Redux - * is `applyMiddleware()`. + * `configureStore` from Redux Toolkit is an improved version of `createStore` that + * simplifies setup and helps avoid common bugs. + * + * You should not be using the `redux` core package by itself today, except for learning purposes. + * The `createStore` method from the core `redux` package will not be removed, but we encourage + * all users to migrate to using Redux Toolkit for all Redux code. + * + * If you want to use `createStore` without this visual deprecation warning, use + * the `legacy_createStore` import instead: + * + * `import { legacy_createStore as createStore} from 'redux'` * - * @returns A Redux store that lets you read the state, dispatch actions - * and subscribe to changes. */ -export default function createStore< - S, - A extends Action, - Ext = {}, - StateExt = never ->( +export function createStore( reducer: Reducer, enhancer?: StoreEnhancer ): Store, A, StateExt, Ext> & Ext -export default function createStore< - S, - A extends Action, - Ext = {}, - StateExt = never ->( +/** + * @deprecated + * + * **We recommend using the `configureStore` method + * of the `@reduxjs/toolkit` package**, which replaces `createStore`. + * + * Redux Toolkit is our recommended approach for writing Redux logic today, + * including store setup, reducers, data fetching, and more. + * + * **For more details, please read this Redux docs page:** + * **https://redux.js.org/introduction/why-rtk-is-redux-today** + * + * `configureStore` from Redux Toolkit is an improved version of `createStore` that + * simplifies setup and helps avoid common bugs. + * + * You should not be using the `redux` core package by itself today, except for learning purposes. + * The `createStore` method from the core `redux` package will not be removed, but we encourage + * all users to migrate to using Redux Toolkit for all Redux code. + * + * If you want to use `createStore` without this visual deprecation warning, use + * the `legacy_createStore` import instead: + * + * `import { legacy_createStore as createStore} from 'redux'` + * + */ +export function createStore( reducer: Reducer, preloadedState?: PreloadedState, enhancer?: StoreEnhancer ): Store, A, StateExt, Ext> & Ext -export default function createStore< - S, - A extends Action, - Ext = {}, - StateExt = never ->( +export function createStore( reducer: Reducer, preloadedState?: PreloadedState | StoreEnhancer, enhancer?: StoreEnhancer @@ -367,3 +377,95 @@ export default function createStore< } as unknown as Store, A, StateExt, Ext> & Ext return store } + +/** + * Creates a Redux store that holds the state tree. + * + * **We recommend using `configureStore` from the + * `@reduxjs/toolkit` package**, which replaces `createStore`: + * **https://redux.js.org/introduction/why-rtk-is-redux-today** + * + * The only way to change the data in the store is to call `dispatch()` on it. + * + * There should only be a single store in your app. To specify how different + * parts of the state tree respond to actions, you may combine several reducers + * into a single reducer function by using `combineReducers`. + * + * @param {Function} reducer A function that returns the next state tree, given + * the current state tree and the action to handle. + * + * @param {any} [preloadedState] The initial state. You may optionally specify it + * to hydrate the state from the server in universal apps, or to restore a + * previously serialized user session. + * If you use `combineReducers` to produce the root reducer function, this must be + * an object with the same shape as `combineReducers` keys. + * + * @param {Function} [enhancer] The store enhancer. You may optionally specify it + * to enhance the store with third-party capabilities such as middleware, + * time travel, persistence, etc. The only store enhancer that ships with Redux + * is `applyMiddleware()`. + * + * @returns {Store} A Redux store that lets you read the state, dispatch actions + * and subscribe to changes. + */ +export function legacy_createStore< + S, + A extends Action, + Ext = {}, + StateExt = never +>( + reducer: Reducer, + enhancer?: StoreEnhancer +): Store, A, StateExt, Ext> & Ext +/** + * Creates a Redux store that holds the state tree. + * + * **We recommend using `configureStore` from the + * `@reduxjs/toolkit` package**, which replaces `createStore`: + * **https://redux.js.org/introduction/why-rtk-is-redux-today** + * + * The only way to change the data in the store is to call `dispatch()` on it. + * + * There should only be a single store in your app. To specify how different + * parts of the state tree respond to actions, you may combine several reducers + * into a single reducer function by using `combineReducers`. + * + * @param {Function} reducer A function that returns the next state tree, given + * the current state tree and the action to handle. + * + * @param {any} [preloadedState] The initial state. You may optionally specify it + * to hydrate the state from the server in universal apps, or to restore a + * previously serialized user session. + * If you use `combineReducers` to produce the root reducer function, this must be + * an object with the same shape as `combineReducers` keys. + * + * @param {Function} [enhancer] The store enhancer. You may optionally specify it + * to enhance the store with third-party capabilities such as middleware, + * time travel, persistence, etc. The only store enhancer that ships with Redux + * is `applyMiddleware()`. + * + * @returns {Store} A Redux store that lets you read the state, dispatch actions + * and subscribe to changes. + */ +export function legacy_createStore< + S, + A extends Action, + Ext = {}, + StateExt = never +>( + reducer: Reducer, + preloadedState?: PreloadedState, + enhancer?: StoreEnhancer +): Store, A, StateExt, Ext> & Ext +export function legacy_createStore< + S, + A extends Action, + Ext = {}, + StateExt = never +>( + reducer: Reducer, + preloadedState?: PreloadedState | StoreEnhancer, + enhancer?: StoreEnhancer +): Store, A, StateExt, Ext> & Ext { + return createStore(reducer, preloadedState as any, enhancer) +} diff --git a/src/index.ts b/src/index.ts index 23e2293666..926be4d143 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ // functions -import createStore from './createStore' +import { createStore, legacy_createStore } from './createStore' import combineReducers from './combineReducers' import bindActionCreators from './bindActionCreators' import applyMiddleware from './applyMiddleware' @@ -39,6 +39,7 @@ export { Action, AnyAction } from './types/actions' export { createStore, + legacy_createStore, combineReducers, bindActionCreators, applyMiddleware,