ez-saga 17.1.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ez-saga",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"description": "The ez-saga project is a project that imitates dva-js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"lint": "eslint --ext .js src"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@reduxjs/toolkit": "^1.
|
|
30
|
-
"redux": "^
|
|
29
|
+
"@reduxjs/toolkit": "^2.1.0",
|
|
30
|
+
"redux": "^5.0.1",
|
|
31
31
|
"redux-saga": "^1.3.0",
|
|
32
32
|
"global": "^4.4.0"
|
|
33
33
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch, Middleware, MiddlewareAPI, Action
|
|
1
|
+
import { Dispatch, Middleware, MiddlewareAPI, Action } from 'redux';
|
|
2
2
|
import { RegistedModel } from './typeDeclare';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -17,11 +17,8 @@ function createPromiseMiddleware<D extends Dispatch>(registedModel: RegistedMode
|
|
|
17
17
|
}
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
// function isReduxAction(action: unknown): action is Action {
|
|
21
|
-
// return (action as Action)?.type !== undefined;
|
|
22
|
-
// }
|
|
23
20
|
|
|
24
|
-
return (api: MiddlewareAPI<D, any>) => (next: (action:
|
|
21
|
+
return (api: MiddlewareAPI<D, any>) => (next: (action: unknown) => any) => (action: unknown) => {
|
|
25
22
|
let exeEffect = false;
|
|
26
23
|
if ((action as Action)?.type !== undefined) {
|
|
27
24
|
const { type } = action as Action;
|
package/src/redux/createApp.ts
CHANGED
|
@@ -3,23 +3,11 @@ import { createSlice, combineReducers } from '@reduxjs/toolkit';
|
|
|
3
3
|
import createSagaMiddleware, { SagaMiddleware } from 'redux-saga';
|
|
4
4
|
import { call, put, select, takeEvery, putResolve } from 'redux-saga/effects';
|
|
5
5
|
import win from 'global/window';
|
|
6
|
-
import { Reducer,
|
|
7
|
-
import { ReduxModel, ReduxApp, RegistedModel, ReduxSagaModel, PayloadAction } from './typeDeclare';
|
|
8
|
-
|
|
6
|
+
import { Reducer, Action } from 'redux';
|
|
7
|
+
import { ReduxModel, ReduxApp, RegistedModel, ReduxSagaModel, EffectTool, PayloadAction } from './typeDeclare';
|
|
8
|
+
import saveState from './defaultReducer';
|
|
9
9
|
import createPromiseMiddleware from './PromiseMiddleware';
|
|
10
10
|
|
|
11
|
-
const saveState: Reducer<any, PayloadAction> = (state: any, action: PayloadAction) => {
|
|
12
|
-
debugger;
|
|
13
|
-
if (!action.payload) {
|
|
14
|
-
return state;
|
|
15
|
-
}
|
|
16
|
-
let newStat = {
|
|
17
|
-
...state,
|
|
18
|
-
...action.payload
|
|
19
|
-
};
|
|
20
|
-
return newStat;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
11
|
/**
|
|
24
12
|
* 获取注册model函数
|
|
25
13
|
* @param store redux store
|
|
@@ -29,7 +17,7 @@ const saveState: Reducer<any, PayloadAction> = (state: any, action: PayloadActio
|
|
|
29
17
|
* @returns 返回function regist(model)
|
|
30
18
|
*/
|
|
31
19
|
function getRegistModelFunc(store: Store<any, ReduxAction>, registedModel: RegistedModel,
|
|
32
|
-
allReducers: { [x: string]: Reducer<any,
|
|
20
|
+
allReducers: { [x: string]: Reducer<any, Action>; },
|
|
33
21
|
sagaMiddleware: SagaMiddleware<object>): (model: ReduxModel) => void {
|
|
34
22
|
/** model函数注册函数
|
|
35
23
|
* @param model 模块, 其格式为
|
|
@@ -72,7 +60,7 @@ function getRegistModelFunc(store: Store<any, ReduxAction>, registedModel: Regis
|
|
|
72
60
|
for (let effect in model.effects) {
|
|
73
61
|
let type: string = `${model.name}/${effect}`;
|
|
74
62
|
let execFun = model.effects[effect];
|
|
75
|
-
function* loading(opFun:
|
|
63
|
+
function* loading(opFun: EffectTool, action: PayloadAction) {
|
|
76
64
|
// 开始异步任务设置loading状态
|
|
77
65
|
yield putResolve({ type: `${model.name}/saveState`, payload: { loading: true } });
|
|
78
66
|
let ret = yield call(execFun, action, opFun);
|
package/src/redux/typeDeclare.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/** 类型申明 */
|
|
2
2
|
import {
|
|
3
|
-
Action as ReduxAction, Store, Reducer,
|
|
3
|
+
Action as ReduxAction, Store, Reducer, UnknownAction
|
|
4
4
|
} from 'redux';
|
|
5
5
|
import { Action, SagaMiddleware } from 'redux-saga';
|
|
6
6
|
import { PutEffect, SelectEffect } from 'redux-saga/effects';
|
|
7
7
|
|
|
8
8
|
/** payload action类型 */
|
|
9
|
-
export interface PayloadAction extends
|
|
9
|
+
export interface PayloadAction extends UnknownAction, ReduxAction<string> {
|
|
10
10
|
/** 类型 */
|
|
11
11
|
type: string,
|
|
12
12
|
/** 载体 */
|
|
13
|
-
payload?: any
|
|
13
|
+
payload?: any,
|
|
14
|
+
[extraProps: string]: any;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/** 工具 */
|