phecda-web 2.0.3 → 2.0.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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Events, Construct } from 'phecda-core';
1
+ 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';
@@ -63,6 +63,7 @@ declare class WebPhecda {
63
63
  modelMap: WeakMap<object, any>;
64
64
  emitter: mitt.Emitter<InternalEvents>;
65
65
  constructor(namespace: string, parseModule: <Instance = any>(instance: Instance) => Instance);
66
+ private then;
66
67
  /**
67
68
  * Initialize a module that has not been created yet, and return it directly if it is cached.
68
69
  */
@@ -82,17 +83,8 @@ declare class WebPhecda {
82
83
  on(type: '*', handler: WildcardHandler<InternalEvents>): void;
83
84
  }
84
85
 
85
- declare class Base {
86
- private readonly __UNMOUNT_SYMBOL__;
87
- private readonly __PROMISE_SYMBOL__;
88
- constructor();
89
- get tag(): PropertyKey;
90
- then(cb: () => void, reject?: (e: any) => void): Promise<void>;
91
- on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
92
- emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
93
- off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
94
- private onUnmount;
95
- private _unmount;
86
+ declare class WebBase extends Base {
87
+ emitter: PhecdaEmitter;
96
88
  }
97
89
 
98
- export { Base, type DeepPartial, type PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
90
+ export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Events, Construct } from 'phecda-core';
1
+ 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';
@@ -63,6 +63,7 @@ declare class WebPhecda {
63
63
  modelMap: WeakMap<object, any>;
64
64
  emitter: mitt.Emitter<InternalEvents>;
65
65
  constructor(namespace: string, parseModule: <Instance = any>(instance: Instance) => Instance);
66
+ private then;
66
67
  /**
67
68
  * Initialize a module that has not been created yet, and return it directly if it is cached.
68
69
  */
@@ -82,17 +83,8 @@ declare class WebPhecda {
82
83
  on(type: '*', handler: WildcardHandler<InternalEvents>): void;
83
84
  }
84
85
 
85
- declare class Base {
86
- private readonly __UNMOUNT_SYMBOL__;
87
- private readonly __PROMISE_SYMBOL__;
88
- constructor();
89
- get tag(): PropertyKey;
90
- then(cb: () => void, reject?: (e: any) => void): Promise<void>;
91
- on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
92
- emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
93
- off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
94
- private onUnmount;
95
- private _unmount;
86
+ declare class WebBase extends Base {
87
+ emitter: PhecdaEmitter;
96
88
  }
97
89
 
98
- export { Base, type DeepPartial, type PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
90
+ export { type DeepPartial, type PhecdaEmitter, WebBase, WebPhecda, bindMethod, defaultWebInject, delDefaultPhecda, emitter, getDefaultPhecda, phecdaNamespace, setDefaultPhecda, wait };
package/dist/index.js CHANGED
@@ -32,7 +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
- Base: () => Base,
35
+ WebBase: () => WebBase,
36
36
  WebPhecda: () => WebPhecda,
37
37
  bindMethod: () => bindMethod,
38
38
  defaultWebInject: () => defaultWebInject,
@@ -142,7 +142,7 @@ function bindMethod(instance, wrapper) {
142
142
  const cache = /* @__PURE__ */ new WeakMap();
143
143
  bindCache.set(instance, new Proxy(instance, {
144
144
  get(target, p) {
145
- if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
145
+ if (typeof target[p] === "function" && p !== "constructor" && !target[p].toString().startsWith("(")) {
146
146
  if (!cache.has(target[p])) cache.set(target[p], wrapper ? wrapper(target, p) : target[p].bind(target));
147
147
  return cache.get(target[p]);
148
148
  }
@@ -178,6 +178,15 @@ var WebPhecda = class {
178
178
  setDefaultPhecda(namespace, this);
179
179
  }
180
180
  }
181
+ // @ts-expect-error internal
182
+ then(onfulfilled, onrejected) {
183
+ const then = this.then;
184
+ this.then = void 0;
185
+ wait(...Object.values(this.state)).then(() => onfulfilled?.(this), onrejected).then(() => {
186
+ this.then = then;
187
+ });
188
+ return this;
189
+ }
181
190
  /**
182
191
  * Initialize a module that has not been created yet, and return it directly if it is cached.
183
192
  */
@@ -312,57 +321,15 @@ var WebPhecda = class {
312
321
 
313
322
  // src/base.ts
314
323
  var import_phecda_core3 = require("phecda-core");
315
- function _ts_decorate(decorators, target, key, desc) {
316
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
317
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
318
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
319
- return c > 3 && r && Object.defineProperty(target, key, r), r;
320
- }
321
- __name(_ts_decorate, "_ts_decorate");
322
- function _ts_metadata(k, v) {
323
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
324
- }
325
- __name(_ts_metadata, "_ts_metadata");
326
- var Base = class {
324
+ var WebBase = class extends import_phecda_core3.Base {
327
325
  static {
328
- __name(this, "Base");
329
- }
330
- __UNMOUNT_SYMBOL__ = [];
331
- __PROMISE_SYMBOL__;
332
- constructor() {
333
- }
334
- get tag() {
335
- return (0, import_phecda_core3.getTag)(this);
336
- }
337
- then(cb, reject) {
338
- return this.__PROMISE_SYMBOL__.then(cb, reject);
339
- }
340
- on(type, handler) {
341
- emitter.on(type, handler);
342
- this.onUnmount(() => emitter.off(type, handler));
343
- }
344
- emit(type, param) {
345
- emitter.emit(type, param);
346
- }
347
- off(type, handler) {
348
- emitter.off(type, handler);
349
- }
350
- onUnmount(cb) {
351
- this.__UNMOUNT_SYMBOL__.push(cb);
352
- }
353
- _unmount() {
354
- return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
326
+ __name(this, "WebBase");
355
327
  }
328
+ emitter = emitter;
356
329
  };
357
- _ts_decorate([
358
- import_phecda_core3.Unmount,
359
- _ts_metadata("design:type", Function),
360
- _ts_metadata("design:paramtypes", []),
361
- _ts_metadata("design:returntype", void 0)
362
- ], Base.prototype, "_unmount", null);
363
330
  // Annotate the CommonJS export names for ESM import in node:
364
331
  0 && (module.exports = {
365
- Base,
332
+ WebBase,
366
333
  WebPhecda,
367
334
  bindMethod,
368
335
  defaultWebInject,
package/dist/index.mjs CHANGED
@@ -100,7 +100,7 @@ function bindMethod(instance, wrapper) {
100
100
  const cache = /* @__PURE__ */ new WeakMap();
101
101
  bindCache.set(instance, new Proxy(instance, {
102
102
  get(target, p) {
103
- if (typeof target[p] === "function" && !target[p].toString().startsWith("(")) {
103
+ if (typeof target[p] === "function" && p !== "constructor" && !target[p].toString().startsWith("(")) {
104
104
  if (!cache.has(target[p])) cache.set(target[p], wrapper ? wrapper(target, p) : target[p].bind(target));
105
105
  return cache.get(target[p]);
106
106
  }
@@ -136,6 +136,15 @@ var WebPhecda = class {
136
136
  setDefaultPhecda(namespace, this);
137
137
  }
138
138
  }
139
+ // @ts-expect-error internal
140
+ then(onfulfilled, onrejected) {
141
+ const then = this.then;
142
+ this.then = void 0;
143
+ wait(...Object.values(this.state)).then(() => onfulfilled?.(this), onrejected).then(() => {
144
+ this.then = then;
145
+ });
146
+ return this;
147
+ }
139
148
  /**
140
149
  * Initialize a module that has not been created yet, and return it directly if it is cached.
141
150
  */
@@ -269,57 +278,15 @@ var WebPhecda = class {
269
278
  };
270
279
 
271
280
  // src/base.ts
272
- import { Unmount, getTag as getTag2 } from "phecda-core";
273
- function _ts_decorate(decorators, target, key, desc) {
274
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
275
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
276
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
277
- return c > 3 && r && Object.defineProperty(target, key, r), r;
278
- }
279
- __name(_ts_decorate, "_ts_decorate");
280
- function _ts_metadata(k, v) {
281
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
282
- }
283
- __name(_ts_metadata, "_ts_metadata");
284
- var Base = class {
281
+ import { Base } from "phecda-core";
282
+ var WebBase = class extends Base {
285
283
  static {
286
- __name(this, "Base");
287
- }
288
- __UNMOUNT_SYMBOL__ = [];
289
- __PROMISE_SYMBOL__;
290
- constructor() {
291
- }
292
- get tag() {
293
- return getTag2(this);
294
- }
295
- then(cb, reject) {
296
- return this.__PROMISE_SYMBOL__.then(cb, reject);
297
- }
298
- on(type, handler) {
299
- emitter.on(type, handler);
300
- this.onUnmount(() => emitter.off(type, handler));
301
- }
302
- emit(type, param) {
303
- emitter.emit(type, param);
304
- }
305
- off(type, handler) {
306
- emitter.off(type, handler);
307
- }
308
- onUnmount(cb) {
309
- this.__UNMOUNT_SYMBOL__.push(cb);
310
- }
311
- _unmount() {
312
- return Promise.all(this.__UNMOUNT_SYMBOL__.map((fn) => fn()));
284
+ __name(this, "WebBase");
313
285
  }
286
+ emitter = emitter;
314
287
  };
315
- _ts_decorate([
316
- Unmount,
317
- _ts_metadata("design:type", Function),
318
- _ts_metadata("design:paramtypes", []),
319
- _ts_metadata("design:returntype", void 0)
320
- ], Base.prototype, "_unmount", null);
321
288
  export {
322
- Base,
289
+ WebBase,
323
290
  WebPhecda,
324
291
  bindMethod,
325
292
  defaultWebInject,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "using proxy, provide phecda function to web app",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "mitt": "^3.0.0",
20
20
  "reflect-metadata": "^0.1.13",
21
- "phecda-core": "3.0.0"
21
+ "phecda-core": "3.0.2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "tsup": "^8.1.0"