@vnejs/plugins.vars.counters 0.1.4 → 0.1.6

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/const/events.js CHANGED
@@ -5,4 +5,5 @@ export const SUBSCRIBE_EVENTS = {
5
5
  COMPARE: "vne:vars_counter:compare",
6
6
  EXEC_INFO: "vne:vars_counter:exec_info",
7
7
  EXEC_CHECK: "vne:vars_counter:exec_check",
8
+ EXEC_GET: "vne:vars_counter:exec_get",
8
9
  };
@@ -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";
@@ -26,22 +27,31 @@ export class Counters extends Module {
26
27
  this.on(this.EVENTS.VARS_COUNTERS.COMPARE, this.onCounterCompare);
27
28
  this.on(this.EVENTS.VARS_COUNTERS.EXEC_INFO, this.onCounterExecInfo);
28
29
  this.on(this.EVENTS.VARS_COUNTERS.EXEC_CHECK, this.onCounterExecCheck);
30
+ this.on(this.EVENTS.VARS_COUNTERS.EXEC_GET, this.onCounterExecGet);
29
31
  };
30
32
 
33
+ init = () => this.emit(this.EVENTS.VARS.DEFAULT_REG, { type: this.CONST.VARS_COUNTERS.TYPE, value: 0 });
34
+
31
35
  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 } = {}) => this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal });
36
+ onCounterGet = ({ name = "", isGlobal = false, state = null } = {}) =>
37
+ this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_COUNTERS.TYPE, isGlobal, state });
33
38
  onCounterChange = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsChangeHandlers[action](value, execValue);
34
39
  onCounterCompare = ({ value = 0, execValue = 0, action = "" } = {}) => this.varsCompareHandlers[action](value, execValue);
35
- onCounterExecInfo = async ({ line = "", keywords = [], withValue = true } = {}) => {
36
- const [name = "", action = "", execValue = "0"] = line.split(" ");
40
+ onCounterExecInfo = async ({ line = "", keywords = [], state = null, withValue = true } = {}) => {
41
+ const [name = "", action = "", execValue = 0] = tokenizeExecLine(line);
37
42
  const isGlobal = keywords.includes("global");
38
- const result = { name, action, isGlobal, execValue: Number(execValue) };
43
+ const result = { name, action, isGlobal, execValue };
39
44
 
40
- return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal }) } : result;
45
+ return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_COUNTERS.GET, { name, isGlobal, state }) } : result;
41
46
  };
42
- onCounterExecCheck = async ({ line = "", keywords = [] } = {}) => {
43
- const { action = "", execValue = 0, value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords });
47
+ onCounterExecCheck = async ({ line = "", keywords = [], state = null } = {}) => {
48
+ const { action = "", execValue = 0, value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state });
44
49
 
45
50
  return this.emitOne(this.EVENTS.VARS_COUNTERS.COMPARE, { value, execValue, action });
46
51
  };
52
+ onCounterExecGet = async ({ line = "", keywords = [], state = null } = {}) => {
53
+ const { value = 0 } = await this.emitOne(this.EVENTS.VARS_COUNTERS.EXEC_INFO, { line, keywords, state });
54
+
55
+ return value;
56
+ };
47
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.counters",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",