phecda-web 2.0.8 → 3.0.0

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/dist/index.js CHANGED
@@ -54,8 +54,8 @@ var import_mitt = __toESM(require("mitt"));
54
54
  var emitter = (0, import_mitt.default)();
55
55
  function defaultWebInject() {
56
56
  if (!(0, import_phecda_core.getInject)("watcher")) {
57
- (0, import_phecda_core.setInject)("watcher", ({ eventName, instance, key, options }) => {
58
- const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
57
+ (0, import_phecda_core.setInject)("watcher", ({ eventName, instance, property, options }) => {
58
+ const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
59
59
  if (options?.once) {
60
60
  const handler = /* @__PURE__ */ __name(() => {
61
61
  fn();
@@ -69,22 +69,22 @@ function defaultWebInject() {
69
69
  });
70
70
  }
71
71
  if (!(0, import_phecda_core.getInject)("storage")) {
72
- (0, import_phecda_core.setInject)("storage", ({ tag, key, instance, toJSON, toString }) => {
73
- tag = `phecda:${key ? `${tag}-${key}` : tag}`;
72
+ (0, import_phecda_core.setInject)("storage", ({ tag, property, instance, toJSON, toString }) => {
73
+ tag = `phecda:${property ? `${tag}-${property}` : tag}`;
74
74
  const initstr = localStorage.getItem(tag);
75
75
  if (initstr) {
76
76
  const data = toJSON(initstr);
77
- if (key) {
78
- instance[key] = data;
77
+ if (property) {
78
+ instance[property] = data;
79
79
  } else {
80
80
  for (const i in data) {
81
81
  if (i) instance[i] = data[i];
82
82
  }
83
83
  }
84
84
  }
85
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
85
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
86
86
  globalThis.addEventListener("beforeunload", () => {
87
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
87
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
88
88
  });
89
89
  });
90
90
  }
@@ -212,7 +212,7 @@ var WebPhecda = class {
212
212
  this.emit("Initialize", {
213
213
  tag
214
214
  });
215
- (0, import_phecda_core2.invokeHandler)("init", instance2);
215
+ (0, import_phecda_core2.invokeInit)(instance2);
216
216
  }
217
217
  return instance2;
218
218
  }, "initModel");
@@ -284,7 +284,7 @@ var WebPhecda = class {
284
284
  tag
285
285
  });
286
286
  const { state } = this;
287
- await (0, import_phecda_core2.invokeHandler)("unmount", this.get(tag));
287
+ await (0, import_phecda_core2.invokeUnmount)(this.get(tag));
288
288
  delete state[tag];
289
289
  }
290
290
  async unmountAll() {
package/dist/index.mjs CHANGED
@@ -10,8 +10,8 @@ import mitt from "mitt";
10
10
  var emitter = mitt();
11
11
  function defaultWebInject() {
12
12
  if (!getInject("watcher")) {
13
- setInject("watcher", ({ eventName, instance, key, options }) => {
14
- const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
13
+ setInject("watcher", ({ eventName, instance, property, options }) => {
14
+ const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
15
15
  if (options?.once) {
16
16
  const handler = /* @__PURE__ */ __name(() => {
17
17
  fn();
@@ -25,22 +25,22 @@ function defaultWebInject() {
25
25
  });
26
26
  }
27
27
  if (!getInject("storage")) {
28
- setInject("storage", ({ tag, key, instance, toJSON, toString }) => {
29
- tag = `phecda:${key ? `${tag}-${key}` : tag}`;
28
+ setInject("storage", ({ tag, property, instance, toJSON, toString }) => {
29
+ tag = `phecda:${property ? `${tag}-${property}` : tag}`;
30
30
  const initstr = localStorage.getItem(tag);
31
31
  if (initstr) {
32
32
  const data = toJSON(initstr);
33
- if (key) {
34
- instance[key] = data;
33
+ if (property) {
34
+ instance[property] = data;
35
35
  } else {
36
36
  for (const i in data) {
37
37
  if (i) instance[i] = data[i];
38
38
  }
39
39
  }
40
40
  }
41
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
41
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
42
42
  globalThis.addEventListener("beforeunload", () => {
43
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
43
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
44
44
  });
45
45
  });
46
46
  }
@@ -48,7 +48,7 @@ function defaultWebInject() {
48
48
  __name(defaultWebInject, "defaultWebInject");
49
49
 
50
50
  // src/core.ts
51
- import { get, getTag, invokeHandler } from "phecda-core";
51
+ import { get, getTag, invokeInit, invokeUnmount } from "phecda-core";
52
52
  import "reflect-metadata";
53
53
  import mitt2 from "mitt";
54
54
 
@@ -168,7 +168,7 @@ var WebPhecda = class {
168
168
  this.emit("Initialize", {
169
169
  tag
170
170
  });
171
- invokeHandler("init", instance2);
171
+ invokeInit(instance2);
172
172
  }
173
173
  return instance2;
174
174
  }, "initModel");
@@ -240,7 +240,7 @@ var WebPhecda = class {
240
240
  tag
241
241
  });
242
242
  const { state } = this;
243
- await invokeHandler("unmount", this.get(tag));
243
+ await invokeUnmount(this.get(tag));
244
244
  delete state[tag];
245
245
  }
246
246
  async unmountAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "2.0.8",
3
+ "version": "3.0.0",
4
4
  "description": "using proxy, provide phecda function to web app",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "mitt": "^3.0.0",
20
20
  "reflect-metadata": "^0.1.13",
21
21
  "ts-mixer": "^6.0.4",
22
- "phecda-core": "3.1.1"
22
+ "phecda-core": "4.0.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "tsup": "^8.1.0"