Skip to content

Releases: reduxjs/redux-toolkit

v1.0.3

13 Nov 04:25
Compare
Choose a tag to compare
1.0.3

v1.0.1

02 Nov 20:04
Compare
Choose a tag to compare

This release includes a TS type bugfix for prepare callbacks, adds a new match method for action creators, and re-exports additional functions from Redux.

Changes

The types for the recently added error field in prepare callbacks were too loose, and that caused them to fall back to any. This has been fixed.

There are cases when it is helpful to have a type guard to narrow action objects down to a known type, such as checking in a middleware. Generated action creators now have a actionCreator.match() type guard function attached.

We were re-exporting some methods from the Redux core, but not all of them. All Redux exports are now re-exported, including bindActionCreators.

Changelog

v1.0.0...v1.0.1

v1.0 Final!

23 Oct 13:31
Compare
Choose a tag to compare

Today I am extremely excited to announce that:

Redux Starter Kit 1.0 is now live!

To celebrate, I've put together a blog post that looks back at the history, inspirations, and development process that led us to this point:

Idiomatic Redux: Redux Starter Kit 1.0

Changes

This release contains only one new change: the ability to include an error field from a prepare callback, to match the FSA standard.

Changelog

  • feat(action): support optional error field (@tvanier - #222)

Credits and Thanks

I'd like to thank everyone who has been involved in Redux Starter Kit in any way. To highlight some of the key participants:

  • @gaearon : the creator of Redux. Wouldn't have any of this without him.
  • @modernserf: wrote the original suggestion that inspired RSK.
  • @timdorr : wrote the RFC: Redux Starter Kit issue that served as the springboard for actually getting RSK started
  • @hswolff : helped talk through the initial list of features
  • @nickmccurdy : implemented almost all of the initial build tooling and several key pieces of initial functionality
  • @shotaK: donated the redux-starter-kit package name on NPM
  • @neurosnap : ported createSlice from Autodux, and donated his implementation after writing it as a separate package
  • @denisw: ported RSK to TypeScript, and valuable suggestions on createSlice
  • @Dudeonyx , @Jessidhia: plenty of TS advice
  • @phryneas : implemented multiple new features, improved our TS types, and coached me through starting to understand how some of this complex types stuff actually works :)
  • @RichiCoder1 : ported our build setup to TSDX

Thank you so much to all of you, and everyone else who has contributed!

v0.9.1

18 Oct 18:09
Compare
Choose a tag to compare

The switch to TSDX accidentally dropped the re-export of types like Action from Redux.

Changelog

  • Fix broken re-export of Redux types d70dc31

v0.9.0...v0.9.1

v0.9.0

18 Oct 16:07
Compare
Choose a tag to compare

This release contains only build tooling changes and package updates. We've switched our build setup from a homegrown Rollup config to use TSDX instead. We're also running CI tests against multiple versions of TypeScript to try to prevent any future type changes that might affect older versions.

As part of the TSDX changes, the published package now contains the types in a single combined index.d.ts file instead of separate files, which may work better in certain build tooling setups.

In the process, we've also updated Immer from 2.1.5 to 4.0.1. This primarily adds auto-freezing of all state objects in development, but shouldn't have any actual changes for your code. See the Immer release notes for more details.

Barring any new issues, this will likely be the last point release before 1.0 release candidates in the next couple days.

Changelog

v0.8.1...v0.9.0

v0.8.1

16 Oct 01:40
Compare
Choose a tag to compare

This patch release fixes a couple small cross-version TypeScript issues that popped up in 0.8.0.

Changelog

v0.8.0...v0.8.1

v0.8.0

15 Oct 02:00
Compare
Choose a tag to compare

This release contains a couple breaking changes, including one that will affect almost all existing users. The plan is for these to be the final breaking changes before 1.0 is released, and that 1.0 will hopefully be out within the next couple weeks.

Breaking Changes

createSlice Now Requires a name Field

So far, createSlice has accepted an optional field called slice, which is used as the prefix for action types generated by that slice:

const counterSlice1 = createSlice({
    slice: "counter", // or could be left out entirely
    initialState: 0,
    reducers: {
        increment: state => state + 1,
    }
});

The slice field has been changed to name, and is now required to be a non-empty string.

const counterSlice1 = createSlice({
    name: "counter", // required!
    initialState: 0,
    reducers: {
        increment: state => state + 1,
    }
});

This removes cases where multiple slices could have accidentally generated identical action types by leaving out the slice name while having similar reducer names. The field name change from slice to name was made to clarify what the field means.

Migration: change all uses of slice to name, and add name to any createSlice() calls that didn't specify it already.

createAction Defaults to a void Payload Type

Previously, createAction("someType") would default to allowing a payload type of any when used with TypeScript. This has been changed to default to void instead. This means that you must specify the type of the payload, such as createAction<string>("someType").

Note that this is not necessary when using createSlice, as it already infers the correct payload types based on your reducer functions.

Migration: ensure that any calls to createAction() explicitly specify the payload type as a generic.

Other Changes

createSlice Exports the Case Reducer Functions

createSlice already returned an object containing the generated slice reducer function and the generated action creators. It now also includes all of the provided case reducers in a field called caseReducers.

const todosSlice = createSlice({
    name: "todos",
    initialState: [],
    reducers: {
        addTodo(state, action) {
            const {id, text} = action.payload;
            state.push({id, text});
        },
        toggleTodo(state, action) {
            const todo = state[action.payload.index];
            todo.completed = !todo.completed
        }
    },
    extraReducers: {
        ["app/logout"](state, action) {
            return []
        }
    }
});
console.log(todosSlice)
/*
{
    name: "todos",
    reducer: Function,
    actions: {
        addTodo: Function,
        toggleTodo: Function,
    },
    caseReducers: {
        addTodo: Function,
        toggleTodo: Function
    }
}
*/

Notes

Special thanks to @phryneas for coaching me through finally starting to get a vague grasp on some very complicated TS types :)

Changelog

v0.7.0...v0.8.0

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