easy-soft-dva 3.6.3 → 3.6.5
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/es/dva-core/index.js +2048 -1
- package/es/dva-loading/index.js +159 -1
- package/es/index.js +178 -1
- package/es/regeneratorRuntime.js +368 -3
- package/es/utils/dvaAssist.d.ts +13 -11
- package/package.json +3 -3
package/es/dva-loading/index.js
CHANGED
|
@@ -1 +1,159 @@
|
|
|
1
|
-
import{d as
|
|
1
|
+
import { d as _defineProperty, _ as _objectSpread2, b as _regeneratorRuntime } from '../regeneratorRuntime.js';
|
|
2
|
+
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
4
|
+
try {
|
|
5
|
+
var info = gen[key](arg);
|
|
6
|
+
var value = info.value;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
reject(error);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (info.done) {
|
|
12
|
+
resolve(value);
|
|
13
|
+
} else {
|
|
14
|
+
Promise.resolve(value).then(_next, _throw);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _asyncToGenerator(fn) {
|
|
18
|
+
return function () {
|
|
19
|
+
var self = this,
|
|
20
|
+
args = arguments;
|
|
21
|
+
return new Promise(function (resolve, reject) {
|
|
22
|
+
var gen = fn.apply(self, args);
|
|
23
|
+
function _next(value) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
25
|
+
}
|
|
26
|
+
function _throw(err) {
|
|
27
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
28
|
+
}
|
|
29
|
+
_next(undefined);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var SHOW = '@@DVA_LOADING/SHOW';
|
|
35
|
+
var HIDE = '@@DVA_LOADING/HIDE';
|
|
36
|
+
var NAMESPACE = 'loading';
|
|
37
|
+
function createLoading() {
|
|
38
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
39
|
+
var namespace = opts.namespace || NAMESPACE;
|
|
40
|
+
var _opts$only = opts.only,
|
|
41
|
+
only = _opts$only === void 0 ? [] : _opts$only,
|
|
42
|
+
_opts$except = opts.except,
|
|
43
|
+
except = _opts$except === void 0 ? [] : _opts$except;
|
|
44
|
+
if (only.length > 0 && except.length > 0) {
|
|
45
|
+
throw Error('It is ambiguous to configurate `only` and `except` items at the same time.');
|
|
46
|
+
}
|
|
47
|
+
var initialState = {
|
|
48
|
+
global: false,
|
|
49
|
+
models: {},
|
|
50
|
+
effects: {}
|
|
51
|
+
};
|
|
52
|
+
var extraReducers = _defineProperty({}, namespace, function () {
|
|
53
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
|
54
|
+
var _ref = arguments.length > 1 ? arguments[1] : undefined,
|
|
55
|
+
type = _ref.type,
|
|
56
|
+
payload = _ref.payload;
|
|
57
|
+
var _ref2 = payload || {},
|
|
58
|
+
ns = _ref2.namespace,
|
|
59
|
+
actionType = _ref2.actionType;
|
|
60
|
+
var ret;
|
|
61
|
+
switch (type) {
|
|
62
|
+
case SHOW:
|
|
63
|
+
ret = _objectSpread2(_objectSpread2({}, state), {}, {
|
|
64
|
+
global: true,
|
|
65
|
+
models: _objectSpread2(_objectSpread2({}, state.models), {}, _defineProperty({}, ns, true)),
|
|
66
|
+
effects: _objectSpread2(_objectSpread2({}, state.effects), {}, _defineProperty({}, actionType, true))
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
case HIDE:
|
|
70
|
+
{
|
|
71
|
+
var effects = _objectSpread2(_objectSpread2({}, state.effects), {}, _defineProperty({}, actionType, false));
|
|
72
|
+
var models = _objectSpread2(_objectSpread2({}, state.models), {}, _defineProperty({}, ns, Object.keys(effects).some(function (at) {
|
|
73
|
+
var _namespace = at.split('/')[0];
|
|
74
|
+
if (_namespace !== ns) return false;
|
|
75
|
+
return effects[at];
|
|
76
|
+
})));
|
|
77
|
+
var global = Object.keys(models).some(function (n) {
|
|
78
|
+
return models[n];
|
|
79
|
+
});
|
|
80
|
+
ret = _objectSpread2(_objectSpread2({}, state), {}, {
|
|
81
|
+
global: global,
|
|
82
|
+
models: models,
|
|
83
|
+
effects: effects
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
ret = state;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return ret;
|
|
92
|
+
});
|
|
93
|
+
function onEffect(effect, _ref3, model, actionType) {
|
|
94
|
+
var put = _ref3.put;
|
|
95
|
+
var ns = model.namespace;
|
|
96
|
+
if (only.length === 0 && except.length === 0 || only.length > 0 && only.indexOf(actionType) !== -1 || except.length > 0 && except.indexOf(actionType) === -1) {
|
|
97
|
+
return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
98
|
+
var _args = arguments;
|
|
99
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
100
|
+
while (1) switch (_context.prev = _context.next) {
|
|
101
|
+
case 0:
|
|
102
|
+
_context.next = 2;
|
|
103
|
+
return put({
|
|
104
|
+
type: SHOW,
|
|
105
|
+
payload: {
|
|
106
|
+
namespace: ns,
|
|
107
|
+
actionType: actionType
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
case 2:
|
|
111
|
+
_context.next = 4;
|
|
112
|
+
return effect.apply(void 0, _args);
|
|
113
|
+
case 4:
|
|
114
|
+
_context.next = 6;
|
|
115
|
+
return put({
|
|
116
|
+
type: HIDE,
|
|
117
|
+
payload: {
|
|
118
|
+
namespace: ns,
|
|
119
|
+
actionType: actionType
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
case 6:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context.stop();
|
|
125
|
+
}
|
|
126
|
+
}, _callee);
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
return effect;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
extraReducers: extraReducers,
|
|
134
|
+
onEffect: onEffect
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* placeholder function
|
|
140
|
+
*/
|
|
141
|
+
function empty() {
|
|
142
|
+
return _empty.apply(this, arguments);
|
|
143
|
+
}
|
|
144
|
+
function _empty() {
|
|
145
|
+
_empty = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
146
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
147
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
148
|
+
case 0:
|
|
149
|
+
return _context2.abrupt("return", {});
|
|
150
|
+
case 1:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context2.stop();
|
|
153
|
+
}
|
|
154
|
+
}, _callee2);
|
|
155
|
+
}));
|
|
156
|
+
return _empty.apply(this, arguments);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { createLoading, empty };
|
package/es/index.js
CHANGED
|
@@ -1 +1,178 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { _ as _objectSpread2 } from './regeneratorRuntime.js';
|
|
2
|
+
import { displayTextMessage, isNumber, logWarn, toNumber, logError, isUndefined, isString, setCache, logDebug } from 'easy-soft-utility';
|
|
3
|
+
import { create } from './dva-core/index.js';
|
|
4
|
+
export { Provider, connect } from './dva-core/index.js';
|
|
5
|
+
import { createLoading } from './dva-loading/index.js';
|
|
6
|
+
import 'invariant';
|
|
7
|
+
import 'react-redux';
|
|
8
|
+
import 'redux';
|
|
9
|
+
import 'redux-saga';
|
|
10
|
+
import 'is-plain-object';
|
|
11
|
+
import 'flatten';
|
|
12
|
+
import '@reduxjs/toolkit';
|
|
13
|
+
import 'warning';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Module Package Name
|
|
17
|
+
*/
|
|
18
|
+
var modulePackageName = 'easy-soft-dva';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build prompt module info
|
|
22
|
+
*/
|
|
23
|
+
function buildPromptModuleInfo(moduleName) {
|
|
24
|
+
return "".concat(modulePackageName, "::").concat(moduleName, "::");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Module Name.
|
|
29
|
+
*/
|
|
30
|
+
var moduleName = 'stateAssist';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get default code
|
|
34
|
+
*/
|
|
35
|
+
function getDefaultCode() {
|
|
36
|
+
if (!stateConfigure.defaultCodeSetComplete) {
|
|
37
|
+
if (!stateConfigure.defaultCodePromptSetInformationComplete) {
|
|
38
|
+
var text = "".concat(buildPromptModuleInfo(moduleName), "logData -> logger display switch default is false, if want to display log, please set it before first log, use setLoggerDisplaySwitch to set it, this message only show once.");
|
|
39
|
+
displayTextMessage({
|
|
40
|
+
text: text,
|
|
41
|
+
color: '#08BBEE',
|
|
42
|
+
dataDescription: 'hint',
|
|
43
|
+
ancillaryInformation: ''
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
throw new Error('please set use setStateDefaultCode');
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
stateConfigure.defaultCodePromptSetInformationComplete = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return stateConfigure.defaultCode;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* state configure
|
|
58
|
+
*/
|
|
59
|
+
var stateConfigure = {
|
|
60
|
+
defaultCodePromptSetInformationComplete: false,
|
|
61
|
+
defaultCodeSetComplete: false,
|
|
62
|
+
defaultCode: 200
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Set state default code
|
|
67
|
+
* @param {Number} code state default code
|
|
68
|
+
*/
|
|
69
|
+
function setStateDefaultCode(code) {
|
|
70
|
+
if (!isNumber(code)) {
|
|
71
|
+
logWarn("".concat(buildPromptModuleInfo(moduleName), "setStateDefaultCode -> code must be number"));
|
|
72
|
+
}
|
|
73
|
+
stateConfigure.defaultCode = toNumber(code);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var app;
|
|
77
|
+
var store;
|
|
78
|
+
var dispatch;
|
|
79
|
+
var registered;
|
|
80
|
+
function createApp(opt) {
|
|
81
|
+
app = create(opt);
|
|
82
|
+
app.use(createLoading({}));
|
|
83
|
+
if (!registered) {
|
|
84
|
+
opt.models.forEach(function (model) {
|
|
85
|
+
return app.model(model);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
registered = true;
|
|
89
|
+
app.start();
|
|
90
|
+
store = app._store;
|
|
91
|
+
app.getStore = function () {
|
|
92
|
+
return store;
|
|
93
|
+
};
|
|
94
|
+
app.use({
|
|
95
|
+
onError: function onError(err) {
|
|
96
|
+
logError(err);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
dispatch = store.dispatch;
|
|
100
|
+
app.dispatch = dispatch;
|
|
101
|
+
return app;
|
|
102
|
+
}
|
|
103
|
+
var reducerNameCollection = {
|
|
104
|
+
reducerData: 'reducerData'
|
|
105
|
+
};
|
|
106
|
+
function reducerDataAssist(state, action, namespace) {
|
|
107
|
+
var _callback$pretreatmen = _objectSpread2(_objectSpread2({}, {
|
|
108
|
+
callback: null,
|
|
109
|
+
pretreatment: null,
|
|
110
|
+
alias: null,
|
|
111
|
+
cacheData: false
|
|
112
|
+
}), action),
|
|
113
|
+
v = _callback$pretreatmen.payload,
|
|
114
|
+
alias = _callback$pretreatmen.alias,
|
|
115
|
+
cacheData = _callback$pretreatmen.cacheData;
|
|
116
|
+
var result = null;
|
|
117
|
+
if (isUndefined(alias) || !isString(alias)) {
|
|
118
|
+
result = _objectSpread2(_objectSpread2({}, state), {}, {
|
|
119
|
+
data: v,
|
|
120
|
+
fromRemote: true
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
result = _objectSpread2(_objectSpread2({}, state), {}, {
|
|
124
|
+
fromRemote: true
|
|
125
|
+
});
|
|
126
|
+
result[alias] = v;
|
|
127
|
+
}
|
|
128
|
+
if (cacheData) {
|
|
129
|
+
var key = "".concat(namespace, "_").concat(alias || 'data');
|
|
130
|
+
var cacheResult = setCache({
|
|
131
|
+
key: key,
|
|
132
|
+
value: v
|
|
133
|
+
});
|
|
134
|
+
logDebug("modal ".concat(namespace, " cache data, key is ").concat(namespace, "_").concat(alias || 'data', ", ").concat(cacheResult ? 'cache success' : 'cache fail', "."));
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
var reducerCollection = {
|
|
139
|
+
reducerData: function reducerData(state, action, namespace) {
|
|
140
|
+
return reducerDataAssist(state, action, namespace);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
function getStore(models) {
|
|
144
|
+
var dvaApp = createApp({
|
|
145
|
+
initialState: {},
|
|
146
|
+
models: models
|
|
147
|
+
});
|
|
148
|
+
var result = dvaApp.getStore();
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* get tacitly state, it is for state initialization.
|
|
154
|
+
*/
|
|
155
|
+
function getTacitlyState() {
|
|
156
|
+
return {
|
|
157
|
+
data: {
|
|
158
|
+
code: getDefaultCode(),
|
|
159
|
+
message: 'success',
|
|
160
|
+
dataSuccess: true,
|
|
161
|
+
data: {},
|
|
162
|
+
list: [],
|
|
163
|
+
extra: {}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
var reducerDefaultParams = {
|
|
168
|
+
cacheData: false
|
|
169
|
+
};
|
|
170
|
+
var handleDefaultParams = {
|
|
171
|
+
callback: null,
|
|
172
|
+
pretreatment: null
|
|
173
|
+
};
|
|
174
|
+
function getDispatchWrapper() {
|
|
175
|
+
return app.dispatch;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { createApp, getDefaultCode, getDispatchWrapper, getStore, getTacitlyState, handleDefaultParams, reducerCollection, reducerDataAssist, reducerDefaultParams, reducerNameCollection, setStateDefaultCode, stateConfigure };
|