@vnejs/plugins.feature.time 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/modules/time.js +12 -14
  2. package/package.json +1 -1
package/modules/time.js CHANGED
@@ -7,26 +7,18 @@ export class TimeModule extends Module {
7
7
  this.on(this.EVENTS.TIME.SET, this.onTimeSet);
8
8
  this.on(this.EVENTS.TIME.ADD, this.onTimeAdd);
9
9
 
10
- this.on(this.EVENTS.STATE.SET, this.setStateFromGlobalState);
10
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
11
11
  this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
12
12
  };
13
13
 
14
- init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.execHandler });
14
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
15
15
 
16
- execHandler = async (line) => {
16
+ onLineExec = async ({ line = "" } = {}) => {
17
17
  const [action, ...values] = line.split(" ");
18
18
 
19
- const hours = Number(values[0] || 0) || 0;
20
- const minutes = Number(values[1] || 0) || 0;
21
- const seconds = Number(values[2] || 0) || 0;
19
+ const [hours, minutes, seconds] = values.map((e) => Number(e || 0) || 0);
22
20
 
23
- switch (action) {
24
- case this.CONST.TIME.ACTIONS.ADD:
25
- await this.emit(this.EVENTS.TIME.ADD, { hours, minutes, seconds });
26
- break;
27
- case this.CONST.TIME.ACTIONS.SET:
28
- await this.emit(this.EVENTS.TIME.SET, { hours, minutes, seconds });
29
- }
21
+ await this.emitTimeEvent(action, { hours, minutes, seconds });
30
22
 
31
23
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
32
24
  };
@@ -36,7 +28,6 @@ export class TimeModule extends Module {
36
28
 
37
29
  this.emit(this.EVENTS.TIME.CHANGED);
38
30
  };
39
-
40
31
  onTimeAdd = ({ hours = 0, minutes = 0, seconds = 0 }) => {
41
32
  this.setState({
42
33
  hours: this.state.hours + hours,
@@ -64,5 +55,12 @@ export class TimeModule extends Module {
64
55
  this.emit(this.EVENTS.TIME.CHANGED);
65
56
  };
66
57
 
58
+ onStateSet = async ({ [this.name]: state } = {}) => this.setState(await this.emitOne(this.EVENTS.VENDORS.CLONE, state));
59
+
60
+ emitTimeEvent = (action, arg) => {
61
+ if (action === this.CONST.TIME.ACTIONS.ADD) return this.emit(this.EVENTS.TIME.ADD, arg);
62
+ if (action === this.CONST.TIME.ACTIONS.SET) return this.emit(this.EVENTS.TIME.SET, arg);
63
+ };
64
+
67
65
  getDefaultState = () => ({ hours: 0, minutes: 0, seconds: 0 });
68
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.feature.time",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",