Skip to content

Releases: reduxjs/redux-toolkit

v0.7.0

08 Sep 23:12
Compare
Choose a tag to compare

This release introduces some noticeable breaking changes as we begin working our way towards 1.0.

Breaking Changes

Removal of Selectorator

RSK previously exported the createSelector function from https://github.com/planttheidea/selectorator . Selectorator wraps around Reselect, and the main selling point was that its createSelector wrapper accepted string keypath "input selectors".

However, this capability made usage with TypeScript almost useless, as the string keypaths couldn't be translated into the actual types for the values that were being extracted. Ultimately, there wasn't enough real benefit for keeping this around, and so we are removing Selectorator.

We now simply export createSelector directly from https://github.com/reduxjs/reselect instead.

Migration

Replace any string keypath usages with actual selector functions:

// before
const selectAB = createSelector(
  ["a", "b"],
  (a, b) => a + b
);

// after
const selectA = state => state.a;
const selectB = state => state.b;

const selectAB = createSelector(
    [selectA, selectB],
    (a, b) => a + b
);

Removal of "slice selectors"

createSlice tried to generate a "slice selector" function based on the provided slice name. This was basically useless, because there was no guarantee that the reducer function was being combined under that name. The dynamic name of the generated function also made it hard to use.

Migration

Remove any uses of slice.selectors (such as slice.selectors.getTodos). If necessary, replace them with separate hand-written calls to createSelector instead.

Other Changes

Customization of Default Middleware

The default middleware array generated by getDefaultMiddleware() has so far been a black box. If you needed to customize one of the middleware, or leave one out, you were forced to hand-initialize the middleware yourself.

