From 051aca01e1a4f44886300f4d48dc519dc9552d79 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Mon, 18 Apr 2022 16:58:27 -0400 Subject: [PATCH 1/2] Update Redux version in package-lock.json --- package-lock.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index a781f16f14..ee8557f55b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,8 @@ "requires": true, "packages": { "": { - "version": "4.1.1", + "name": "redux", + "version": "4.1.2", "license": "MIT", "dependencies": { "@babel/runtime": "^7.9.2" From fdf5956bdc0eee39c44fee01d95bbbdfd97a8b3e Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Mon, 18 Apr 2022 17:02:52 -0400 Subject: [PATCH 2/2] Mark `createStore` as deprecated and add `legacy_createStore` - Updated `createStore`'s doc description to mark it as `@deprecated`, so that it shows up with a visual strikethrough in editors. - Added new descriptive text to `createStore` to encourage users to migrate to RTK, and pointing to the "RTK is Redux Today" docs page - Rewrote TS typedefs for `createStore` to define it as a function with overloads, rather than a varible, to get correct docs tooltips when hovering over variable usages - Added `legacy_createStore` API as an alias without the deprecation --- index.d.ts | 134 +++++++++++++++++++++++++++++++++++++++------ src/createStore.js | 70 ++++++++++++++++------- src/index.js | 3 +- 3 files changed, 170 insertions(+), 37 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6fe4f59830..f922196611 100644 --- a/index.d.ts +++ b/index.d.ts @@ -371,35 +371,135 @@ export interface StoreCreator { ): Store & Ext } +/** + * @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 declare function createStore( + reducer: Reducer, + enhancer?: StoreEnhancer +): Store & Ext +/** + * @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 declare function createStore( + reducer: Reducer, + preloadedState?: PreloadedState, + enhancer?: StoreEnhancer +): Store & 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 + * parts of the state tree respond to actions, you may combine several reducers * into a single reducer function by using `combineReducers`. * - * @template S State object type. + * @param {Function} reducer A function that returns the next state tree, given + * the current state tree and the action to handle. * - * @param 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 [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 declare function legacy_createStore( + reducer: Reducer, + enhancer?: StoreEnhancer +): Store & Ext +/** + * Creates a Redux store that holds the state tree. * - * @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()`. + * **We recommend using `configureStore` from the + * `@reduxjs/toolkit` package**, which replaces `createStore`: + * **https://redux.js.org/introduction/why-rtk-is-redux-today** * - * @returns A Redux store that lets you read the state, dispatch actions and - * subscribe to changes. + * 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 const createStore: StoreCreator +export declare function legacy_createStore( + reducer: Reducer, + preloadedState?: PreloadedState, + enhancer?: StoreEnhancer +): Store & Ext /** * A store enhancer is a higher-order function that composes a store creator diff --git a/src/createStore.js b/src/createStore.js index 5e64e323d1..b588e3a04d 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -5,31 +5,31 @@ 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 {Function} 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 {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. + * **For more details, please read this Redux docs page:** + * **https://redux.js.org/introduction/why-rtk-is-redux-today** * - * @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()`. + * `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 {Store} A Redux store that lets you read the state, dispatch actions - * and subscribe to changes. */ -export default function createStore(reducer, preloadedState, enhancer) { +export function createStore(reducer, preloadedState, enhancer) { if ( (typeof preloadedState === 'function' && typeof enhancer === 'function') || (typeof enhancer === 'function' && typeof arguments[3] === 'function') @@ -313,3 +313,35 @@ export default function createStore(reducer, preloadedState, enhancer) { [$$observable]: observable, } } + +/** + * 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 const legacy_createStore = createStore diff --git a/src/index.js b/src/index.js index 277e57b8dc..141a84e1dd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import createStore from './createStore' +import { createStore, legacy_createStore } from './createStore' import combineReducers from './combineReducers' import bindActionCreators from './bindActionCreators' import applyMiddleware from './applyMiddleware' @@ -28,6 +28,7 @@ if ( export { createStore, + legacy_createStore, combineReducers, bindActionCreators, applyMiddleware,