-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
131 lines (106 loc) · 3.04 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var { getComputed, appendState, setState, getState } = require('concent');
var pluginName = 'cuStatus';
var module_batchCount_ = {};
function makeCuState(done, retKey, err) {
var toReturn = { done: true, err: null, retKey: '' };
if (done !== undefined) toReturn.done = done;
if (err !== undefined) toReturn.err = err;
if (retKey !== undefined) toReturn.retKey = retKey;
return toReturn;
}
function makeCuStateKey(module, retKey) {
return module + '/' + retKey;
}
function incBatchCount(module) {
try {
module_batchCount_[module]++;
} catch (err) {
module_batchCount_[module] = 1;
}
}
function decBatchCount(module) {
try {
module_batchCount_[module]--;
} catch (err) {
module_batchCount_[module] = 0;
}
}
function changeDone(data, done) {
var payload = data.payload;
var retKey = payload.retKey;
var module = payload.module;
var err = payload.err;
var stateKey = makeCuStateKey(module, retKey);
const cuStatus = getState(pluginName);
if (cuStatus[module].done !== done) {
var toSet = {};
toSet[stateKey] = makeCuState(done, retKey, err);
setState(pluginName, toSet);
}
}
exports.getPluginName = function () {
return pluginName;
}
exports.setPluginName = function (_pluginName) {
pluginName = _pluginName;
}
exports.makeComputedStatusState = function (module) {
var targetComputed = {};
if (module) {
targetComputed[module] = getComputed(module);
} else {
targetComputed = getComputed();;
}
var state = {};
Object.keys(targetComputed).forEach(function (module) {
state[module] = makeCuState();
module_batchCount_[module] = 0;
const subComputed = targetComputed[module];
Object.getOwnPropertyNames(subComputed).forEach(function (retKey) {
state[makeCuStateKey(module, retKey)] = makeCuState(true, retKey);
});
});
return state;
}
/**
* 通过configure接口配置了新模块时,触发此函数
*/
exports.onModuleConfigured = function (data) {
var newModule = data.payload;
var toAppend = makeComputedStatusState(newModule);
appendState(getPluginName(), toAppend);
}
exports.onCuBatchStart = function (data) {
var module = data.payload.module;
incBatchCount(module);
const cuStatus = getState(pluginName);
if (cuStatus[module].done === true) {
var toSet = {};
toSet[module] = makeCuState(false);
setState(pluginName, toSet);
}
}
exports.onCuBatchEnd = function (data) {
var payload = data.payload;
var module = payload.module;
var retKey = payload.retKey || '';
var err = payload.err || null;
decBatchCount(module);
const cuStatus = getState(pluginName);
const modCuStatus = cuStatus[module];
const done = module_batchCount_[module] === 0;
if (modCuStatus.done !== done || modCuStatus.err !== err) {
var toSet = {};
toSet[module] = makeCuState(done, retKey, err);
setState(pluginName, toSet);
}
}
exports.onCuFnStart = function (data) {
changeDone(data, false);
}
exports.onCuFnEnd = function (data) {
changeDone(data, true);
}
exports.onCuFnError = function (data) {
changeDone(data, true);
}