getDefaultMiddleware now accepts an options object that allows selectively disabling specific middleware, as well as passing options to each of the middleware (such as redux-thunk's extraArgument option).

New Tutorials!

We've added a set of new tutorial pages that walk you through how to use RSK:

  • Basic Tutorial: introduces the RSK APIs in a vanilla JS page
  • Intermediate Tutorial: shows how to use RSK in a CRA app, by converting the standard Redux "todos" example to use RSK
  • Advanced Tutorial: shows how to use RSK with TypeScript, thunks for async and data fetching, and React-Redux hooks, by converting a plain React app to use RSK

Changelog

v0.6.3...v0.7.0

v0.6.3

29 Jul 04:21
Compare
Choose a tag to compare

One of the major limitations of RSK thus far is that the generated action creators only accept a single argument, which becomes the payload of the action. There's been no way to do things like:

  • add a field like meta, which is commonly used as part of the "Flux Standard Action" convention
  • pass in multiple function parameters to the action creator, and process them to set up the payload
  • Encapsulate setup work like generating unique IDs before returning the action object

That also means that the code dispatching the action has been entirely responsible for determining the correct shape of the payload.

This release adds the ability to pass in a "prepare" callback to createAction. The prepare callback must return an object containing a payload field, and may include a meta field as well. All arguments that were passed to the action creator will be passed into the prepare callback:

const testAction = createAction(
    "TEST_ACTION",
    (a: string, b: string, c: string) => ({
        payload: a + b + c,
        meta: "d"
    })
)

console.log(testAction("1", "2", "3"))
// {type: "TEST_ACTION", payload: "123", meta: "d"}

createSlice has also been updated to enable customizing the auto-generated action creators as well. Instead of passing a reducer function directly as the value inside the reducers object, pass an object containing {reducer, prepare}:

const counterSlice = createSlice({
	slice: 'counter',
	initialState: 0,
	reducers: {
	    setValue: {
		  reducer: (state, action: PayloadAction<number>) => {
		      return state + action.payload
		  },
		  prepare: (amount: number) => {
		      if(amount < 0) {
		          throw new Error("Must be a positive number!");
		      }
		      return {payload: amount}
		  }
	  }
	}
})

This resolves the related issues of #146 and #148 .

Changes

v0.6.2...v0.6.3

v0.6.1

18 Jul 04:22
Compare
Choose a tag to compare

Our UMD build (redux-starter-kit.umd.js) has actually been broken for a while, because it still tried to reference process, which doesn't exist in a web environment.

We've updated our build process to ensure that the UMD build is fixed up to correctly handle that "is dev" check.

In addition, we only had an unminified UMD dev build so far. We now include a properly minified production-mode UMD build as well, redux-starter-kit.umd.min.js.

Note that our configureStore() function defaults to different behavior in dev and prod by including extra runtime check middleware in development. The dev and prod UMD builds should match the dev/prod behavior for configureStore(), so if you are using a UMD build and want the runtime checks, make sure you link to the dev build.

Finally, note that when used as a plain script tag, the UMD builds now create a global variable named window.RSK, rather than window["redux-starter-kit"]. This is theoretically a breaking change, but given that the UMD builds have never worked right, I'm fine with calling this a "patch" instead :)

Changes

v0.6.0...v0.6.1

v0.6.0

17 Jul 01:30
Compare
Choose a tag to compare

This release includes a couple improvements to our serializable-state-invariant-middleware to enable more flexibility in defining what values are and are not serializable, as well as some additional typing tweaks to improve inference of PayloadAction types and ensure that action creators generated by createSlice() are recognized as PayloadActionCreators that have a type field.

Changes

  • Fix: SerializableStateInvariantMiddleware: Use isSerializable when checking state (@ali-rantakari - #139)
  • Allow consumer to augment middleware to tolerate certain structures (e.g. Immutable) (@kgregory - #141)
  • Fix PayloadAction inference (@kroogs - #138)
  • infer action creators from createSlice as PayloadActionCreator (@phryneas - #158)

v0.5.1

30 Apr 03:47
Compare
Choose a tag to compare

0.5.0 accidentally removed our re-exports of functions from other libraries (createSelector, createNextState, combineReducers, and compose). This release should fix that.

Changes

  • Fix accidentally removed re-exports bf2f376

v0.5.0...v0.5.1

v0.5.0

28 Apr 18:48
Compare
Choose a tag to compare

We've finally had some time to merge in several PRs that were contributed by the community. No major API changes, but there's some tooling / dependency improvements and tweaks to the typings for createSlice() that should help improve type inference of case reducers, and configureStore() now allows passing options through to the Redux DevTools Extension.

Changes

  • Create declaration files with typescript (@B3zo0 - #128)
  • Upgrade to Immer 2.x (@ezzatron - #132)
  • Improve type inference of case reducers (@denisw - #133)
  • feat(configureStore): add support for devTools options (@wldcordeiro - #130)

v0.4.3

27 Jan 15:56
Compare
Choose a tag to compare

0.4.2 and 0.4.3 contain additional typings fixes contributed by @denisw :

  • createSlice should now infer action types better (#94 )
  • createReducer should now accept other action types correctly (#104 )

v0.4.1: `createSlice` and `extraReducers`

25 Jan 03:17
Compare
Choose a tag to compare

createSlice generates action types directly from the names of the reducer functions you provide in the reducers field. However, this conceptually limits a slice's reducer to only responding to action types that it "owns" and defined.

We have always encouraged Redux users to have multiple reducer functions responding to the same action type. In order to support this, createSlice now accepts a second lookup table of action types, currently named extraReducers. (The name is not final - we're still debating options. If you've got a better name, please let us know in #83 .)

Unlike the reducers field, the extraReducers field will not generate action creators for the provided functions, and the keys should be other existing Redux action type constants.

In addition to the createSlice changes, the TS conversion process accidentally stopped re-exporting compose and combineReducers from Redux. That's been fixed.

v0.4.0: The One With TypeScript

19 Jan 03:04
Compare
Choose a tag to compare

Note: If you're not familiar with Redux Starter Kit, please see the Redux Starter Kit docs for more details.

We've had a number of requests to convert redux-starter-kit to use TypeScript. That work was done in #73, and the TS build is now available as 0.4.0 . Thanks to @denisw for doing the bulk of the work, and @Dudeonyx and @Jessidhia for providing review and feedback!

All functionality from 0.3.3 should be the same, with one exception. the redux-immutable-state-invariant middleware is now conditionally imported in dev builds, which means it should be left out of production builds and save a few bytes.

Please let us know if you find any problems, especially anything related to TypeScript usage.

v0.4.0-0: TypeScript rewrite test release

15 Jan 01:24
Compare
Choose a tag to compare

Per #73 , we've been rewriting redux-starter-kit using TypeScript. This is a preview release to see if there are any issues from the TS rewrite.

This build is available on NPM as tag redux-starter-kit@ts-next. Please try it out, especially in TS apps, and let us know if there are any issues.