phecda-web 2.0.1 → 2.0.2

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.ts CHANGED
@@ -14,6 +14,8 @@ declare const emitter: PhecdaEmitter;
14
14
  declare function defaultWebInject(): void;
15
15
 
16
16
  declare function wait(...instances: InstanceType<Construct>[]): Promise<any[]>;
17
+ declare function setDefaultPhecda(phecda: WebPhecda): void;
18
+ declare function getDefaultPhecda(): WebPhecda;
17
19
  declare function bindMethod(instance: any): any;
18
20
  declare class WebPhecda {
19
21
  protected parseModule: <Instance = any>(instance: Instance) => Instance;
@@ -46,4 +48,4 @@ declare class Base {
46
48
  private _unmount;
47
49
  }
48
50
 
49
- export { Base, DeepPartial, PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, emitter, wait };
51
+ export { Base, DeepPartial, PhecdaEmitter, WebPhecda, bindMethod, defaultWebInject, emitter, getDefaultPhecda, setDefaultPhecda, wait };
package/dist/index.js CHANGED
@@ -37,18 +37,18 @@ __export(src_exports, {
37
37
  bindMethod: () => bindMethod,
38
38
  defaultWebInject: () => defaultWebInject,
39
39
  emitter: () => emitter,
40
+ getDefaultPhecda: () => getDefaultPhecda,
41
+ setDefaultPhecda: () => setDefaultPhecda,
40
42
  wait: () => wait
41
43
  });
42
44
  module.exports = __toCommonJS(src_exports);
43
45
  __reExport(src_exports, require("phecda-core"), module.exports);
44
46
 
45
- // src/plugin.ts
47
+ // src/inject.ts
46
48
  var import_phecda_core = require("phecda-core");
47
49
  var import_mitt = __toESM(require("mitt"));
48
50
  var emitter = (0, import_mitt.default)();
49
51
  function defaultWebInject() {
50
- if (typeof window === "undefined")
51
- return;
52
52
  if (!(0, import_phecda_core.getInject)("watcher")) {
53
53
  (0, import_phecda_core.setInject)("watcher", ({ eventName, instance, key, options }) => {
54
54
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
@@ -122,6 +122,15 @@ function getParamtypes(Model, key) {
122
122
  return Reflect.getMetadata("design:paramtypes", Model, key);
123
123
  }
124
124
  __name(getParamtypes, "getParamtypes");
125
+ var defaultPhecda;
126
+ function setDefaultPhecda(phecda) {
127
+ defaultPhecda = phecda;
128
+ }
129
+ __name(setDefaultPhecda, "setDefaultPhecda");
130
+ function getDefaultPhecda() {
131
+ return defaultPhecda;
132
+ }
133
+ __name(getDefaultPhecda, "getDefaultPhecda");
125
134
  var bindCache = /* @__PURE__ */ new WeakMap();
126
135
  function bindMethod(instance) {
127
136
  if (!bindCache.has(instance)) {
@@ -150,7 +159,10 @@ var WebPhecda = class {
150
159
  this.origin = {};
151
160
  this.state = {};
152
161
  this.modelMap = /* @__PURE__ */ new WeakMap();
153
- defaultWebInject();
162
+ if (typeof window !== "undefined") {
163
+ defaultWebInject();
164
+ setDefaultPhecda(this);
165
+ }
154
166
  }
155
167
  // Initialize a module that has not been created yet, and return it directly if it is cached.
156
168
  init(model) {
@@ -315,6 +327,8 @@ _ts_decorate([
315
327
  bindMethod,
316
328
  defaultWebInject,
317
329
  emitter,
330
+ getDefaultPhecda,
331
+ setDefaultPhecda,
318
332
  wait,
319
333
  ...require("phecda-core")
320
334
  });
package/dist/index.mjs CHANGED
@@ -4,13 +4,11 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/index.ts
5
5
  export * from "phecda-core";
6
6
 
7
- // src/plugin.ts
7
+ // src/inject.ts
8
8
  import { getInject, setInject } from "phecda-core";
9
9
  import mitt from "mitt";
10
10
  var emitter = mitt();
11
11
  function defaultWebInject() {
12
- if (typeof window === "undefined")
13
- return;
14
12
  if (!getInject("watcher")) {
15
13
  setInject("watcher", ({ eventName, instance, key, options }) => {
16
14
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
@@ -84,6 +82,15 @@ function getParamtypes(Model, key) {
84
82
  return Reflect.getMetadata("design:paramtypes", Model, key);
85
83
  }
86
84
  __name(getParamtypes, "getParamtypes");
85
+ var defaultPhecda;
86
+ function setDefaultPhecda(phecda) {
87
+ defaultPhecda = phecda;
88
+ }
89
+ __name(setDefaultPhecda, "setDefaultPhecda");
90
+ function getDefaultPhecda() {
91
+ return defaultPhecda;
92
+ }
93
+ __name(getDefaultPhecda, "getDefaultPhecda");
87
94
  var bindCache = /* @__PURE__ */ new WeakMap();
88
95
  function bindMethod(instance) {
89
96
  if (!bindCache.has(instance)) {
@@ -112,7 +119,10 @@ var WebPhecda = class {
112
119
  this.origin = {};
113
120
  this.state = {};
114
121
  this.modelMap = /* @__PURE__ */ new WeakMap();
115
- defaultWebInject();
122
+ if (typeof window !== "undefined") {
123
+ defaultWebInject();
124
+ setDefaultPhecda(this);
125
+ }
116
126
  }
117
127
  // Initialize a module that has not been created yet, and return it directly if it is cached.
118
128
  init(model) {
@@ -276,5 +286,7 @@ export {
276
286
  bindMethod,
277
287
  defaultWebInject,
278
288
  emitter,
289
+ getDefaultPhecda,
290
+ setDefaultPhecda,
279
291
  wait
280
292
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "using proxy, provide phecda function to web app",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",