phecda-web 1.0.1-alpha.9 → 1.0.1-beta.11
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 +12 -3
- package/dist/index.js +38 -13
- package/dist/index.mjs +38 -14
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,16 @@ declare function waitUntilInit(...instances: InstanceType<Construct>[]): Promise
|
|
|
20
20
|
declare function resetActiveInstance(instance?: ActiveInstance): void;
|
|
21
21
|
declare function getActiveInstance(): ActiveInstance;
|
|
22
22
|
declare function serializeState(): any;
|
|
23
|
-
declare function isModuleLoad(
|
|
24
|
-
declare function unmountModule(
|
|
23
|
+
declare function isModuleLoad(model: Construct): boolean;
|
|
24
|
+
declare function unmountModule(model: Construct | PropertyKey): Promise<void>;
|
|
25
25
|
|
|
26
|
-
|
|
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.
|
|
49
|
-
(0, import_phecda_core.
|
|
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.
|
|
64
|
-
(0, import_phecda_core.
|
|
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);
|
|
@@ -107,27 +108,51 @@ function serializeState() {
|
|
|
107
108
|
return JSON.parse(JSON.stringify(activeInstance.state));
|
|
108
109
|
}
|
|
109
110
|
__name(serializeState, "serializeState");
|
|
110
|
-
function isModuleLoad(
|
|
111
|
+
function isModuleLoad(model) {
|
|
111
112
|
const { origin, state } = getActiveInstance();
|
|
112
|
-
const tag = (0, import_phecda_core2.getTag)(
|
|
113
|
+
const tag = (0, import_phecda_core2.getTag)(model);
|
|
113
114
|
if (tag in state) {
|
|
114
|
-
if (origin.get(state[tag]) !==
|
|
115
|
-
throw new Error(`Synonym module: Module taged "${String(tag)}" (but not "${
|
|
115
|
+
if (origin.get(state[tag]) !== model)
|
|
116
|
+
throw new Error(`Synonym module: Module taged "${String(tag)}" (but not "${model.name}") has been loaded before`);
|
|
116
117
|
return true;
|
|
117
118
|
}
|
|
118
119
|
return false;
|
|
119
120
|
}
|
|
120
121
|
__name(isModuleLoad, "isModuleLoad");
|
|
121
|
-
async function unmountModule(
|
|
122
|
-
if (typeof
|
|
123
|
-
|
|
122
|
+
async function unmountModule(model) {
|
|
123
|
+
if (typeof model === "object")
|
|
124
|
+
model = (0, import_phecda_core2.getTag)(model);
|
|
124
125
|
const { state } = getActiveInstance();
|
|
125
|
-
await (0, import_phecda_core2.invokeHandler)("unmount", state[
|
|
126
|
-
delete state[
|
|
126
|
+
await (0, import_phecda_core2.invokeHandler)("unmount", state[model]);
|
|
127
|
+
delete state[model];
|
|
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 {
|
|
8
|
+
import { getKey, injectKey } from "phecda-core";
|
|
9
9
|
import mitt from "mitt";
|
|
10
10
|
var emitter = mitt();
|
|
11
11
|
function defaultWebInject() {
|
|
12
|
-
if (!
|
|
13
|
-
|
|
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 (!
|
|
28
|
-
|
|
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);
|
|
@@ -71,26 +71,50 @@ function serializeState() {
|
|
|
71
71
|
return JSON.parse(JSON.stringify(activeInstance.state));
|
|
72
72
|
}
|
|
73
73
|
__name(serializeState, "serializeState");
|
|
74
|
-
function isModuleLoad(
|
|
74
|
+
function isModuleLoad(model) {
|
|
75
75
|
const { origin, state } = getActiveInstance();
|
|
76
|
-
const tag = getTag(
|
|
76
|
+
const tag = getTag(model);
|
|
77
77
|
if (tag in state) {
|
|
78
|
-
if (origin.get(state[tag]) !==
|
|
79
|
-
throw new Error(`Synonym module: Module taged "${String(tag)}" (but not "${
|
|
78
|
+
if (origin.get(state[tag]) !== model)
|
|
79
|
+
throw new Error(`Synonym module: Module taged "${String(tag)}" (but not "${model.name}") has been loaded before`);
|
|
80
80
|
return true;
|
|
81
81
|
}
|
|
82
82
|
return false;
|
|
83
83
|
}
|
|
84
84
|
__name(isModuleLoad, "isModuleLoad");
|
|
85
|
-
async function unmountModule(
|
|
86
|
-
if (typeof
|
|
87
|
-
|
|
85
|
+
async function unmountModule(model) {
|
|
86
|
+
if (typeof model === "object")
|
|
87
|
+
model = getTag(model);
|
|
88
88
|
const { state } = getActiveInstance();
|
|
89
|
-
await invokeHandler("unmount", state[
|
|
90
|
-
delete state[
|
|
89
|
+
await invokeHandler("unmount", state[model]);
|
|
90
|
+
delete state[model];
|
|
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-
|
|
3
|
+
"version": "1.0.1-beta.11",
|
|
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-
|
|
16
|
+
"phecda-core": "3.0.0-beta.14"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsup": "^6.5.0"
|