Skip to content

Commit

Permalink
Add more comment and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunduin committed May 6, 2021
1 parent 516d49e commit 3667790
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 904 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
"pre-commit": "npm run lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"name": "dva-toolkit",
"author": "Bay",
"module": "dist/dva-toolkit.esm.js",
Expand Down
19 changes: 17 additions & 2 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ActionCreatorDvaCaseReducer<R> =
: ActionCreatorWithoutPayload

/**
* dva action need
* dva reducer actions creator
*
* @public
*/
Expand All @@ -25,7 +25,7 @@ export type ActionCreatorDvaReducers<Reducers extends DvaReducers> = {
}

/**
* dva
* dva reducer actions
*
* @public
*/
Expand All @@ -35,13 +35,23 @@ export type DvaReducersAction<
? ActionCreatorDvaReducers<Reducers>
: never

/**
* dva effects actions creator
*
* @public
*/
export type ActionCreatorDvaEffect<E> =
E extends (action: infer Action, effects: any) => any
? Action extends { payload: infer P }
? ActionCreatorWithPayload<P>
: ActionCreatorWithoutPayload
: ActionCreatorWithoutPayload

/**
* dva effects actions
*
* @public
*/
export type DvaEffectsAction<
CE extends DvaSliceCaseEffects
> = {
Expand All @@ -50,6 +60,11 @@ export type DvaEffectsAction<
: ActionCreatorDvaEffect<CE[Type]>
}

/**
* dva actions
*
* @public
*/
export type DvaCaseAction<
CR extends DvaSliceCaseReducers<any>,
CE extends DvaSliceCaseEffects
Expand Down
13 changes: 9 additions & 4 deletions src/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { call, put, take, select, cancel } from 'redux-saga/effects'
import type { PayloadAction } from '@reduxjs/toolkit'

/**
* dva 支持的 saga command 列表
* saga effects supported by dva
*
* @public
*/
Expand All @@ -17,25 +17,30 @@ export type SagaEffectsCommandMap = {
}

/**
* effect 方法
* pure effect method
*
* @public
*/
export type DvaCaseEffects =
(action: PayloadAction<any>, effects: SagaEffectsCommandMap) => Generator

/**
* effect 类型的 effect 方法
* effect with saga config
*
* @public
*/
export type DvaCaseEffectWithType =
[DvaCaseEffects, {type: EffectType}]

/**
* all effect case
*
* @public
*/
export type DvaCaseEffectValue = DvaCaseEffects | DvaCaseEffectWithType

/**
* dva 配置中 effects 列表的类型
* effects in dva config
*
* @public
*/
Expand Down
2 changes: 1 addition & 1 deletion src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type DvaSliceCaseReducers<
> = DvaReducersWithEnhancer<S, Reducers> | Reducers

/**
* 没看懂,但加上去就对了
* valid dva reducers case
*
* TODO: try to understand this func
*/
Expand Down
5 changes: 5 additions & 0 deletions src/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export type CreateDvaSliceOption<
subscriptions?: SubscriptionsMapObject,
}

/**
* dva slice result, `model` is dva model, `action` is typed action generator
*
* @public
*/
export type DvaSlice<
State = any,
CR extends DvaSliceCaseReducers<State> = DvaSliceCaseReducers<State>,
Expand Down
Loading

0 comments on commit 3667790

Please sign in to comment.