v2.0.0-alpha.5 #3382
markerikson
announced in
Announcements
v2.0.0-alpha.5
#3382
Replies: 1 comment
-
Really looking forward to this! Trying it out now, and bumping into a TS issue. Its quite common for us to use selectors within other selectors, like this for instance:
When I do this though, the surveysSlice object itself gets the type "any". If I change to this, then the type is correct again:
Should I register an issue for this, or is this not something you would expect to work? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is an alpha release for Redux Toolkit 2.0. This release adds a new
combineSlices
API for reducer injection, has many changes to our build setup and published package contents, updates theredux
dep to the latest alpha, updates theimmer
dep to 10.0 final, includes the latest changes from 1.9.x, and has breaking changes.Changelog
New
combineSlices
APIThe Redux core has always included
combineReducers
, which takes an object full of "slice reducer" functions and generates a reducer that calls those slice reducers. RTK'screateSlice
generates slice reducers + associated action creators, and we've taught the pattern of exporting individual action creators as named exports and the slice reducer as a default export. Meanwhile, we've never had official support for lazy-loading reducers, although we've had sample code for some "reducer injection" patterns in our docs.This release includes a new
combineSlices
API that is designed to enable lazy-loading of reducers at runtime. It accepts individual slices or an object full of slices as arguments, and automatically callscombineReducers
using thesliceObject.name
field as the key for each state field. The generated reducer function has an additional.inject()
method attached that can be used to dynamically inject additional slices at runtime. It also includes a.withLazyLoadedSlices()
method that can be used to generate TS types for reducers that will be added later. See #2776 for the original discussion around this idea.For now, we are not building this into
configureStore
, so you'll need to callconst rootReducer = combineSlices(.....)
yourself and pass that toconfigureStore({reducer: rootReducer})
.In addition, the existing
createSlice
API now has support for definingselectors
directly as part of the slice. By default, these will be generated with the assumption that the slice is mounted in the root state usingslice.name
as the field, such asname: "todos"
->rootState.todos
. You can callsliceObject.getSelectors(selectSliceState)
to generate the selectors with an alternate location, similar to howentityAdapter.getSelectors()
works.We don't have documentation added for these features yet, but here's example usages from the
combineSlices
PR tests:Basic usage: a mixture of slices and standalone reducers passed to
combineSlices
Basic slice reducer injection
Slice selectors
Build Setup Updates
We've switched our build setup to use
tsup
, an ESBuild-powered build framework. This release should have identical build artifacts to2.0.0-alpha.4
, but let us know if there are any issues!Immer 10.0
Immer 10.0 is now final, and has several major improvements and updates:
We've updated RTK to depend on the final Immer 10.0 release .
Redux 5.0 alpha and TS types updates
We've updated RTK to use the latest Redux
5.0-alpha.5
release, which tweaks theReducer
type, drops the internal$CombinedState
type, and updates middleware types to default tounknown
for actions.For RTK, we've improved type inference for store enhancers, especially those that add additional fields to the state or store.
What's Changed
tsup
by @markerikson in Switch build setup from a custom ESBuild+TS script totsup
#3362responseHandler
being used infetchBaseQuery
by @praxxis in Fix globalresponseHandler
being used infetchBaseQuery
#3137resetApiState
by @phryneas in reset internalState.currentSubscriptions onresetApiState
#3333subscriptionUpdated
as autobatched by @markerikson in Bump deps and marksubscriptionUpdated
as autobatched #3364Full Changelog: v2.0.0-alpha.4...v2.0.0-alpha.5
This discussion was created from the release v2.0.0-alpha.5.
Beta Was this translation helpful? Give feedback.
All reactions