@vnejs/plugins.vars 0.1.2 → 0.1.4

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/vars.js +11 -8
  2. package/package.json +1 -1
package/modules/vars.js CHANGED
@@ -7,24 +7,27 @@ export class Vars extends Module {
7
7
  this.on(this.EVENTS.VARS.SET, this.onVarSet);
8
8
  this.on(this.EVENTS.VARS.INJECT, this.onVarInject);
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
14
  init = async () => {
15
- const vars = await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { prefix: this.name });
16
-
17
- this.shared.vars = vars || {};
15
+ this.shared.vars = await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name });
18
16
  };
19
17
 
20
18
  onVarSet = async ({ name, type, value, isGlobal = false }) => {
21
19
  const varName = `${type}:${name}`;
22
20
 
23
- (isGlobal ? this.shared.vars : this.state)[varName] = value;
24
- isGlobal && this.emit(this.EVENTS.STORAGE.SET, { prefix: this.name, key: varName, value });
21
+ if (isGlobal) {
22
+ this.shared.vars[varName] = value;
23
+
24
+ return this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: varName, value });
25
+ }
26
+
27
+ this.state[varName] = value;
25
28
  };
26
29
 
27
- onVarInject = async ({ text = "" }) => this.injectsVars(this.injectsVars(text.slice(), this.shared.vars, "%%"), this.state, "%");
30
+ onVarInject = async ({ text = "" } = {}) => this.injectsVars(this.injectsVars(text.slice(), this.shared.vars, "%%"), this.state, "%");
28
31
 
29
32
  injectsVars = (text, vars, symbol) => {
30
33
  let newText = text.slice();
@@ -36,5 +39,5 @@ export class Vars extends Module {
36
39
  return newText;
37
40
  };
38
41
 
39
- getDefaultState = () => ({});
42
+ onStateSet = async ({ [this.name]: state } = {}) => this.setState(await this.emitOne(this.EVENTS.VENDORS.CLONE, state));
40
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",