@urso/core 0.2.2-dev → 0.2.3-dev
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
|
@@ -2,12 +2,16 @@ ComponentsBaseController = require('./../base/controller.js');
|
|
|
2
2
|
|
|
3
3
|
class ComponentsStateDrivenController extends ComponentsBaseController {
|
|
4
4
|
|
|
5
|
+
//config for the states guards
|
|
5
6
|
configStates = {
|
|
6
7
|
/*IDLE: {
|
|
7
8
|
guard: () => { log(123, 'IDLE guard'); return true; }
|
|
8
9
|
}*/
|
|
9
10
|
};
|
|
10
11
|
|
|
12
|
+
//config for the actions configs. Guard and terminate functions are optional. Run will called when action starts.
|
|
13
|
+
//call finish callback in the run handler to immidiately finish this action
|
|
14
|
+
//use callFinish(actionKey) when its need after run handler called to delayed finish this action
|
|
11
15
|
configActions = {
|
|
12
16
|
/*startSpin: {
|
|
13
17
|
guard: () => { log(123, 'guard'); return true; },
|
|
@@ -16,6 +20,24 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
|
|
|
16
20
|
}*/
|
|
17
21
|
};
|
|
18
22
|
|
|
23
|
+
//system callbacks storage
|
|
24
|
+
_finishCallbacks = {};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* caller for delayed finish callback
|
|
29
|
+
* @param {String} actionKey
|
|
30
|
+
*/
|
|
31
|
+
callFinish(actionKey) {
|
|
32
|
+
if (!this._finishCallbacks.actionKey) {
|
|
33
|
+
Urso.logger.error('ComponentsStateDrivenController: no finish for actionKey', actionKey, this);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this._finishCallbacks.actionKey();
|
|
38
|
+
delete this._finishCallbacks.actionKey;
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
_processStates() {
|
|
20
42
|
for (const stateKey in this.configStates) {
|
|
21
43
|
Urso.statesManager.setStateGuard(stateKey, this.configStates[stateKey].guard.bind(this));
|
|
@@ -29,7 +51,10 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
|
|
|
29
51
|
const actionCfg = this.configActions[actionKey];
|
|
30
52
|
|
|
31
53
|
if (actionCfg.run)
|
|
32
|
-
Urso.statesManager.addActionRun(actionKey,
|
|
54
|
+
Urso.statesManager.addActionRun(actionKey, (finish) => {
|
|
55
|
+
this._saveFinish(actionKey, finish);
|
|
56
|
+
actionCfg.run(() => this.callFinish(actionKey));
|
|
57
|
+
});
|
|
33
58
|
else {
|
|
34
59
|
Urso.logger.error('ComponentsStateDrivenController: no run function in config', actionKey, this);
|
|
35
60
|
continue;
|
|
@@ -43,6 +68,18 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
|
|
|
43
68
|
}
|
|
44
69
|
}
|
|
45
70
|
|
|
71
|
+
/**
|
|
72
|
+
* saver for delayed finish callback
|
|
73
|
+
* @param {String} actionKey
|
|
74
|
+
* @param {Function} finish
|
|
75
|
+
*/
|
|
76
|
+
_saveFinish(actionKey, finish) {
|
|
77
|
+
if (this._finishCallbacks.actionKey)
|
|
78
|
+
Urso.logger.error('ComponentsStateDrivenController: actionKey alredy exists', actionKey, finish, this);
|
|
79
|
+
|
|
80
|
+
this._finishCallbacks.actionKey = finish;
|
|
81
|
+
}
|
|
82
|
+
|
|
46
83
|
_subscribeOnce() {
|
|
47
84
|
//do not forget use super._subscribeOnce() , if you will use _subscribeOnce in the component
|
|
48
85
|
this._processStates();
|