phecda-web 1.0.1-alpha.8 → 1.0.1-beta.10

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
@@ -23,4 +23,13 @@ declare function serializeState(): any;
23
23
  declare function isModuleLoad(module: Construct): boolean;
24
24
  declare function unmountModule(module: Construct | PropertyKey): Promise<void>;
25
25
 
26
- export { ActiveInstance, PhecdaEmitter, defaultWebInject, emitter, getActiveInstance, isModuleLoad, resetActiveInstance, serializeState, unmountModule, waitUntilInit };
26
+ declare class P {
27
+ constructor();
28
+ get tag(): PropertyKey;
29
+ then(cb: () => void, reject?: (e: any) => void): any;
30
+ on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
31
+ emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
32
+ off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
33
+ }
34
+
35
+ export { ActiveInstance, P, PhecdaEmitter, defaultWebInject, emitter, getActiveInstance, isModuleLoad, resetActiveInstance, serializeState, unmountModule, waitUntilInit };
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  // src/index.ts
29
29
  var src_exports = {};
30
30
  __export(src_exports, {
31
+ P: () => P,
31
32
  defaultWebInject: () => defaultWebInject,
32
33
  emitter: () => emitter,
33
34
  getActiveInstance: () => getActiveInstance,
@@ -45,8 +46,8 @@ var import_phecda_core = require("phecda-core");
45
46
  var import_mitt = __toESM(require("mitt"));
46
47
  var emitter = (0, import_mitt.default)();
47
48
  function defaultWebInject() {
48
- if (!(0, import_phecda_core.getProperty)("watcher")) {
49
- (0, import_phecda_core.injectProperty)("watcher", ({ eventName, instance, key, options }) => {
49
+ if (!(0, import_phecda_core.getKey)("watcher")) {
50
+ (0, import_phecda_core.injectKey)("watcher", ({ eventName, instance, key, options }) => {
50
51
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
51
52
  if (options?.once) {
52
53
  const handler = /* @__PURE__ */ __name(() => {
@@ -60,8 +61,8 @@ function defaultWebInject() {
60
61
  return () => emitter.off(eventName);
61
62
  });
62
63
  }
63
- if (!(0, import_phecda_core.getProperty)("storage")) {
64
- (0, import_phecda_core.injectProperty)("storage", ({ tag, key, instance, toJSON, toString }) => {
64
+ if (!(0, import_phecda_core.getKey)("storage")) {
65
+ (0, import_phecda_core.injectKey)("storage", ({ tag, key, instance, toJSON, toString }) => {
65
66
  if (!tag)
66
67
  return;
67
68
  const initstr = localStorage.getItem(tag);
@@ -126,8 +127,32 @@ async function unmountModule(module2) {
126
127
  delete state[module2];
127
128
  }
128
129
  __name(unmountModule, "unmountModule");
130
+
131
+ // src/base.ts
132
+ var import_phecda_core3 = require("phecda-core");
133
+ var P = class {
134
+ constructor() {
135
+ }
136
+ get tag() {
137
+ return (0, import_phecda_core3.getTag)(this);
138
+ }
139
+ then(cb, reject) {
140
+ return this._promise.then(cb, reject);
141
+ }
142
+ on(type, handler) {
143
+ emitter.on(type, handler);
144
+ }
145
+ emit(type, param) {
146
+ emitter.emit(type, param);
147
+ }
148
+ off(type, handler) {
149
+ emitter.off(type, handler);
150
+ }
151
+ };
152
+ __name(P, "P");
129
153
  // Annotate the CommonJS export names for ESM import in node:
130
154
  0 && (module.exports = {
155
+ P,
131
156
  defaultWebInject,
132
157
  emitter,
133
158
  getActiveInstance,
package/dist/index.mjs CHANGED
@@ -5,12 +5,12 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
5
5
  export * from "phecda-core";
6
6
 
7
7
  // src/plugin.ts
8
- import { getProperty, injectProperty } from "phecda-core";
8
+ import { getKey, injectKey } from "phecda-core";
9
9
  import mitt from "mitt";
10
10
  var emitter = mitt();
11
11
  function defaultWebInject() {
12
- if (!getProperty("watcher")) {
13
- injectProperty("watcher", ({ eventName, instance, key, options }) => {
12
+ if (!getKey("watcher")) {
13
+ injectKey("watcher", ({ eventName, instance, key, options }) => {
14
14
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
15
15
  if (options?.once) {
16
16
  const handler = /* @__PURE__ */ __name(() => {
@@ -24,8 +24,8 @@ function defaultWebInject() {
24
24
  return () => emitter.off(eventName);
25
25
  });
26
26
  }
27
- if (!getProperty("storage")) {
28
- injectProperty("storage", ({ tag, key, instance, toJSON, toString }) => {
27
+ if (!getKey("storage")) {
28
+ injectKey("storage", ({ tag, key, instance, toJSON, toString }) => {
29
29
  if (!tag)
30
30
  return;
31
31
  const initstr = localStorage.getItem(tag);
@@ -90,7 +90,31 @@ async function unmountModule(module) {
90
90
  delete state[module];
91
91
  }
92
92
  __name(unmountModule, "unmountModule");
93
+
94
+ // src/base.ts
95
+ import { getTag as getTag2 } from "phecda-core";
96
+ var P = class {
97
+ constructor() {
98
+ }
99
+ get tag() {
100
+ return getTag2(this);
101
+ }
102
+ then(cb, reject) {
103
+ return this._promise.then(cb, reject);
104
+ }
105
+ on(type, handler) {
106
+ emitter.on(type, handler);
107
+ }
108
+ emit(type, param) {
109
+ emitter.emit(type, param);
110
+ }
111
+ off(type, handler) {
112
+ emitter.off(type, handler);
113
+ }
114
+ };
115
+ __name(P, "P");
93
116
  export {
117
+ P,
94
118
  defaultWebInject,
95
119
  emitter,
96
120
  getActiveInstance,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-web",
3
- "version": "1.0.1-alpha.8",
3
+ "version": "1.0.1-beta.10",
4
4
  "description": "provide web function for phecda",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "mitt": "^3.0.0",
16
- "phecda-core": "3.0.0-alpha.11"
16
+ "phecda-core": "3.0.0-beta.13"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tsup": "^6.5.0"