phecda-web 2.0.7 → 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.d.mts CHANGED
@@ -2,6 +2,7 @@ import { Events, Construct, Base } from 'phecda-core';
2
2
  export * from 'phecda-core';
3
3
  import * as mitt from 'mitt';
4
4
  import { Handler, WildcardHandler } from 'mitt';
5
+ export { Mixin } from 'ts-mixer';
5
6
 
6
7
  interface PhecdaEmitter {
7
8
  on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
@@ -16,6 +17,7 @@ declare const emitter: PhecdaEmitter;
16
17
  declare function defaultWebInject(): void;
17
18
 
18
19
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
20
+ declare function getParamtypes(Model: Construct): any;
19
21
  declare const phecdaNamespace: Map<string, WebPhecda>;
20
22
  declare function setDefaultPhecda(namespace: string, phecda: WebPhecda): void;
21
23
  /**
@@ -87,4 +89,4 @@ declare class WebBase extends Base {
87
89
  emitter: PhecdaEmitter;
88
90
  }
89
91
 
90
- export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
92
+ export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, getParamtypes, phecdaNamespace, setDefaultPhecda, wait };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Events, Construct, Base } from 'phecda-core';
2
2
  export * from 'phecda-core';
3
3
  import * as mitt from 'mitt';
4
4
  import { Handler, WildcardHandler } from 'mitt';
5
+ export { Mixin } from 'ts-mixer';
5
6
 
6
7
  interface PhecdaEmitter {
7
8
  on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
@@ -16,6 +17,7 @@ declare const emitter: PhecdaEmitter;
16
17
  declare function defaultWebInject(): void;
17
18
 
18
19
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
20
+ declare function getParamtypes(Model: Construct): any;
19
21
  declare const phecdaNamespace: Map<string, WebPhecda>;
20
22
  declare function setDefaultPhecda(namespace: string, phecda: WebPhecda): void;
21
23
  /**
@@ -87,4 +89,4 @@ declare class WebBase extends Base {
87
89
  emitter: PhecdaEmitter;
88
90
  }
89
91
 
90
- export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
92
+ export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, getParamtypes, phecdaNamespace, setDefaultPhecda, wait };
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
  // src/index.ts
33
33
  var src_exports = {};
34
34
  __export(src_exports, {
35
+ Mixin: () => import_ts_mixer.Mixin,
35
36
  WebBase: () => WebBase,
36
37
  WebPhecda: () => WebPhecda,
37
38
  bindMethod: () => bindMethod,
@@ -39,6 +40,7 @@ __export(src_exports, {
39
40
  delDefaultPhecda: () => delDefaultPhecda,
40
41
  emitter: () => emitter,
41
42
  getDefaultPhecda: () => getDefaultPhecda,
43
+ getParamtypes: () => getParamtypes,
42
44
  phecdaNamespace: () => phecdaNamespace,
43
45
  setDefaultPhecda: () => setDefaultPhecda,
44
46
  wait: () => wait
@@ -52,8 +54,8 @@ var import_mitt = __toESM(require("mitt"));
52
54
  var emitter = (0, import_mitt.default)();
53
55
  function defaultWebInject() {
54
56
  if (!(0, import_phecda_core.getInject)("watcher")) {
55
- (0, import_phecda_core.setInject)("watcher", ({ eventName, instance, key, options }) => {
56
- 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;
57
59
  if (options?.once) {
58
60
  const handler = /* @__PURE__ */ __name(() => {
59
61
  fn();
@@ -67,22 +69,22 @@ function defaultWebInject() {
67
69
  });
68
70
  }
69
71
  if (!(0, import_phecda_core.getInject)("storage")) {
70
- (0, import_phecda_core.setInject)("storage", ({ tag, key, instance, toJSON, toString }) => {
71
- 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}`;
72
74
  const initstr = localStorage.getItem(tag);
73
75
  if (initstr) {
74
76
  const data = toJSON(initstr);
75
- if (key) {
76
- instance[key] = data;
77
+ if (property) {
78
+ instance[property] = data;
77
79
  } else {
78
80
  for (const i in data) {
79
81
  if (i) instance[i] = data[i];
80
82
  }
81
83
  }
82
84
  }
83
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
85
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
84
86
  globalThis.addEventListener("beforeunload", () => {
85
- localStorage.setItem(tag, toString(key ? instance[key] : instance));
87
+ localStorage.setItem(tag, toString(property ? instance[property] : instance));
86
88
  });
87
89
  });
88
90
  }
@@ -119,8 +121,8 @@ function wait(...instances) {
119
121
  return Promise.all(instances.map((i) => i.__PROMISE_SYMBOL__));
120
122
  }
121
123
  __name(wait, "wait");
122
- function getParamtypes(Model, key) {
123
- return Reflect.getMetadata("design:paramtypes", Model, key);
124
+ function getParamtypes(Model) {
125
+ return Reflect.getMetadata("design:paramtypes", Model);
124
126
  }
125
127
  __name(getParamtypes, "getParamtypes");
126
128
  var phecdaNamespace = /* @__PURE__ */ new Map();
@@ -210,7 +212,7 @@ var WebPhecda = class {
210
212
  this.emit("Initialize", {
211
213
  tag
212
214
  });
213
- (0, import_phecda_core2.invokeHandler)("init", instance2);
215
+ (0, import_phecda_core2.invokeInit)(instance2);
214
216
  }
215
217
  return instance2;
216
218
  }, "initModel");
@@ -282,7 +284,7 @@ var WebPhecda = class {
282
284
  tag
283
285
  });
284
286
  const { state } = this;
285
- await (0, import_phecda_core2.invokeHandler)("unmount", this.get(tag));
287
+ await (0, import_phecda_core2.invokeUnmount)(this.get(tag));
286
288
  delete state[tag];
287
289
  }
288
290
  async unmountAll() {
@@ -327,8 +329,12 @@ var WebBase = class extends import_phecda_core3.Base {
327
329
  }
328
330
  emitter = emitter;
329
331
  };
332
+
333
+ // src/index.ts
334
+ var import_ts_mixer = require("ts-mixer");
330
335
  // Annotate the CommonJS export names for ESM import in node:
331
336
  0 && (module.exports = {
337
+ Mixin,
332
338
  WebBase,
333
339
  WebPhecda,
334
340
  bindMethod,
@@ -336,6 +342,7 @@ var WebBase = class extends import_phecda_core3.Base {
336
342
  delDefaultPhecda,
337
343
  emitter,
338
344
  getDefaultPhecda,
345
+ getParamtypes,
339
346
  phecdaNamespace,
340
347
  setDefaultPhecda,
341
348
  wait,
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
 
@@ -77,8 +77,8 @@ function wait(...instances) {
77
77
  return Promise.all(instances.map((i) => i.__PROMISE_SYMBOL__));
78
78
  }
79
79
  __name(wait, "wait");
80
- function getParamtypes(Model, key) {
81
- return Reflect.getMetadata("design:paramtypes", Model, key);
80
+ function getParamtypes(Model) {
81
+ return Reflect.getMetadata("design:paramtypes", Model);
82
82
  }
83
83
  __name(getParamtypes, "getParamtypes");
84
84
  var phecdaNamespace = /* @__PURE__ */ new Map();
@@ -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() {
@@ -285,7 +285,11 @@ var WebBase = class extends Base {
285
285
  }
286
286
  emitter = emitter;
287
287
  };
288
+
289
+ // src/index.ts
290
+ import { Mixin } from "ts-mixer";
288
291
  export {
292
+ Mixin,
289
293
  WebBase,
290
294
  WebPhecda,
291
295
  bindMethod,
@@ -293,6 +297,7 @@ export {
293
297
  delDefaultPhecda,
294
298
  emitter,
295
299
  getDefaultPhecda,
300
+ getParamtypes,
296
301
  phecdaNamespace,
297
302
  setDefaultPhecda,
298
303
  wait
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "2.0.7",
3
+ "version": "3.0.0",
4
4
  "description": "using proxy, provide phecda function to web app",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -18,7 +18,8 @@
18
18
  "dependencies": {
19
19
  "mitt": "^3.0.0",
20
20
  "reflect-metadata": "^0.1.13",
21
- "phecda-core": "3.1.1"
21
+ "ts-mixer": "^6.0.4",
22
+ "phecda-core": "4.0.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "tsup": "^8.1.0"