phecda-core 2.1.2-alpha.0 → 3.0.0-alpha.1
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 +37 -41
- package/dist/index.js +127 -160
- package/dist/index.mjs +123 -154
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ interface Handler {
|
|
|
10
10
|
interface Phecda {
|
|
11
11
|
prototype: any;
|
|
12
12
|
_namespace: {
|
|
13
|
-
__INIT_EVENT__: Set<PropertyKey>;
|
|
14
13
|
__EXPOSE_VAR__: Set<PropertyKey>;
|
|
15
14
|
__IGNORE_VAR__: Set<PropertyKey>;
|
|
16
15
|
__STATE_VAR__: Set<PropertyKey>;
|
|
@@ -24,26 +23,26 @@ type ClassValue<I> = {
|
|
|
24
23
|
interface Events {
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
declare function Init(
|
|
28
|
-
declare function Bind(value: any): (
|
|
29
|
-
declare function Ignore(
|
|
30
|
-
declare function Clear(
|
|
31
|
-
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (
|
|
32
|
-
declare function Expose(
|
|
33
|
-
declare function To(cb: (arg: any, instance: any, key: string) => any): (
|
|
34
|
-
declare function Tag(tag: string): (
|
|
35
|
-
declare function Assign(cb: (instance?: any) => any): (
|
|
36
|
-
declare function Global(
|
|
37
|
-
declare function Empty(
|
|
26
|
+
declare function Init(proto: any, key: PropertyKey): void;
|
|
27
|
+
declare function Bind(value: any): (proto: any, k: PropertyKey) => void;
|
|
28
|
+
declare function Ignore(proto: any, key: PropertyKey): void;
|
|
29
|
+
declare function Clear(proto: any, key: PropertyKey): void;
|
|
30
|
+
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (proto: any, key: PropertyKey) => void;
|
|
31
|
+
declare function Expose(proto: any, key: PropertyKey): void;
|
|
32
|
+
declare function To(cb: (arg: any, instance: any, key: string) => any): (proto: any, key: PropertyKey) => void;
|
|
33
|
+
declare function Tag(tag: string): (module: any) => void;
|
|
34
|
+
declare function Assign(cb: (instance?: any) => any): (module: any) => void;
|
|
35
|
+
declare function Global(module: any): void;
|
|
36
|
+
declare function Empty(module: any): void;
|
|
38
37
|
declare const DataMap: InjectData;
|
|
39
38
|
declare function Provide<K extends keyof InjectData>(key: K, value: InjectData[K]): void;
|
|
40
39
|
declare function Inject<K extends keyof InjectData>(key: K): InjectData[K];
|
|
41
|
-
declare function Nested<M extends new (...args: any) => any>(
|
|
40
|
+
declare function Nested<M extends new (...args: any) => any>(module: M): (proto: any, key: PropertyKey) => void;
|
|
42
41
|
|
|
43
|
-
declare function getTag<M extends new (...args: any) => any>(
|
|
42
|
+
declare function getTag<M extends new (...args: any) => any>(module: M): any;
|
|
44
43
|
declare function getSymbol<M extends new (...args: any) => any>(instance: InstanceType<M>): any;
|
|
45
|
-
declare function getBind<M extends new (...args: any) => any>(
|
|
46
|
-
declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(
|
|
44
|
+
declare function getBind<M extends new (...args: any) => any>(module: M): any;
|
|
45
|
+
declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(module: M, input: Data): InstanceType<M>;
|
|
47
46
|
declare function transformClass<M extends new (...args: any) => any>(instance: InstanceType<M>, force?: boolean): Promise<string[]>;
|
|
48
47
|
declare function classToValue<M>(instance: M): ClassValue<M>;
|
|
49
48
|
declare function snapShot<T extends new (...args: any) => any>(data: InstanceType<T>): {
|
|
@@ -51,39 +50,36 @@ declare function snapShot<T extends new (...args: any) => any>(data: InstanceTyp
|
|
|
51
50
|
clear(): void;
|
|
52
51
|
apply(): void;
|
|
53
52
|
};
|
|
54
|
-
declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: '
|
|
53
|
+
declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key: keyof InstanceType<M> | string, handler: ((target: any, key: PropertyKey) => void), type?: 'property' | 'class'): void;
|
|
55
54
|
declare function Pipeline(...decos: ((...args: any) => void)[]): (...args: any) => void;
|
|
56
55
|
|
|
57
|
-
declare function isPhecda(
|
|
58
|
-
declare
|
|
59
|
-
declare function
|
|
60
|
-
declare function
|
|
61
|
-
declare function
|
|
62
|
-
declare function
|
|
63
|
-
declare function
|
|
64
|
-
declare function
|
|
65
|
-
declare function
|
|
66
|
-
declare function
|
|
67
|
-
declare function
|
|
68
|
-
declare function
|
|
69
|
-
declare function
|
|
70
|
-
declare function
|
|
71
|
-
declare function
|
|
72
|
-
declare function
|
|
73
|
-
declare function
|
|
74
|
-
declare function getOwnState(target: Phecda, key: PropertyKey): Object;
|
|
75
|
-
declare function getState(target: Phecda, key: PropertyKey): any;
|
|
56
|
+
declare function isPhecda(module: any): boolean;
|
|
57
|
+
declare const SHARE_KEY: unique symbol;
|
|
58
|
+
declare function init(proto: Phecda): void;
|
|
59
|
+
declare function setVar(proto: Phecda, key: PropertyKey): void;
|
|
60
|
+
declare function setExposeKey(proto: Phecda, key: PropertyKey): void;
|
|
61
|
+
declare function setIgnoreKey(proto: Phecda, key: PropertyKey): void;
|
|
62
|
+
declare function getOwnModuleState(instance: Phecda): string[];
|
|
63
|
+
declare function getModuleState(instance: Phecda): PropertyKey[];
|
|
64
|
+
declare function getOwnExposeKey(instance: Phecda): string[];
|
|
65
|
+
declare function getExposeKey(instance: Phecda): PropertyKey[];
|
|
66
|
+
declare function getOwnIgnoreKey(instance: Phecda): string[];
|
|
67
|
+
declare function regisHandler(proto: Phecda, key: PropertyKey, handler: Handler): void;
|
|
68
|
+
declare function getOwnHandler(instance: Phecda, key: PropertyKey): Handler[];
|
|
69
|
+
declare function getHandler(instance: Phecda, key: PropertyKey): any[];
|
|
70
|
+
declare function setState(proto: Phecda, key: PropertyKey, state: Record<string, any>): void;
|
|
71
|
+
declare function getOwnState(instance: Phecda, key: PropertyKey): Object;
|
|
72
|
+
declare function getState(instance: Phecda, key: PropertyKey): any;
|
|
76
73
|
declare function register(instance: Phecda): void;
|
|
77
74
|
declare function registerAsync(instance: Phecda): Promise<void>;
|
|
78
75
|
|
|
79
76
|
declare const activeInstance: Record<string, any>;
|
|
80
77
|
declare function injectProperty(key: string, value: any): Record<string, any>;
|
|
81
78
|
declare function getProperty(key: string): any;
|
|
82
|
-
|
|
83
79
|
declare function Watcher(eventName: keyof Events, options?: {
|
|
84
80
|
once: boolean;
|
|
85
|
-
}): (
|
|
86
|
-
declare function Effect(eventName: string, options?: any): (
|
|
87
|
-
declare function Storage(storeKey?: string): (
|
|
81
|
+
}): (proto: any, key: string) => void;
|
|
82
|
+
declare function Effect(eventName: string, options?: any): (proto: any, key: string) => void;
|
|
83
|
+
declare function Storage(storeKey?: string): (proto: any, key?: PropertyKey) => void;
|
|
88
84
|
|
|
89
|
-
export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Nested, Phecda, Pipeline, Provide, Storage, Tag, To, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler,
|
|
85
|
+
export { Assign, Bind, ClassValue, Clear, DataMap, Effect, Empty, Err, Events, Expose, Global, Handler, Ignore, Init, Inject, InjectData, NameSpace, Nested, Phecda, Pipeline, Provide, SHARE_KEY, Storage, Tag, To, Watcher, activeInstance, addDecoToClass, classToValue, getBind, getExposeKey, getHandler, getModuleState, getOwnExposeKey, getOwnHandler, getOwnIgnoreKey, getOwnModuleState, getOwnState, getProperty, getState, getSymbol, getTag, init, injectProperty, isPhecda, plainToClass, regisHandler, register, registerAsync, setExposeKey, setIgnoreKey, setState, setVar, snapShot, transformClass };
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
Nested: () => Nested,
|
|
37
37
|
Pipeline: () => Pipeline,
|
|
38
38
|
Provide: () => Provide,
|
|
39
|
+
SHARE_KEY: () => SHARE_KEY,
|
|
39
40
|
Storage: () => Storage,
|
|
40
41
|
Tag: () => Tag,
|
|
41
42
|
To: () => To,
|
|
@@ -46,13 +47,11 @@ __export(src_exports, {
|
|
|
46
47
|
getBind: () => getBind,
|
|
47
48
|
getExposeKey: () => getExposeKey,
|
|
48
49
|
getHandler: () => getHandler,
|
|
49
|
-
|
|
50
|
-
getModelState: () => getModelState,
|
|
50
|
+
getModuleState: () => getModuleState,
|
|
51
51
|
getOwnExposeKey: () => getOwnExposeKey,
|
|
52
52
|
getOwnHandler: () => getOwnHandler,
|
|
53
53
|
getOwnIgnoreKey: () => getOwnIgnoreKey,
|
|
54
|
-
|
|
55
|
-
getOwnModelState: () => getOwnModelState,
|
|
54
|
+
getOwnModuleState: () => getOwnModuleState,
|
|
56
55
|
getOwnState: () => getOwnState,
|
|
57
56
|
getProperty: () => getProperty,
|
|
58
57
|
getState: () => getState,
|
|
@@ -63,32 +62,30 @@ __export(src_exports, {
|
|
|
63
62
|
isPhecda: () => isPhecda,
|
|
64
63
|
plainToClass: () => plainToClass,
|
|
65
64
|
regisHandler: () => regisHandler,
|
|
66
|
-
regisInitEvent: () => regisInitEvent,
|
|
67
65
|
register: () => register,
|
|
68
66
|
registerAsync: () => registerAsync,
|
|
69
67
|
setExposeKey: () => setExposeKey,
|
|
70
68
|
setIgnoreKey: () => setIgnoreKey,
|
|
71
|
-
setModelVar: () => setModelVar,
|
|
72
69
|
setState: () => setState,
|
|
70
|
+
setVar: () => setVar,
|
|
73
71
|
snapShot: () => snapShot,
|
|
74
72
|
transformClass: () => transformClass
|
|
75
73
|
});
|
|
76
74
|
module.exports = __toCommonJS(src_exports);
|
|
77
75
|
|
|
78
76
|
// src/core.ts
|
|
79
|
-
function isPhecda(
|
|
80
|
-
if (typeof
|
|
81
|
-
return !!
|
|
82
|
-
}
|
|
77
|
+
function isPhecda(module2) {
|
|
78
|
+
if (typeof module2 === "function")
|
|
79
|
+
return !!module2.prototype?._namespace;
|
|
83
80
|
return false;
|
|
84
81
|
}
|
|
85
82
|
__name(isPhecda, "isPhecda");
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
var SHARE_KEY = Symbol("phecda-core");
|
|
84
|
+
function init(proto) {
|
|
85
|
+
if (!proto)
|
|
88
86
|
return;
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
87
|
+
if (!proto.hasOwnProperty("_namespace")) {
|
|
88
|
+
proto._namespace = {
|
|
92
89
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
93
90
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
94
91
|
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -98,56 +95,31 @@ function init(target) {
|
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
__name(init, "init");
|
|
101
|
-
function
|
|
102
|
-
init(
|
|
103
|
-
|
|
98
|
+
function setVar(proto, key) {
|
|
99
|
+
init(proto);
|
|
100
|
+
proto._namespace.__STATE_VAR__.add(key);
|
|
101
|
+
setExposeKey(proto, key);
|
|
104
102
|
}
|
|
105
|
-
__name(
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return [
|
|
110
|
-
...target._namespace.__INIT_EVENT__
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
__name(getOwnInitEvent, "getOwnInitEvent");
|
|
114
|
-
function getInitEvent(target) {
|
|
115
|
-
let proto = Object.getPrototypeOf(target);
|
|
116
|
-
const set = /* @__PURE__ */ new Set();
|
|
117
|
-
while (proto?._namespace) {
|
|
118
|
-
proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
|
|
119
|
-
proto = Object.getPrototypeOf(proto);
|
|
120
|
-
}
|
|
121
|
-
return [
|
|
122
|
-
...set
|
|
123
|
-
];
|
|
124
|
-
}
|
|
125
|
-
__name(getInitEvent, "getInitEvent");
|
|
126
|
-
function setModelVar(target, key) {
|
|
127
|
-
init(target);
|
|
128
|
-
target._namespace.__STATE_VAR__.add(key);
|
|
129
|
-
setExposeKey(target, key);
|
|
130
|
-
}
|
|
131
|
-
__name(setModelVar, "setModelVar");
|
|
132
|
-
function setExposeKey(target, key) {
|
|
133
|
-
init(target);
|
|
134
|
-
target._namespace.__EXPOSE_VAR__.add(key);
|
|
103
|
+
__name(setVar, "setVar");
|
|
104
|
+
function setExposeKey(proto, key) {
|
|
105
|
+
init(proto);
|
|
106
|
+
proto._namespace.__EXPOSE_VAR__.add(key);
|
|
135
107
|
}
|
|
136
108
|
__name(setExposeKey, "setExposeKey");
|
|
137
|
-
function setIgnoreKey(
|
|
138
|
-
init(
|
|
139
|
-
|
|
109
|
+
function setIgnoreKey(proto, key) {
|
|
110
|
+
init(proto);
|
|
111
|
+
proto._namespace.__IGNORE_VAR__.add(key);
|
|
140
112
|
}
|
|
141
113
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
142
|
-
function
|
|
143
|
-
|
|
114
|
+
function getOwnModuleState(instance) {
|
|
115
|
+
instance = Object.getPrototypeOf(instance);
|
|
144
116
|
return [
|
|
145
|
-
...
|
|
117
|
+
...instance._namespace.__STATE_VAR__
|
|
146
118
|
];
|
|
147
119
|
}
|
|
148
|
-
__name(
|
|
149
|
-
function
|
|
150
|
-
let proto = Object.getPrototypeOf(
|
|
120
|
+
__name(getOwnModuleState, "getOwnModuleState");
|
|
121
|
+
function getModuleState(instance) {
|
|
122
|
+
let proto = Object.getPrototypeOf(instance);
|
|
151
123
|
const set = /* @__PURE__ */ new Set();
|
|
152
124
|
while (proto?._namespace) {
|
|
153
125
|
proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
|
|
@@ -157,16 +129,16 @@ function getModelState(target) {
|
|
|
157
129
|
...set
|
|
158
130
|
];
|
|
159
131
|
}
|
|
160
|
-
__name(
|
|
161
|
-
function getOwnExposeKey(
|
|
162
|
-
|
|
132
|
+
__name(getModuleState, "getModuleState");
|
|
133
|
+
function getOwnExposeKey(instance) {
|
|
134
|
+
instance = Object.getPrototypeOf(instance);
|
|
163
135
|
return [
|
|
164
|
-
...
|
|
165
|
-
].filter((item) => !
|
|
136
|
+
...instance._namespace.__EXPOSE_VAR__
|
|
137
|
+
].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
|
|
166
138
|
}
|
|
167
139
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
168
|
-
function getExposeKey(
|
|
169
|
-
let proto = Object.getPrototypeOf(
|
|
140
|
+
function getExposeKey(instance) {
|
|
141
|
+
let proto = Object.getPrototypeOf(instance);
|
|
170
142
|
const set = /* @__PURE__ */ new Set();
|
|
171
143
|
while (proto?._namespace) {
|
|
172
144
|
[
|
|
@@ -179,32 +151,32 @@ function getExposeKey(target) {
|
|
|
179
151
|
];
|
|
180
152
|
}
|
|
181
153
|
__name(getExposeKey, "getExposeKey");
|
|
182
|
-
function getOwnIgnoreKey(
|
|
183
|
-
if (!
|
|
154
|
+
function getOwnIgnoreKey(instance) {
|
|
155
|
+
if (!instance?._namespace)
|
|
184
156
|
return [];
|
|
185
157
|
return [
|
|
186
|
-
...
|
|
158
|
+
...instance._namespace.__IGNORE_VAR__
|
|
187
159
|
];
|
|
188
160
|
}
|
|
189
161
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
190
|
-
function regisHandler(
|
|
191
|
-
init(
|
|
192
|
-
if (!
|
|
193
|
-
|
|
162
|
+
function regisHandler(proto, key, handler) {
|
|
163
|
+
init(proto);
|
|
164
|
+
if (!proto._namespace.__STATE_HANDLER__.has(key))
|
|
165
|
+
proto._namespace.__STATE_HANDLER__.set(key, [
|
|
194
166
|
handler
|
|
195
167
|
]);
|
|
196
168
|
else
|
|
197
|
-
|
|
169
|
+
proto._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
198
170
|
}
|
|
199
171
|
__name(regisHandler, "regisHandler");
|
|
200
|
-
function getOwnHandler(
|
|
201
|
-
if (!
|
|
172
|
+
function getOwnHandler(instance, key) {
|
|
173
|
+
if (!instance?._namespace)
|
|
202
174
|
return [];
|
|
203
|
-
return
|
|
175
|
+
return instance._namespace.__STATE_HANDLER__.get(key) || [];
|
|
204
176
|
}
|
|
205
177
|
__name(getOwnHandler, "getOwnHandler");
|
|
206
|
-
function getHandler(
|
|
207
|
-
let proto = Object.getPrototypeOf(
|
|
178
|
+
function getHandler(instance, key) {
|
|
179
|
+
let proto = Object.getPrototypeOf(instance);
|
|
208
180
|
const set = /* @__PURE__ */ new Set();
|
|
209
181
|
while (proto?._namespace) {
|
|
210
182
|
proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
|
|
@@ -215,19 +187,19 @@ function getHandler(target, key) {
|
|
|
215
187
|
];
|
|
216
188
|
}
|
|
217
189
|
__name(getHandler, "getHandler");
|
|
218
|
-
function setState(
|
|
219
|
-
init(
|
|
220
|
-
const namespace =
|
|
190
|
+
function setState(proto, key, state) {
|
|
191
|
+
init(proto);
|
|
192
|
+
const namespace = proto._namespace.__STATE_NAMESPACE__;
|
|
221
193
|
namespace.set(key, state);
|
|
222
194
|
}
|
|
223
195
|
__name(setState, "setState");
|
|
224
|
-
function getOwnState(
|
|
225
|
-
|
|
226
|
-
return
|
|
196
|
+
function getOwnState(instance, key) {
|
|
197
|
+
instance = Object.getPrototypeOf(instance);
|
|
198
|
+
return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
|
|
227
199
|
}
|
|
228
200
|
__name(getOwnState, "getOwnState");
|
|
229
|
-
function getState(
|
|
230
|
-
let proto = Object.getPrototypeOf(
|
|
201
|
+
function getState(instance, key) {
|
|
202
|
+
let proto = Object.getPrototypeOf(instance);
|
|
231
203
|
let ret = {};
|
|
232
204
|
while (proto?._namespace) {
|
|
233
205
|
const state = proto._namespace.__STATE_NAMESPACE__.get(key);
|
|
@@ -261,18 +233,18 @@ async function registerAsync(instance) {
|
|
|
261
233
|
__name(registerAsync, "registerAsync");
|
|
262
234
|
|
|
263
235
|
// src/helper.ts
|
|
264
|
-
function getTag(
|
|
265
|
-
return
|
|
236
|
+
function getTag(module2) {
|
|
237
|
+
return module2.prototype?.__TAG__;
|
|
266
238
|
}
|
|
267
239
|
__name(getTag, "getTag");
|
|
268
240
|
function getSymbol(instance) {
|
|
269
|
-
const
|
|
270
|
-
return getTag(
|
|
241
|
+
const module2 = instance.constructor;
|
|
242
|
+
return getTag(module2) || module2.name;
|
|
271
243
|
}
|
|
272
244
|
__name(getSymbol, "getSymbol");
|
|
273
|
-
function getBind(
|
|
274
|
-
const instance = new
|
|
275
|
-
const keys =
|
|
245
|
+
function getBind(module2) {
|
|
246
|
+
const instance = new module2();
|
|
247
|
+
const keys = getModuleState(instance);
|
|
276
248
|
const ret = {};
|
|
277
249
|
for (const item of keys) {
|
|
278
250
|
const state = getState(instance, item);
|
|
@@ -282,8 +254,8 @@ function getBind(Model) {
|
|
|
282
254
|
return ret;
|
|
283
255
|
}
|
|
284
256
|
__name(getBind, "getBind");
|
|
285
|
-
function plainToClass(
|
|
286
|
-
const instance = new
|
|
257
|
+
function plainToClass(module2, input) {
|
|
258
|
+
const instance = new module2();
|
|
287
259
|
const keys = getExposeKey(instance);
|
|
288
260
|
for (const item of keys)
|
|
289
261
|
instance[item] = input[item];
|
|
@@ -292,7 +264,7 @@ function plainToClass(Model, input) {
|
|
|
292
264
|
__name(plainToClass, "plainToClass");
|
|
293
265
|
async function transformClass(instance, force = false) {
|
|
294
266
|
const err = [];
|
|
295
|
-
const stateVars =
|
|
267
|
+
const stateVars = getModuleState(instance);
|
|
296
268
|
for (const item of stateVars) {
|
|
297
269
|
const handlers = getHandler(instance, item);
|
|
298
270
|
if (handlers) {
|
|
@@ -336,8 +308,8 @@ function snapShot(data) {
|
|
|
336
308
|
};
|
|
337
309
|
}
|
|
338
310
|
__name(snapShot, "snapShot");
|
|
339
|
-
function addDecoToClass(c, key, handler, type = "
|
|
340
|
-
handler(type === "
|
|
311
|
+
function addDecoToClass(c, key, handler, type = "class") {
|
|
312
|
+
handler(type === "class" ? c.prototype : c, key);
|
|
341
313
|
}
|
|
342
314
|
__name(addDecoToClass, "addDecoToClass");
|
|
343
315
|
function Pipeline(...decos) {
|
|
@@ -349,9 +321,9 @@ function Pipeline(...decos) {
|
|
|
349
321
|
__name(Pipeline, "Pipeline");
|
|
350
322
|
|
|
351
323
|
// src/decorators.ts
|
|
352
|
-
function Init(
|
|
353
|
-
|
|
354
|
-
regisHandler(
|
|
324
|
+
function Init(proto, key) {
|
|
325
|
+
setVar(proto, key);
|
|
326
|
+
regisHandler(proto, key, {
|
|
355
327
|
async init(instance) {
|
|
356
328
|
instance[key]();
|
|
357
329
|
}
|
|
@@ -359,45 +331,44 @@ function Init(target, key) {
|
|
|
359
331
|
}
|
|
360
332
|
__name(Init, "Init");
|
|
361
333
|
function Bind(value) {
|
|
362
|
-
return (
|
|
363
|
-
|
|
364
|
-
setState(
|
|
334
|
+
return (proto, k) => {
|
|
335
|
+
setVar(proto, k);
|
|
336
|
+
setState(proto, k, {
|
|
365
337
|
value
|
|
366
338
|
});
|
|
367
339
|
};
|
|
368
340
|
}
|
|
369
341
|
__name(Bind, "Bind");
|
|
370
|
-
function Ignore(
|
|
371
|
-
setIgnoreKey(
|
|
342
|
+
function Ignore(proto, key) {
|
|
343
|
+
setIgnoreKey(proto, key);
|
|
372
344
|
}
|
|
373
345
|
__name(Ignore, "Ignore");
|
|
374
|
-
function Clear(
|
|
375
|
-
init(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
target._namespace.__STATE_NAMESPACE__.delete(key);
|
|
346
|
+
function Clear(proto, key) {
|
|
347
|
+
init(proto);
|
|
348
|
+
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
349
|
+
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
350
|
+
proto._namespace.__STATE_VAR__.delete(key);
|
|
351
|
+
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
352
|
+
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
382
353
|
}
|
|
383
354
|
__name(Clear, "Clear");
|
|
384
355
|
function Err(cb) {
|
|
385
|
-
return (
|
|
386
|
-
|
|
387
|
-
regisHandler(
|
|
356
|
+
return (proto, key) => {
|
|
357
|
+
setVar(proto, key);
|
|
358
|
+
regisHandler(proto, key, {
|
|
388
359
|
error: cb
|
|
389
360
|
});
|
|
390
361
|
};
|
|
391
362
|
}
|
|
392
363
|
__name(Err, "Err");
|
|
393
|
-
function Expose(
|
|
394
|
-
setExposeKey(
|
|
364
|
+
function Expose(proto, key) {
|
|
365
|
+
setExposeKey(proto, key);
|
|
395
366
|
}
|
|
396
367
|
__name(Expose, "Expose");
|
|
397
368
|
function To(cb) {
|
|
398
|
-
return (
|
|
399
|
-
|
|
400
|
-
regisHandler(
|
|
369
|
+
return (proto, key) => {
|
|
370
|
+
setVar(proto, key);
|
|
371
|
+
regisHandler(proto, key, {
|
|
401
372
|
async pipe(instance) {
|
|
402
373
|
instance[key] = await cb(instance[key], instance, key);
|
|
403
374
|
}
|
|
@@ -406,17 +377,17 @@ function To(cb) {
|
|
|
406
377
|
}
|
|
407
378
|
__name(To, "To");
|
|
408
379
|
function Tag(tag) {
|
|
409
|
-
return (
|
|
410
|
-
init(
|
|
411
|
-
|
|
380
|
+
return (module2) => {
|
|
381
|
+
init(module2.prototype);
|
|
382
|
+
module2.prototype.__TAG__ = tag;
|
|
412
383
|
};
|
|
413
384
|
}
|
|
414
385
|
__name(Tag, "Tag");
|
|
415
386
|
function Assign(cb) {
|
|
416
|
-
return (
|
|
417
|
-
init(
|
|
418
|
-
|
|
419
|
-
regisHandler(
|
|
387
|
+
return (module2) => {
|
|
388
|
+
init(module2.prototype);
|
|
389
|
+
setVar(module2.prototype, SHARE_KEY);
|
|
390
|
+
regisHandler(module2.prototype, SHARE_KEY, {
|
|
420
391
|
init: async (instance) => {
|
|
421
392
|
const value = await cb(instance);
|
|
422
393
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -428,10 +399,10 @@ function Assign(cb) {
|
|
|
428
399
|
};
|
|
429
400
|
}
|
|
430
401
|
__name(Assign, "Assign");
|
|
431
|
-
function Global(
|
|
432
|
-
init(
|
|
433
|
-
|
|
434
|
-
regisHandler(
|
|
402
|
+
function Global(module2) {
|
|
403
|
+
init(module2.prototype);
|
|
404
|
+
setVar(module2.prototype, SHARE_KEY);
|
|
405
|
+
regisHandler(module2.prototype, SHARE_KEY, {
|
|
435
406
|
init: async (instance) => {
|
|
436
407
|
const tag = instance.__TAG__;
|
|
437
408
|
if (!tag)
|
|
@@ -443,8 +414,8 @@ function Global(target) {
|
|
|
443
414
|
});
|
|
444
415
|
}
|
|
445
416
|
__name(Global, "Global");
|
|
446
|
-
function Empty(
|
|
447
|
-
init(
|
|
417
|
+
function Empty(module2) {
|
|
418
|
+
init(module2.prototype);
|
|
448
419
|
}
|
|
449
420
|
__name(Empty, "Empty");
|
|
450
421
|
var DataMap = {};
|
|
@@ -461,9 +432,9 @@ function Inject(key) {
|
|
|
461
432
|
return DataMap[key] || EmptyProxy;
|
|
462
433
|
}
|
|
463
434
|
__name(Inject, "Inject");
|
|
464
|
-
function Nested(
|
|
435
|
+
function Nested(module2) {
|
|
465
436
|
return To(async (property) => {
|
|
466
|
-
const instance = plainToClass(
|
|
437
|
+
const instance = plainToClass(module2, property);
|
|
467
438
|
const err = await transformClass(instance);
|
|
468
439
|
if (err.length > 0)
|
|
469
440
|
throw new Error(err[0]);
|
|
@@ -472,7 +443,7 @@ function Nested(Model) {
|
|
|
472
443
|
}
|
|
473
444
|
__name(Nested, "Nested");
|
|
474
445
|
|
|
475
|
-
// src/
|
|
446
|
+
// src/custom/decorator.ts
|
|
476
447
|
var activeInstance = {};
|
|
477
448
|
function injectProperty(key, value) {
|
|
478
449
|
activeInstance[key] = value;
|
|
@@ -483,12 +454,10 @@ function getProperty(key) {
|
|
|
483
454
|
return activeInstance[key];
|
|
484
455
|
}
|
|
485
456
|
__name(getProperty, "getProperty");
|
|
486
|
-
|
|
487
|
-
// src/custom/decorator.ts
|
|
488
457
|
function Watcher(eventName, options) {
|
|
489
|
-
return (
|
|
490
|
-
|
|
491
|
-
regisHandler(
|
|
458
|
+
return (proto, key) => {
|
|
459
|
+
setVar(proto, key);
|
|
460
|
+
regisHandler(proto, key, {
|
|
492
461
|
init(instance) {
|
|
493
462
|
getProperty("watcher")?.({
|
|
494
463
|
eventName,
|
|
@@ -502,9 +471,9 @@ function Watcher(eventName, options) {
|
|
|
502
471
|
}
|
|
503
472
|
__name(Watcher, "Watcher");
|
|
504
473
|
function Effect(eventName, options) {
|
|
505
|
-
return (
|
|
506
|
-
|
|
507
|
-
regisHandler(
|
|
474
|
+
return (proto, key) => {
|
|
475
|
+
setVar(proto, key);
|
|
476
|
+
regisHandler(proto, key, {
|
|
508
477
|
init(instance) {
|
|
509
478
|
instance[`$_${key}`] = instance[key];
|
|
510
479
|
Object.defineProperty(instance, key, {
|
|
@@ -528,14 +497,14 @@ function Effect(eventName, options) {
|
|
|
528
497
|
}
|
|
529
498
|
__name(Effect, "Effect");
|
|
530
499
|
function Storage(storeKey) {
|
|
531
|
-
return (
|
|
500
|
+
return (proto, key) => {
|
|
532
501
|
let tag;
|
|
533
502
|
if (key) {
|
|
534
|
-
init(
|
|
535
|
-
tag = storeKey ||
|
|
503
|
+
init(proto);
|
|
504
|
+
tag = storeKey || proto.__TAG__;
|
|
536
505
|
const uniTag = Symbol(tag);
|
|
537
|
-
|
|
538
|
-
regisHandler(
|
|
506
|
+
setVar(proto, uniTag);
|
|
507
|
+
regisHandler(proto, uniTag, {
|
|
539
508
|
init: (instance) => {
|
|
540
509
|
getProperty("storage")?.({
|
|
541
510
|
instance,
|
|
@@ -545,11 +514,11 @@ function Storage(storeKey) {
|
|
|
545
514
|
}
|
|
546
515
|
});
|
|
547
516
|
} else {
|
|
548
|
-
init(
|
|
549
|
-
tag = storeKey || `${
|
|
517
|
+
init(proto.prototype);
|
|
518
|
+
tag = storeKey || `${proto.prototype.__TAG__}_${key}`;
|
|
550
519
|
const uniTag = Symbol(tag);
|
|
551
|
-
|
|
552
|
-
regisHandler(
|
|
520
|
+
setVar(proto.prototype, uniTag);
|
|
521
|
+
regisHandler(proto.prototype, uniTag, {
|
|
553
522
|
init: (instance) => {
|
|
554
523
|
getProperty("storage")?.({
|
|
555
524
|
instance,
|
|
@@ -579,6 +548,7 @@ __name(Storage, "Storage");
|
|
|
579
548
|
Nested,
|
|
580
549
|
Pipeline,
|
|
581
550
|
Provide,
|
|
551
|
+
SHARE_KEY,
|
|
582
552
|
Storage,
|
|
583
553
|
Tag,
|
|
584
554
|
To,
|
|
@@ -589,13 +559,11 @@ __name(Storage, "Storage");
|
|
|
589
559
|
getBind,
|
|
590
560
|
getExposeKey,
|
|
591
561
|
getHandler,
|
|
592
|
-
|
|
593
|
-
getModelState,
|
|
562
|
+
getModuleState,
|
|
594
563
|
getOwnExposeKey,
|
|
595
564
|
getOwnHandler,
|
|
596
565
|
getOwnIgnoreKey,
|
|
597
|
-
|
|
598
|
-
getOwnModelState,
|
|
566
|
+
getOwnModuleState,
|
|
599
567
|
getOwnState,
|
|
600
568
|
getProperty,
|
|
601
569
|
getState,
|
|
@@ -606,13 +574,12 @@ __name(Storage, "Storage");
|
|
|
606
574
|
isPhecda,
|
|
607
575
|
plainToClass,
|
|
608
576
|
regisHandler,
|
|
609
|
-
regisInitEvent,
|
|
610
577
|
register,
|
|
611
578
|
registerAsync,
|
|
612
579
|
setExposeKey,
|
|
613
580
|
setIgnoreKey,
|
|
614
|
-
setModelVar,
|
|
615
581
|
setState,
|
|
582
|
+
setVar,
|
|
616
583
|
snapShot,
|
|
617
584
|
transformClass
|
|
618
585
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,19 +2,18 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/core.ts
|
|
5
|
-
function isPhecda(
|
|
6
|
-
if (typeof
|
|
7
|
-
return !!
|
|
8
|
-
}
|
|
5
|
+
function isPhecda(module) {
|
|
6
|
+
if (typeof module === "function")
|
|
7
|
+
return !!module.prototype?._namespace;
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
11
10
|
__name(isPhecda, "isPhecda");
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var SHARE_KEY = Symbol("phecda-core");
|
|
12
|
+
function init(proto) {
|
|
13
|
+
if (!proto)
|
|
14
14
|
return;
|
|
15
|
-
if (!
|
|
16
|
-
|
|
17
|
-
__INIT_EVENT__: /* @__PURE__ */ new Set(),
|
|
15
|
+
if (!proto.hasOwnProperty("_namespace")) {
|
|
16
|
+
proto._namespace = {
|
|
18
17
|
__EXPOSE_VAR__: /* @__PURE__ */ new Set(),
|
|
19
18
|
__IGNORE_VAR__: /* @__PURE__ */ new Set(),
|
|
20
19
|
__STATE_VAR__: /* @__PURE__ */ new Set(),
|
|
@@ -24,56 +23,31 @@ function init(target) {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
__name(init, "init");
|
|
27
|
-
function
|
|
28
|
-
init(
|
|
29
|
-
|
|
26
|
+
function setVar(proto, key) {
|
|
27
|
+
init(proto);
|
|
28
|
+
proto._namespace.__STATE_VAR__.add(key);
|
|
29
|
+
setExposeKey(proto, key);
|
|
30
30
|
}
|
|
31
|
-
__name(
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return [
|
|
36
|
-
...target._namespace.__INIT_EVENT__
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
__name(getOwnInitEvent, "getOwnInitEvent");
|
|
40
|
-
function getInitEvent(target) {
|
|
41
|
-
let proto = Object.getPrototypeOf(target);
|
|
42
|
-
const set = /* @__PURE__ */ new Set();
|
|
43
|
-
while (proto?._namespace) {
|
|
44
|
-
proto._namespace.__INIT_EVENT__.forEach((item) => set.add(item));
|
|
45
|
-
proto = Object.getPrototypeOf(proto);
|
|
46
|
-
}
|
|
47
|
-
return [
|
|
48
|
-
...set
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
__name(getInitEvent, "getInitEvent");
|
|
52
|
-
function setModelVar(target, key) {
|
|
53
|
-
init(target);
|
|
54
|
-
target._namespace.__STATE_VAR__.add(key);
|
|
55
|
-
setExposeKey(target, key);
|
|
56
|
-
}
|
|
57
|
-
__name(setModelVar, "setModelVar");
|
|
58
|
-
function setExposeKey(target, key) {
|
|
59
|
-
init(target);
|
|
60
|
-
target._namespace.__EXPOSE_VAR__.add(key);
|
|
31
|
+
__name(setVar, "setVar");
|
|
32
|
+
function setExposeKey(proto, key) {
|
|
33
|
+
init(proto);
|
|
34
|
+
proto._namespace.__EXPOSE_VAR__.add(key);
|
|
61
35
|
}
|
|
62
36
|
__name(setExposeKey, "setExposeKey");
|
|
63
|
-
function setIgnoreKey(
|
|
64
|
-
init(
|
|
65
|
-
|
|
37
|
+
function setIgnoreKey(proto, key) {
|
|
38
|
+
init(proto);
|
|
39
|
+
proto._namespace.__IGNORE_VAR__.add(key);
|
|
66
40
|
}
|
|
67
41
|
__name(setIgnoreKey, "setIgnoreKey");
|
|
68
|
-
function
|
|
69
|
-
|
|
42
|
+
function getOwnModuleState(instance) {
|
|
43
|
+
instance = Object.getPrototypeOf(instance);
|
|
70
44
|
return [
|
|
71
|
-
...
|
|
45
|
+
...instance._namespace.__STATE_VAR__
|
|
72
46
|
];
|
|
73
47
|
}
|
|
74
|
-
__name(
|
|
75
|
-
function
|
|
76
|
-
let proto = Object.getPrototypeOf(
|
|
48
|
+
__name(getOwnModuleState, "getOwnModuleState");
|
|
49
|
+
function getModuleState(instance) {
|
|
50
|
+
let proto = Object.getPrototypeOf(instance);
|
|
77
51
|
const set = /* @__PURE__ */ new Set();
|
|
78
52
|
while (proto?._namespace) {
|
|
79
53
|
proto._namespace.__STATE_VAR__.forEach((item) => set.add(item));
|
|
@@ -83,16 +57,16 @@ function getModelState(target) {
|
|
|
83
57
|
...set
|
|
84
58
|
];
|
|
85
59
|
}
|
|
86
|
-
__name(
|
|
87
|
-
function getOwnExposeKey(
|
|
88
|
-
|
|
60
|
+
__name(getModuleState, "getModuleState");
|
|
61
|
+
function getOwnExposeKey(instance) {
|
|
62
|
+
instance = Object.getPrototypeOf(instance);
|
|
89
63
|
return [
|
|
90
|
-
...
|
|
91
|
-
].filter((item) => !
|
|
64
|
+
...instance._namespace.__EXPOSE_VAR__
|
|
65
|
+
].filter((item) => !instance._namespace.__IGNORE_VAR__.has(item));
|
|
92
66
|
}
|
|
93
67
|
__name(getOwnExposeKey, "getOwnExposeKey");
|
|
94
|
-
function getExposeKey(
|
|
95
|
-
let proto = Object.getPrototypeOf(
|
|
68
|
+
function getExposeKey(instance) {
|
|
69
|
+
let proto = Object.getPrototypeOf(instance);
|
|
96
70
|
const set = /* @__PURE__ */ new Set();
|
|
97
71
|
while (proto?._namespace) {
|
|
98
72
|
[
|
|
@@ -105,32 +79,32 @@ function getExposeKey(target) {
|
|
|
105
79
|
];
|
|
106
80
|
}
|
|
107
81
|
__name(getExposeKey, "getExposeKey");
|
|
108
|
-
function getOwnIgnoreKey(
|
|
109
|
-
if (!
|
|
82
|
+
function getOwnIgnoreKey(instance) {
|
|
83
|
+
if (!instance?._namespace)
|
|
110
84
|
return [];
|
|
111
85
|
return [
|
|
112
|
-
...
|
|
86
|
+
...instance._namespace.__IGNORE_VAR__
|
|
113
87
|
];
|
|
114
88
|
}
|
|
115
89
|
__name(getOwnIgnoreKey, "getOwnIgnoreKey");
|
|
116
|
-
function regisHandler(
|
|
117
|
-
init(
|
|
118
|
-
if (!
|
|
119
|
-
|
|
90
|
+
function regisHandler(proto, key, handler) {
|
|
91
|
+
init(proto);
|
|
92
|
+
if (!proto._namespace.__STATE_HANDLER__.has(key))
|
|
93
|
+
proto._namespace.__STATE_HANDLER__.set(key, [
|
|
120
94
|
handler
|
|
121
95
|
]);
|
|
122
96
|
else
|
|
123
|
-
|
|
97
|
+
proto._namespace.__STATE_HANDLER__.get(key).push(handler);
|
|
124
98
|
}
|
|
125
99
|
__name(regisHandler, "regisHandler");
|
|
126
|
-
function getOwnHandler(
|
|
127
|
-
if (!
|
|
100
|
+
function getOwnHandler(instance, key) {
|
|
101
|
+
if (!instance?._namespace)
|
|
128
102
|
return [];
|
|
129
|
-
return
|
|
103
|
+
return instance._namespace.__STATE_HANDLER__.get(key) || [];
|
|
130
104
|
}
|
|
131
105
|
__name(getOwnHandler, "getOwnHandler");
|
|
132
|
-
function getHandler(
|
|
133
|
-
let proto = Object.getPrototypeOf(
|
|
106
|
+
function getHandler(instance, key) {
|
|
107
|
+
let proto = Object.getPrototypeOf(instance);
|
|
134
108
|
const set = /* @__PURE__ */ new Set();
|
|
135
109
|
while (proto?._namespace) {
|
|
136
110
|
proto._namespace.__STATE_HANDLER__.get(key)?.forEach((item) => set.add(item));
|
|
@@ -141,19 +115,19 @@ function getHandler(target, key) {
|
|
|
141
115
|
];
|
|
142
116
|
}
|
|
143
117
|
__name(getHandler, "getHandler");
|
|
144
|
-
function setState(
|
|
145
|
-
init(
|
|
146
|
-
const namespace =
|
|
118
|
+
function setState(proto, key, state) {
|
|
119
|
+
init(proto);
|
|
120
|
+
const namespace = proto._namespace.__STATE_NAMESPACE__;
|
|
147
121
|
namespace.set(key, state);
|
|
148
122
|
}
|
|
149
123
|
__name(setState, "setState");
|
|
150
|
-
function getOwnState(
|
|
151
|
-
|
|
152
|
-
return
|
|
124
|
+
function getOwnState(instance, key) {
|
|
125
|
+
instance = Object.getPrototypeOf(instance);
|
|
126
|
+
return instance._namespace.__STATE_NAMESPACE__.get(key) || {};
|
|
153
127
|
}
|
|
154
128
|
__name(getOwnState, "getOwnState");
|
|
155
|
-
function getState(
|
|
156
|
-
let proto = Object.getPrototypeOf(
|
|
129
|
+
function getState(instance, key) {
|
|
130
|
+
let proto = Object.getPrototypeOf(instance);
|
|
157
131
|
let ret = {};
|
|
158
132
|
while (proto?._namespace) {
|
|
159
133
|
const state = proto._namespace.__STATE_NAMESPACE__.get(key);
|
|
@@ -187,18 +161,18 @@ async function registerAsync(instance) {
|
|
|
187
161
|
__name(registerAsync, "registerAsync");
|
|
188
162
|
|
|
189
163
|
// src/helper.ts
|
|
190
|
-
function getTag(
|
|
191
|
-
return
|
|
164
|
+
function getTag(module) {
|
|
165
|
+
return module.prototype?.__TAG__;
|
|
192
166
|
}
|
|
193
167
|
__name(getTag, "getTag");
|
|
194
168
|
function getSymbol(instance) {
|
|
195
|
-
const
|
|
196
|
-
return getTag(
|
|
169
|
+
const module = instance.constructor;
|
|
170
|
+
return getTag(module) || module.name;
|
|
197
171
|
}
|
|
198
172
|
__name(getSymbol, "getSymbol");
|
|
199
|
-
function getBind(
|
|
200
|
-
const instance = new
|
|
201
|
-
const keys =
|
|
173
|
+
function getBind(module) {
|
|
174
|
+
const instance = new module();
|
|
175
|
+
const keys = getModuleState(instance);
|
|
202
176
|
const ret = {};
|
|
203
177
|
for (const item of keys) {
|
|
204
178
|
const state = getState(instance, item);
|
|
@@ -208,8 +182,8 @@ function getBind(Model) {
|
|
|
208
182
|
return ret;
|
|
209
183
|
}
|
|
210
184
|
__name(getBind, "getBind");
|
|
211
|
-
function plainToClass(
|
|
212
|
-
const instance = new
|
|
185
|
+
function plainToClass(module, input) {
|
|
186
|
+
const instance = new module();
|
|
213
187
|
const keys = getExposeKey(instance);
|
|
214
188
|
for (const item of keys)
|
|
215
189
|
instance[item] = input[item];
|
|
@@ -218,7 +192,7 @@ function plainToClass(Model, input) {
|
|
|
218
192
|
__name(plainToClass, "plainToClass");
|
|
219
193
|
async function transformClass(instance, force = false) {
|
|
220
194
|
const err = [];
|
|
221
|
-
const stateVars =
|
|
195
|
+
const stateVars = getModuleState(instance);
|
|
222
196
|
for (const item of stateVars) {
|
|
223
197
|
const handlers = getHandler(instance, item);
|
|
224
198
|
if (handlers) {
|
|
@@ -262,8 +236,8 @@ function snapShot(data) {
|
|
|
262
236
|
};
|
|
263
237
|
}
|
|
264
238
|
__name(snapShot, "snapShot");
|
|
265
|
-
function addDecoToClass(c, key, handler, type = "
|
|
266
|
-
handler(type === "
|
|
239
|
+
function addDecoToClass(c, key, handler, type = "class") {
|
|
240
|
+
handler(type === "class" ? c.prototype : c, key);
|
|
267
241
|
}
|
|
268
242
|
__name(addDecoToClass, "addDecoToClass");
|
|
269
243
|
function Pipeline(...decos) {
|
|
@@ -275,9 +249,9 @@ function Pipeline(...decos) {
|
|
|
275
249
|
__name(Pipeline, "Pipeline");
|
|
276
250
|
|
|
277
251
|
// src/decorators.ts
|
|
278
|
-
function Init(
|
|
279
|
-
|
|
280
|
-
regisHandler(
|
|
252
|
+
function Init(proto, key) {
|
|
253
|
+
setVar(proto, key);
|
|
254
|
+
regisHandler(proto, key, {
|
|
281
255
|
async init(instance) {
|
|
282
256
|
instance[key]();
|
|
283
257
|
}
|
|
@@ -285,45 +259,44 @@ function Init(target, key) {
|
|
|
285
259
|
}
|
|
286
260
|
__name(Init, "Init");
|
|
287
261
|
function Bind(value) {
|
|
288
|
-
return (
|
|
289
|
-
|
|
290
|
-
setState(
|
|
262
|
+
return (proto, k) => {
|
|
263
|
+
setVar(proto, k);
|
|
264
|
+
setState(proto, k, {
|
|
291
265
|
value
|
|
292
266
|
});
|
|
293
267
|
};
|
|
294
268
|
}
|
|
295
269
|
__name(Bind, "Bind");
|
|
296
|
-
function Ignore(
|
|
297
|
-
setIgnoreKey(
|
|
270
|
+
function Ignore(proto, key) {
|
|
271
|
+
setIgnoreKey(proto, key);
|
|
298
272
|
}
|
|
299
273
|
__name(Ignore, "Ignore");
|
|
300
|
-
function Clear(
|
|
301
|
-
init(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
target._namespace.__STATE_NAMESPACE__.delete(key);
|
|
274
|
+
function Clear(proto, key) {
|
|
275
|
+
init(proto);
|
|
276
|
+
proto._namespace.__EXPOSE_VAR__.delete(key);
|
|
277
|
+
proto._namespace.__IGNORE_VAR__.delete(key);
|
|
278
|
+
proto._namespace.__STATE_VAR__.delete(key);
|
|
279
|
+
proto._namespace.__STATE_HANDLER__.delete(key);
|
|
280
|
+
proto._namespace.__STATE_NAMESPACE__.delete(key);
|
|
308
281
|
}
|
|
309
282
|
__name(Clear, "Clear");
|
|
310
283
|
function Err(cb) {
|
|
311
|
-
return (
|
|
312
|
-
|
|
313
|
-
regisHandler(
|
|
284
|
+
return (proto, key) => {
|
|
285
|
+
setVar(proto, key);
|
|
286
|
+
regisHandler(proto, key, {
|
|
314
287
|
error: cb
|
|
315
288
|
});
|
|
316
289
|
};
|
|
317
290
|
}
|
|
318
291
|
__name(Err, "Err");
|
|
319
|
-
function Expose(
|
|
320
|
-
setExposeKey(
|
|
292
|
+
function Expose(proto, key) {
|
|
293
|
+
setExposeKey(proto, key);
|
|
321
294
|
}
|
|
322
295
|
__name(Expose, "Expose");
|
|
323
296
|
function To(cb) {
|
|
324
|
-
return (
|
|
325
|
-
|
|
326
|
-
regisHandler(
|
|
297
|
+
return (proto, key) => {
|
|
298
|
+
setVar(proto, key);
|
|
299
|
+
regisHandler(proto, key, {
|
|
327
300
|
async pipe(instance) {
|
|
328
301
|
instance[key] = await cb(instance[key], instance, key);
|
|
329
302
|
}
|
|
@@ -332,17 +305,17 @@ function To(cb) {
|
|
|
332
305
|
}
|
|
333
306
|
__name(To, "To");
|
|
334
307
|
function Tag(tag) {
|
|
335
|
-
return (
|
|
336
|
-
init(
|
|
337
|
-
|
|
308
|
+
return (module) => {
|
|
309
|
+
init(module.prototype);
|
|
310
|
+
module.prototype.__TAG__ = tag;
|
|
338
311
|
};
|
|
339
312
|
}
|
|
340
313
|
__name(Tag, "Tag");
|
|
341
314
|
function Assign(cb) {
|
|
342
|
-
return (
|
|
343
|
-
init(
|
|
344
|
-
|
|
345
|
-
regisHandler(
|
|
315
|
+
return (module) => {
|
|
316
|
+
init(module.prototype);
|
|
317
|
+
setVar(module.prototype, SHARE_KEY);
|
|
318
|
+
regisHandler(module.prototype, SHARE_KEY, {
|
|
346
319
|
init: async (instance) => {
|
|
347
320
|
const value = await cb(instance);
|
|
348
321
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -354,10 +327,10 @@ function Assign(cb) {
|
|
|
354
327
|
};
|
|
355
328
|
}
|
|
356
329
|
__name(Assign, "Assign");
|
|
357
|
-
function Global(
|
|
358
|
-
init(
|
|
359
|
-
|
|
360
|
-
regisHandler(
|
|
330
|
+
function Global(module) {
|
|
331
|
+
init(module.prototype);
|
|
332
|
+
setVar(module.prototype, SHARE_KEY);
|
|
333
|
+
regisHandler(module.prototype, SHARE_KEY, {
|
|
361
334
|
init: async (instance) => {
|
|
362
335
|
const tag = instance.__TAG__;
|
|
363
336
|
if (!tag)
|
|
@@ -369,8 +342,8 @@ function Global(target) {
|
|
|
369
342
|
});
|
|
370
343
|
}
|
|
371
344
|
__name(Global, "Global");
|
|
372
|
-
function Empty(
|
|
373
|
-
init(
|
|
345
|
+
function Empty(module) {
|
|
346
|
+
init(module.prototype);
|
|
374
347
|
}
|
|
375
348
|
__name(Empty, "Empty");
|
|
376
349
|
var DataMap = {};
|
|
@@ -387,9 +360,9 @@ function Inject(key) {
|
|
|
387
360
|
return DataMap[key] || EmptyProxy;
|
|
388
361
|
}
|
|
389
362
|
__name(Inject, "Inject");
|
|
390
|
-
function Nested(
|
|
363
|
+
function Nested(module) {
|
|
391
364
|
return To(async (property) => {
|
|
392
|
-
const instance = plainToClass(
|
|
365
|
+
const instance = plainToClass(module, property);
|
|
393
366
|
const err = await transformClass(instance);
|
|
394
367
|
if (err.length > 0)
|
|
395
368
|
throw new Error(err[0]);
|
|
@@ -398,7 +371,7 @@ function Nested(Model) {
|
|
|
398
371
|
}
|
|
399
372
|
__name(Nested, "Nested");
|
|
400
373
|
|
|
401
|
-
// src/
|
|
374
|
+
// src/custom/decorator.ts
|
|
402
375
|
var activeInstance = {};
|
|
403
376
|
function injectProperty(key, value) {
|
|
404
377
|
activeInstance[key] = value;
|
|
@@ -409,12 +382,10 @@ function getProperty(key) {
|
|
|
409
382
|
return activeInstance[key];
|
|
410
383
|
}
|
|
411
384
|
__name(getProperty, "getProperty");
|
|
412
|
-
|
|
413
|
-
// src/custom/decorator.ts
|
|
414
385
|
function Watcher(eventName, options) {
|
|
415
|
-
return (
|
|
416
|
-
|
|
417
|
-
regisHandler(
|
|
386
|
+
return (proto, key) => {
|
|
387
|
+
setVar(proto, key);
|
|
388
|
+
regisHandler(proto, key, {
|
|
418
389
|
init(instance) {
|
|
419
390
|
getProperty("watcher")?.({
|
|
420
391
|
eventName,
|
|
@@ -428,9 +399,9 @@ function Watcher(eventName, options) {
|
|
|
428
399
|
}
|
|
429
400
|
__name(Watcher, "Watcher");
|
|
430
401
|
function Effect(eventName, options) {
|
|
431
|
-
return (
|
|
432
|
-
|
|
433
|
-
regisHandler(
|
|
402
|
+
return (proto, key) => {
|
|
403
|
+
setVar(proto, key);
|
|
404
|
+
regisHandler(proto, key, {
|
|
434
405
|
init(instance) {
|
|
435
406
|
instance[`$_${key}`] = instance[key];
|
|
436
407
|
Object.defineProperty(instance, key, {
|
|
@@ -454,14 +425,14 @@ function Effect(eventName, options) {
|
|
|
454
425
|
}
|
|
455
426
|
__name(Effect, "Effect");
|
|
456
427
|
function Storage(storeKey) {
|
|
457
|
-
return (
|
|
428
|
+
return (proto, key) => {
|
|
458
429
|
let tag;
|
|
459
430
|
if (key) {
|
|
460
|
-
init(
|
|
461
|
-
tag = storeKey ||
|
|
431
|
+
init(proto);
|
|
432
|
+
tag = storeKey || proto.__TAG__;
|
|
462
433
|
const uniTag = Symbol(tag);
|
|
463
|
-
|
|
464
|
-
regisHandler(
|
|
434
|
+
setVar(proto, uniTag);
|
|
435
|
+
regisHandler(proto, uniTag, {
|
|
465
436
|
init: (instance) => {
|
|
466
437
|
getProperty("storage")?.({
|
|
467
438
|
instance,
|
|
@@ -471,11 +442,11 @@ function Storage(storeKey) {
|
|
|
471
442
|
}
|
|
472
443
|
});
|
|
473
444
|
} else {
|
|
474
|
-
init(
|
|
475
|
-
tag = storeKey || `${
|
|
445
|
+
init(proto.prototype);
|
|
446
|
+
tag = storeKey || `${proto.prototype.__TAG__}_${key}`;
|
|
476
447
|
const uniTag = Symbol(tag);
|
|
477
|
-
|
|
478
|
-
regisHandler(
|
|
448
|
+
setVar(proto.prototype, uniTag);
|
|
449
|
+
regisHandler(proto.prototype, uniTag, {
|
|
479
450
|
init: (instance) => {
|
|
480
451
|
getProperty("storage")?.({
|
|
481
452
|
instance,
|
|
@@ -504,6 +475,7 @@ export {
|
|
|
504
475
|
Nested,
|
|
505
476
|
Pipeline,
|
|
506
477
|
Provide,
|
|
478
|
+
SHARE_KEY,
|
|
507
479
|
Storage,
|
|
508
480
|
Tag,
|
|
509
481
|
To,
|
|
@@ -514,13 +486,11 @@ export {
|
|
|
514
486
|
getBind,
|
|
515
487
|
getExposeKey,
|
|
516
488
|
getHandler,
|
|
517
|
-
|
|
518
|
-
getModelState,
|
|
489
|
+
getModuleState,
|
|
519
490
|
getOwnExposeKey,
|
|
520
491
|
getOwnHandler,
|
|
521
492
|
getOwnIgnoreKey,
|
|
522
|
-
|
|
523
|
-
getOwnModelState,
|
|
493
|
+
getOwnModuleState,
|
|
524
494
|
getOwnState,
|
|
525
495
|
getProperty,
|
|
526
496
|
getState,
|
|
@@ -531,13 +501,12 @@ export {
|
|
|
531
501
|
isPhecda,
|
|
532
502
|
plainToClass,
|
|
533
503
|
regisHandler,
|
|
534
|
-
regisInitEvent,
|
|
535
504
|
register,
|
|
536
505
|
registerAsync,
|
|
537
506
|
setExposeKey,
|
|
538
507
|
setIgnoreKey,
|
|
539
|
-
setModelVar,
|
|
540
508
|
setState,
|
|
509
|
+
setVar,
|
|
541
510
|
snapShot,
|
|
542
511
|
transformClass
|
|
543
512
|
};
|