Skip to content

Commit

Permalink
fix(types): improve the accuracy of dispatcher inference (#937)
Browse files Browse the repository at this point in the history
* fix(types): correct dispatcher argument inference when payload defined as any type

* fix(types): improve the inference accuracy of dispatcher

* refactor: use `RematchDispatcher` for both reducer and effect

* fix(types): remove the default effects/reducers/basereducer type if they are undefined

* test(dispatcher-typings): add more tests

* fix: use correct overload to match rematch core

* fix(): Tsdx is abandoned and we moved to a forked TSDX updated (#939)

Co-authored-by: tianzhich <zhi.tian@yahoo.com>

* docs(core): format, add new documents and revise the olds

Co-authored-by: Sergio Moreno <sergiomorenoalbert@gmail.com>
  • Loading branch information
tianzhich and semoal committed Oct 11, 2021
1 parent b90027c commit 4bca82d
Show file tree
Hide file tree
Showing 15 changed files with 3,249 additions and 3,443 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@
"prettier": "2.3.2",
"rimraf": "^3.0.2",
"size-limit": "^5.0.3",
"tsdx": "^0.14.1",
"dts-cli": "^0.19.2",
"tslib": "^2.3.1",
"typescript": "^4.4.2"
},
"resolutions": {
"terser" : "4.8.0"
},
"lint-staged": {
"packages/**/*.{ts,tsx,jsx,js,json,md,mdx}": [
Expand Down Expand Up @@ -141,4 +138,4 @@
"limit": "300 B"
}
]
}
}
11 changes: 6 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
"access": "public"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build --format cjs,esm,umd --tsconfig ./tsconfig.build.json",
"test": "tsdx test",
"lint": "tsdx lint",
"start": "dts watch",
"build": "dts build --format cjs,esm,umd --tsconfig ./tsconfig.build.json",
"test": "dts test",
"lint": "dts lint",
"clean": "rimraf dist"
},
"files": [
"dist",
"src"
"src",
"README.md"
],
"engines": {
"node": ">=10"
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
NamedModel,
RematchBag,
RematchDispatcher,
EffectRematchDispatcher,
RematchStore,
} from './types'
import { validateModelEffect, validateModelReducer } from './validate'
Expand All @@ -25,7 +24,7 @@ const createActionDispatcher = <
modelName: string,
actionName: string,
isEffect: boolean
): RematchDispatcher | EffectRematchDispatcher => {
): RematchDispatcher<boolean> => {
return Object.assign(
(payload?: any, meta?: any): Action => {
const action: Action = { type: `${modelName}/${actionName}` }
Expand Down
12 changes: 1 addition & 11 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ export const init = <
return createRematchStore(config)
}

export const createModel: ModelCreator =
() =>
(mo): any => {
const { reducers = {}, effects = {} } = mo

return {
...mo,
reducers,
effects,
}
}
export const createModel: ModelCreator = () => (mo) => mo as any

export default {
init,
Expand Down

0 comments on commit 4bca82d

Please sign in to comment.