@vnejs/plugins.vars.counters 0.1.4 → 0.1.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/modules/counters.js +7 -3
- package/package.json +1 -1
package/modules/counters.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Module } from "@vnejs/module";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
2
3
|
|
|
3
4
|
export class Counters extends Module {
|
|
4
5
|
name = "vars.counters";
|
|
@@ -28,14 +29,17 @@ export class Counters extends Module {
|
|
|
28
29
|
this.on(this.EVENTS.VARS_COUNTERS.EXEC_CHECK, this.onCounterExecCheck);
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
|
|
33
|
+
|
|
31
34
|
onCounterSet = ({ name, isGlobal = false, value = 0 }) => this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_COUNTERS.TYPE, value, isGlobal });
|
|
32
|
-
onCounterGet = ({ name = "", isGlobal = false } = {}) =>
|
|
35
|
+
onCounterGet = ({ name = "", isGlobal = false } = {}) =>
|
|
36
|
+
this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, defaultValue: 0 });
|
|
33
37
|
onCounterChange = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsChangeHandlers[action](value, execValue);
|
|
34
38
|
onCounterCompare = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsCompareHandlers[action](value, execValue);
|
|
35
39
|
onCounterExecInfo = async ({ line = "", keywords = [], withValue = true } = {}) => {
|
|
36
|
-
const [name = "", action = "", execValue =
|
|
40
|
+
const [name = "", action = "", execValue = 0] = tokenizeExecLine(line);
|
|
37
41
|
const isGlobal = keywords.includes("global");
|
|
38
|
-
const result = { name, action, isGlobal, execValue
|
|
42
|
+
const result = { name, action, isGlobal, execValue };
|
|
39
43
|
|
|
40
44
|
return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal }) } : result;
|
|
41
45
|
};
|