Today we're announcing version 2.1.0 of Rematch. More or less 4 months passed since we opened the Roadmap for version 2.1.0. Here we are writing this post telling you guys all the incredible improvements and features we introduced to this new version of Rematch.
Bug fixesโ
- Typescript 4.3.X typings was causing some issues with
connect()method and Rematch. #893 - When the
payloadof an effect or reducer was explicitly adding a default value in case of null, wasn't getting inferred. #894 - When using
thisobject accessor insideeffectsproperty, wasn't autocompleted. Since getting autocomplete was like a super-man task we ended up at least not throwing an error of any. Now returns anAction<any, any>#870 init()function now accepts Rematch models likePartial<RootModel>, this can be used in conjuntion with store functionstore.addModel()for dynamically adding models. #892- Loading plugin returns the chain of promises, that means if an effect crashes you can catch that error. #907
- Upgrading TypeScript from
4.1.2version to4.3.Xcaused some unexpectednevertypes. #912 Immerpeer dependency of@rematch/immerplugin updated to > 9, we keep our official plugins updated.
New featuresโ
- We officially released
@rematch/typed-stateplugin, was an official plugin for Rematch v1, but we didn't back ported it to v2 since now. It's just258 bytes, and recommended to anyone who wants to encourage a good shape of state on any JavaScript codebase. You can read more about this plugin in the official documentation. @rematch/loadingnow has been refactored to accept more options thanbooleanornumber, now you can pass `
Store as full object
Passing full to config will create a shape where if any effect promise crashes, will save the error object inside error, if the promise resolves correctly will set success to true, and if it keeps loading, will keep the loading property to true.
It's quite similar to React-Query library, and really powerful for building interactive libraries without writing tons of reducers for our effects.
tstype FullModel = ExtraModelsFromLoading<RootModel, { type: 'full' }>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin({ type: 'full' })],})
tstype FullModel = ExtraModelsFromLoading<RootModel, { type: 'full' }>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin({ type: 'full' })],})
Store as numbers
Will work as usual, when a effect is loading will increment the number of the state.
tstype FullModel = ExtraModelsFromLoading<RootModel, { type: 'number' }>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin({ type: 'number' })],})
tstype FullModel = ExtraModelsFromLoading<RootModel, { type: 'number' }>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin({ type: 'number' })],})
Store as booleans
true or false given the effect promise if it's resolved or not.
tstype FullModel = ExtraModelsFromLoading<RootModel>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin()],})
tstype FullModel = ExtraModelsFromLoading<RootModel>export const store = init<RootModel, FullModel>({models,plugins: [loadingPlugin()],})
You can see the pull request implementation here and read more about this on the official documentation here.
Choreโ
- Now we test every night our entire CI setup with
latestandnextTypeScript versions, which means a bunch of tests integration, unit and even end-to-end in a real world React application written with TypeScript with all our plugins is tested before TypeScript releases a new version.info
This will avoid issues with future versions of Rematch + TypeScript since we're testing before TypeScript officially releases the version is causing issues, giving us time to fix the issue on Rematch side.
- Now we added
shiki-twoslashto Rematch documentation, now you can see the powerful of Rematch with TypeScript directly in the browser, not needed to download any project, just check the typings as you would do on your favorite code editor.
For instance, check this count model:
tsimport {createModel } from '@rematch/core'import type {RootModel } from './models'ยexport constcount =createModel <RootModel >()({state : 0,reducers : {increment (state ,payload : number) {returnstate +payload },},effects : (dispatch ) => ({incrementAsync (payload : number,state ) {dispatch .count .increment (payload )},}),})
tsimport {createModel } from '@rematch/core'import type {RootModel } from './models'ยexport constcount =createModel <RootModel >()({state : 0,reducers : {increment (state ,payload : number) {returnstate +payload },},effects : (dispatch ) => ({incrementAsync (payload : number,state ) {dispatch .count .increment (payload )},}),})
Hope you enjoy this new release, feel free install it as usual with your favorite package manager.
bashnpm install @rematch/core --save
bashnpm install @rematch/core --save
Socialโ
Feel free to official Twitter to get live updates of Rematch new releases or any news related to Rematch.
Also, you can join our Discord community to live-guidance or assistance with your Rematch projects.