phecda-vue 3.0.0-alpha.8 → 3.0.0-beta.16
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 +17 -17
- package/dist/index.js +64 -90
- package/dist/index.mjs +57 -87
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue from 'vue';
|
|
2
2
|
import { Ref, App, UnwrapNestedRefs } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { Construct, Events } from 'phecda-web';
|
|
4
4
|
export * from 'phecda-web';
|
|
5
5
|
|
|
6
|
+
declare const RawSymbol: unique symbol;
|
|
7
|
+
type Raw<T> = T & {
|
|
8
|
+
[RawSymbol]: true;
|
|
9
|
+
};
|
|
6
10
|
type ReplaceInstanceValues<I> = {
|
|
7
|
-
[P in keyof I]: I[P] extends (...args: any[]) => any ? I[P] : Ref<I[P]>;
|
|
11
|
+
[P in keyof I]: I[P] extends (...args: any[]) => any ? I[P] : I[P] extends Raw<infer O> ? O : Ref<I[P]>;
|
|
8
12
|
};
|
|
9
13
|
type SchemaToObj<S> = {
|
|
10
14
|
[P in keyof S]: S[P] extends object ? SchemaToObj<S[P]> : (S[P] extends string ? any : S[P]);
|
|
@@ -18,7 +22,7 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
|
|
|
18
22
|
errorHandler?: (error?: Error, errorPath?: string) => any;
|
|
19
23
|
}): {
|
|
20
24
|
filter: <Schema>(obj: Schema) => SchemaToObj<Schema>;
|
|
21
|
-
data: [Data] extends [
|
|
25
|
+
data: [Data] extends [vue.Ref<any>] ? Data : vue.Ref<vue.UnwrapRef<Data>>;
|
|
22
26
|
init: (params?: Data) => void;
|
|
23
27
|
setState: <Key extends string>(key: Key, value: Data[Key]) => void;
|
|
24
28
|
storeState: (key: string, params?: Data) => void;
|
|
@@ -31,26 +35,20 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
|
|
|
31
35
|
delState: (key: string) => void;
|
|
32
36
|
};
|
|
33
37
|
|
|
34
|
-
declare class PV {
|
|
35
|
-
constructor();
|
|
36
|
-
get tag(): any;
|
|
37
|
-
on<Key extends keyof Events>(type: Key, handler: (arg: Events[Key]) => void): void;
|
|
38
|
-
emit<Key extends keyof Events>(type: Key, param: Events[Key]): void;
|
|
39
|
-
off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
38
|
declare const phecdaSymbol: unique symbol;
|
|
43
|
-
declare function createPhecda():
|
|
44
|
-
plugins: Plugin[];
|
|
39
|
+
declare function createPhecda(): vue.Raw<{
|
|
45
40
|
install(app: App): void;
|
|
46
|
-
use(...plugins: Plugin[]): any;
|
|
47
41
|
load(state: any): any;
|
|
48
|
-
unmount(): void
|
|
42
|
+
unmount(): Promise<void>;
|
|
49
43
|
}>;
|
|
50
44
|
|
|
51
45
|
type DeepPartial<T> = {
|
|
52
46
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
53
47
|
};
|
|
48
|
+
declare function markRaw<T extends object>(value: T): Raw<T>;
|
|
49
|
+
declare function isObject(o: any): boolean;
|
|
50
|
+
declare function mergeReactiveObjects<T extends Record<any, unknown> | Map<unknown, unknown> | Set<unknown>>(target: T, patchToApply: DeepPartial<T>): T;
|
|
51
|
+
declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
|
|
54
52
|
|
|
55
53
|
declare function useO<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
56
54
|
declare function useRaw<T extends Construct>(module: T): InstanceType<T>;
|
|
@@ -63,4 +61,6 @@ declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event:
|
|
|
63
61
|
};
|
|
64
62
|
declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
declare function Shallow(module: any): void;
|
|
65
|
+
|
|
66
|
+
export { DeepPartial, RE, Raw, RawSymbol, ReplaceInstanceValues, SchemaToObj, Shallow, createFilter, createPhecda, createSharedReactive, initialize, isObject, markRaw, mergeReactiveObjects, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
|
package/dist/index.js
CHANGED
|
@@ -22,11 +22,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
var src_exports = {};
|
|
24
24
|
__export(src_exports, {
|
|
25
|
-
PV: () => PV,
|
|
26
25
|
RE: () => RE,
|
|
26
|
+
Shallow: () => Shallow,
|
|
27
27
|
createFilter: () => createFilter,
|
|
28
28
|
createPhecda: () => createPhecda,
|
|
29
|
+
createSharedReactive: () => createSharedReactive,
|
|
29
30
|
initialize: () => initialize,
|
|
31
|
+
isObject: () => isObject,
|
|
32
|
+
markRaw: () => markRaw2,
|
|
33
|
+
mergeReactiveObjects: () => mergeReactiveObjects,
|
|
30
34
|
phecdaSymbol: () => phecdaSymbol,
|
|
31
35
|
useEvent: () => useEvent,
|
|
32
36
|
useO: () => useO,
|
|
@@ -135,53 +139,28 @@ __name(createFilter, "createFilter");
|
|
|
135
139
|
// src/index.ts
|
|
136
140
|
__reExport(src_exports, require("phecda-web"), module.exports);
|
|
137
141
|
|
|
138
|
-
// src/wrapper.ts
|
|
139
|
-
var import_phecda_web = require("phecda-web");
|
|
140
|
-
var PV = class {
|
|
141
|
-
constructor() {
|
|
142
|
-
}
|
|
143
|
-
get tag() {
|
|
144
|
-
return this.__TAG__;
|
|
145
|
-
}
|
|
146
|
-
on(type, handler) {
|
|
147
|
-
import_phecda_web.emitter.on(type, handler);
|
|
148
|
-
}
|
|
149
|
-
emit(type, param) {
|
|
150
|
-
import_phecda_web.emitter.emit(type, param);
|
|
151
|
-
}
|
|
152
|
-
off(type, handler) {
|
|
153
|
-
import_phecda_web.emitter.off(type, handler);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
__name(PV, "PV");
|
|
157
|
-
|
|
158
142
|
// src/phecda.ts
|
|
159
143
|
var import_vue2 = require("vue");
|
|
160
|
-
var
|
|
144
|
+
var import_phecda_web = require("phecda-web");
|
|
161
145
|
var phecdaSymbol = Symbol("phecda");
|
|
162
146
|
function createPhecda() {
|
|
163
|
-
(0,
|
|
147
|
+
(0, import_phecda_web.resetActiveInstance)();
|
|
164
148
|
const phecda = (0, import_vue2.markRaw)({
|
|
165
|
-
plugins: [],
|
|
166
149
|
install(app) {
|
|
167
|
-
const instance = (0,
|
|
150
|
+
const instance = (0, import_phecda_web.getActiveInstance)();
|
|
168
151
|
instance.app = app;
|
|
169
152
|
app.provide(phecdaSymbol, instance);
|
|
170
153
|
app.config.globalProperties.$phecda = instance;
|
|
171
|
-
this.plugins.forEach((p) => p.setup(instance));
|
|
172
|
-
},
|
|
173
|
-
use(...plugins) {
|
|
174
|
-
plugins.forEach((p) => this.plugins.push(p));
|
|
175
|
-
return this;
|
|
176
154
|
},
|
|
177
155
|
load(state) {
|
|
178
|
-
const instance = (0,
|
|
156
|
+
const instance = (0, import_phecda_web.getActiveInstance)();
|
|
179
157
|
instance.state = state;
|
|
180
158
|
return this;
|
|
181
159
|
},
|
|
182
|
-
unmount() {
|
|
183
|
-
const
|
|
184
|
-
|
|
160
|
+
async unmount() {
|
|
161
|
+
const { state } = (0, import_phecda_web.getActiveInstance)();
|
|
162
|
+
await Object.values(state).map((ins) => (0, import_phecda_web.invokeHandler)("unmount", ins));
|
|
163
|
+
(0, import_phecda_web.resetActiveInstance)();
|
|
185
164
|
}
|
|
186
165
|
});
|
|
187
166
|
return phecda;
|
|
@@ -190,10 +169,14 @@ __name(createPhecda, "createPhecda");
|
|
|
190
169
|
|
|
191
170
|
// src/composable.ts
|
|
192
171
|
var import_vue4 = require("vue");
|
|
193
|
-
var
|
|
172
|
+
var import_phecda_web2 = require("phecda-web");
|
|
194
173
|
|
|
195
174
|
// src/utils.ts
|
|
196
175
|
var import_vue3 = require("vue");
|
|
176
|
+
function markRaw2(value) {
|
|
177
|
+
return (0, import_vue3.markRaw)(value);
|
|
178
|
+
}
|
|
179
|
+
__name(markRaw2, "markRaw");
|
|
197
180
|
function isObject(o) {
|
|
198
181
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
199
182
|
}
|
|
@@ -223,7 +206,7 @@ function createSharedReactive(composable) {
|
|
|
223
206
|
state = scope = null;
|
|
224
207
|
}
|
|
225
208
|
}, "dispose");
|
|
226
|
-
|
|
209
|
+
const cb = /* @__PURE__ */ __name(() => {
|
|
227
210
|
subscribers++;
|
|
228
211
|
if (!state) {
|
|
229
212
|
scope = (0, import_vue3.effectScope)(true);
|
|
@@ -231,23 +214,28 @@ function createSharedReactive(composable) {
|
|
|
231
214
|
}
|
|
232
215
|
(0, import_vue3.onScopeDispose)(dispose);
|
|
233
216
|
return state;
|
|
234
|
-
};
|
|
217
|
+
}, "cb");
|
|
218
|
+
cb.r = true;
|
|
219
|
+
return cb;
|
|
235
220
|
}
|
|
236
221
|
__name(createSharedReactive, "createSharedReactive");
|
|
237
222
|
|
|
238
223
|
// src/composable.ts
|
|
224
|
+
var REF_SYMBOL = Symbol("ref");
|
|
239
225
|
function useO(module2) {
|
|
240
|
-
const { state } = (0,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
instance
|
|
226
|
+
const { state, origin } = (0, import_phecda_web2.getActiveInstance)();
|
|
227
|
+
const proxyFn = (0, import_phecda_web2.get)(module2.prototype, "shallow") ? import_vue4.shallowReactive : import_vue4.reactive;
|
|
228
|
+
if ((0, import_phecda_web2.get)(module2.prototype, "isolate")) {
|
|
229
|
+
const instance = proxyFn(new module2());
|
|
230
|
+
instance._promise = (0, import_phecda_web2.invokeHandler)("init", instance);
|
|
244
231
|
return instance;
|
|
245
232
|
}
|
|
246
|
-
const tag = (0,
|
|
233
|
+
const tag = (0, import_phecda_web2.getTag)(module2);
|
|
247
234
|
if (!(tag in state)) {
|
|
248
|
-
const instance = (
|
|
249
|
-
instance._promise = (0,
|
|
235
|
+
const instance = proxyFn(new module2());
|
|
236
|
+
instance._promise = (0, import_phecda_web2.invokeHandler)("init", instance);
|
|
250
237
|
state[tag] = instance;
|
|
238
|
+
origin.set(instance, module2);
|
|
251
239
|
}
|
|
252
240
|
return state[tag];
|
|
253
241
|
}
|
|
@@ -262,54 +250,27 @@ function usePatch(module2, Data) {
|
|
|
262
250
|
}
|
|
263
251
|
__name(usePatch, "usePatch");
|
|
264
252
|
function useR(module2) {
|
|
265
|
-
|
|
266
|
-
const instance = useO(module2);
|
|
267
|
-
if (rmap.has(instance))
|
|
268
|
-
return rmap.get(instance);
|
|
269
|
-
const proxy = new Proxy(instance, {
|
|
270
|
-
get(target, key) {
|
|
271
|
-
if (typeof target[key] === "function") {
|
|
272
|
-
if (fmap.has(target[key]))
|
|
273
|
-
return fmap.get(target[key]);
|
|
274
|
-
const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
|
|
275
|
-
if (!errorHandler)
|
|
276
|
-
return target[key].bind(target);
|
|
277
|
-
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
278
|
-
fmap.set(target[key], wrapper);
|
|
279
|
-
return wrapper;
|
|
280
|
-
}
|
|
281
|
-
return target[key];
|
|
282
|
-
},
|
|
283
|
-
set(target, key, v) {
|
|
284
|
-
target[key] = v;
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
rmap.set(instance, proxy);
|
|
289
|
-
return proxy;
|
|
253
|
+
return useO(module2);
|
|
290
254
|
}
|
|
291
255
|
__name(useR, "useR");
|
|
292
256
|
function useV(module2) {
|
|
293
|
-
const {
|
|
257
|
+
const { cache: cacheMap } = (0, import_phecda_web2.getActiveInstance)();
|
|
294
258
|
const instance = useO(module2);
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
259
|
+
const cache = cacheMap.get(instance) || {};
|
|
260
|
+
if (cache[REF_SYMBOL])
|
|
261
|
+
return cache[REF_SYMBOL];
|
|
298
262
|
const proxy = new Proxy(instance, {
|
|
299
263
|
get(target, key) {
|
|
300
264
|
if (typeof target[key] === "function") {
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (!errorHandler)
|
|
305
|
-
return target[key].bind(target);
|
|
306
|
-
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
307
|
-
fmap.set(target[key], wrapper);
|
|
308
|
-
return wrapper;
|
|
265
|
+
if (!cache[key])
|
|
266
|
+
cache[key] = target[key].bind(this);
|
|
267
|
+
return cache[key];
|
|
309
268
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
269
|
+
if (target[key]?.__v_skip)
|
|
270
|
+
return target[key];
|
|
271
|
+
const cacheRef = cache[key];
|
|
272
|
+
if (cacheRef && cacheRef.r)
|
|
273
|
+
return cacheRef();
|
|
313
274
|
cache[key] = createSharedReactive(() => {
|
|
314
275
|
return (0, import_vue4.toRef)(target, key);
|
|
315
276
|
});
|
|
@@ -319,18 +280,20 @@ function useV(module2) {
|
|
|
319
280
|
return false;
|
|
320
281
|
}
|
|
321
282
|
});
|
|
322
|
-
|
|
283
|
+
cache[REF_SYMBOL] = proxy;
|
|
284
|
+
if (!cacheMap.has(instance))
|
|
285
|
+
cacheMap.set(instance, cache);
|
|
323
286
|
return proxy;
|
|
324
287
|
}
|
|
325
288
|
__name(useV, "useV");
|
|
326
289
|
function useEvent(eventName, cb) {
|
|
327
290
|
(0, import_vue4.onBeforeUnmount)(() => {
|
|
328
|
-
|
|
291
|
+
import_phecda_web2.emitter.off(eventName, cb);
|
|
329
292
|
});
|
|
330
|
-
|
|
293
|
+
import_phecda_web2.emitter.on(eventName, cb);
|
|
331
294
|
return {
|
|
332
|
-
emit: (arg) =>
|
|
333
|
-
cancel: () =>
|
|
295
|
+
emit: (arg) => import_phecda_web2.emitter.emit(eventName, arg),
|
|
296
|
+
cancel: () => import_phecda_web2.emitter.off(eventName, cb)
|
|
334
297
|
};
|
|
335
298
|
}
|
|
336
299
|
__name(useEvent, "useEvent");
|
|
@@ -346,13 +309,24 @@ function initialize(module2, deleteOtherProperty = true) {
|
|
|
346
309
|
}
|
|
347
310
|
}
|
|
348
311
|
__name(initialize, "initialize");
|
|
312
|
+
|
|
313
|
+
// src/decorator.ts
|
|
314
|
+
var import_phecda_web3 = require("phecda-web");
|
|
315
|
+
function Shallow(module2) {
|
|
316
|
+
(0, import_phecda_web3.set)(module2.prototype, "shallow", true);
|
|
317
|
+
}
|
|
318
|
+
__name(Shallow, "Shallow");
|
|
349
319
|
// Annotate the CommonJS export names for ESM import in node:
|
|
350
320
|
0 && (module.exports = {
|
|
351
|
-
PV,
|
|
352
321
|
RE,
|
|
322
|
+
Shallow,
|
|
353
323
|
createFilter,
|
|
354
324
|
createPhecda,
|
|
325
|
+
createSharedReactive,
|
|
355
326
|
initialize,
|
|
327
|
+
isObject,
|
|
328
|
+
markRaw,
|
|
329
|
+
mergeReactiveObjects,
|
|
356
330
|
phecdaSymbol,
|
|
357
331
|
useEvent,
|
|
358
332
|
useO,
|
package/dist/index.mjs
CHANGED
|
@@ -99,53 +99,28 @@ __name(createFilter, "createFilter");
|
|
|
99
99
|
// src/index.ts
|
|
100
100
|
export * from "phecda-web";
|
|
101
101
|
|
|
102
|
-
// src/wrapper.ts
|
|
103
|
-
import { emitter } from "phecda-web";
|
|
104
|
-
var PV = class {
|
|
105
|
-
constructor() {
|
|
106
|
-
}
|
|
107
|
-
get tag() {
|
|
108
|
-
return this.__TAG__;
|
|
109
|
-
}
|
|
110
|
-
on(type, handler) {
|
|
111
|
-
emitter.on(type, handler);
|
|
112
|
-
}
|
|
113
|
-
emit(type, param) {
|
|
114
|
-
emitter.emit(type, param);
|
|
115
|
-
}
|
|
116
|
-
off(type, handler) {
|
|
117
|
-
emitter.off(type, handler);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
__name(PV, "PV");
|
|
121
|
-
|
|
122
102
|
// src/phecda.ts
|
|
123
103
|
import { markRaw } from "vue";
|
|
124
|
-
import { getActiveInstance, resetActiveInstance } from "phecda-web";
|
|
104
|
+
import { getActiveInstance, invokeHandler, resetActiveInstance } from "phecda-web";
|
|
125
105
|
var phecdaSymbol = Symbol("phecda");
|
|
126
106
|
function createPhecda() {
|
|
127
107
|
resetActiveInstance();
|
|
128
108
|
const phecda = markRaw({
|
|
129
|
-
plugins: [],
|
|
130
109
|
install(app) {
|
|
131
110
|
const instance = getActiveInstance();
|
|
132
111
|
instance.app = app;
|
|
133
112
|
app.provide(phecdaSymbol, instance);
|
|
134
113
|
app.config.globalProperties.$phecda = instance;
|
|
135
|
-
this.plugins.forEach((p) => p.setup(instance));
|
|
136
|
-
},
|
|
137
|
-
use(...plugins) {
|
|
138
|
-
plugins.forEach((p) => this.plugins.push(p));
|
|
139
|
-
return this;
|
|
140
114
|
},
|
|
141
115
|
load(state) {
|
|
142
116
|
const instance = getActiveInstance();
|
|
143
117
|
instance.state = state;
|
|
144
118
|
return this;
|
|
145
119
|
},
|
|
146
|
-
unmount() {
|
|
147
|
-
const
|
|
148
|
-
|
|
120
|
+
async unmount() {
|
|
121
|
+
const { state } = getActiveInstance();
|
|
122
|
+
await Object.values(state).map((ins) => invokeHandler("unmount", ins));
|
|
123
|
+
resetActiveInstance();
|
|
149
124
|
}
|
|
150
125
|
});
|
|
151
126
|
return phecda;
|
|
@@ -153,11 +128,15 @@ function createPhecda() {
|
|
|
153
128
|
__name(createPhecda, "createPhecda");
|
|
154
129
|
|
|
155
130
|
// src/composable.ts
|
|
156
|
-
import { onBeforeUnmount, reactive, toRaw, toRef } from "vue";
|
|
157
|
-
import { emitter
|
|
131
|
+
import { onBeforeUnmount, reactive, shallowReactive, toRaw, toRef } from "vue";
|
|
132
|
+
import { emitter, get, getActiveInstance as getActiveInstance2, getTag, invokeHandler as invokeHandler2 } from "phecda-web";
|
|
158
133
|
|
|
159
134
|
// src/utils.ts
|
|
160
|
-
import { effectScope as effectScope2, isReactive, isRef, onScopeDispose } from "vue";
|
|
135
|
+
import { effectScope as effectScope2, isReactive, isRef, onScopeDispose, markRaw as raw } from "vue";
|
|
136
|
+
function markRaw2(value) {
|
|
137
|
+
return raw(value);
|
|
138
|
+
}
|
|
139
|
+
__name(markRaw2, "markRaw");
|
|
161
140
|
function isObject(o) {
|
|
162
141
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
163
142
|
}
|
|
@@ -187,7 +166,7 @@ function createSharedReactive(composable) {
|
|
|
187
166
|
state = scope = null;
|
|
188
167
|
}
|
|
189
168
|
}, "dispose");
|
|
190
|
-
|
|
169
|
+
const cb = /* @__PURE__ */ __name(() => {
|
|
191
170
|
subscribers++;
|
|
192
171
|
if (!state) {
|
|
193
172
|
scope = effectScope2(true);
|
|
@@ -195,23 +174,28 @@ function createSharedReactive(composable) {
|
|
|
195
174
|
}
|
|
196
175
|
onScopeDispose(dispose);
|
|
197
176
|
return state;
|
|
198
|
-
};
|
|
177
|
+
}, "cb");
|
|
178
|
+
cb.r = true;
|
|
179
|
+
return cb;
|
|
199
180
|
}
|
|
200
181
|
__name(createSharedReactive, "createSharedReactive");
|
|
201
182
|
|
|
202
183
|
// src/composable.ts
|
|
184
|
+
var REF_SYMBOL = Symbol("ref");
|
|
203
185
|
function useO(module) {
|
|
204
|
-
const { state } = getActiveInstance2();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
instance
|
|
186
|
+
const { state, origin } = getActiveInstance2();
|
|
187
|
+
const proxyFn = get(module.prototype, "shallow") ? shallowReactive : reactive;
|
|
188
|
+
if (get(module.prototype, "isolate")) {
|
|
189
|
+
const instance = proxyFn(new module());
|
|
190
|
+
instance._promise = invokeHandler2("init", instance);
|
|
208
191
|
return instance;
|
|
209
192
|
}
|
|
210
193
|
const tag = getTag(module);
|
|
211
194
|
if (!(tag in state)) {
|
|
212
|
-
const instance =
|
|
213
|
-
instance._promise =
|
|
195
|
+
const instance = proxyFn(new module());
|
|
196
|
+
instance._promise = invokeHandler2("init", instance);
|
|
214
197
|
state[tag] = instance;
|
|
198
|
+
origin.set(instance, module);
|
|
215
199
|
}
|
|
216
200
|
return state[tag];
|
|
217
201
|
}
|
|
@@ -226,54 +210,27 @@ function usePatch(module, Data) {
|
|
|
226
210
|
}
|
|
227
211
|
__name(usePatch, "usePatch");
|
|
228
212
|
function useR(module) {
|
|
229
|
-
|
|
230
|
-
const instance = useO(module);
|
|
231
|
-
if (rmap.has(instance))
|
|
232
|
-
return rmap.get(instance);
|
|
233
|
-
const proxy = new Proxy(instance, {
|
|
234
|
-
get(target, key) {
|
|
235
|
-
if (typeof target[key] === "function") {
|
|
236
|
-
if (fmap.has(target[key]))
|
|
237
|
-
return fmap.get(target[key]);
|
|
238
|
-
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
239
|
-
if (!errorHandler)
|
|
240
|
-
return target[key].bind(target);
|
|
241
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
242
|
-
fmap.set(target[key], wrapper);
|
|
243
|
-
return wrapper;
|
|
244
|
-
}
|
|
245
|
-
return target[key];
|
|
246
|
-
},
|
|
247
|
-
set(target, key, v) {
|
|
248
|
-
target[key] = v;
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
rmap.set(instance, proxy);
|
|
253
|
-
return proxy;
|
|
213
|
+
return useO(module);
|
|
254
214
|
}
|
|
255
215
|
__name(useR, "useR");
|
|
256
216
|
function useV(module) {
|
|
257
|
-
const {
|
|
217
|
+
const { cache: cacheMap } = getActiveInstance2();
|
|
258
218
|
const instance = useO(module);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
219
|
+
const cache = cacheMap.get(instance) || {};
|
|
220
|
+
if (cache[REF_SYMBOL])
|
|
221
|
+
return cache[REF_SYMBOL];
|
|
262
222
|
const proxy = new Proxy(instance, {
|
|
263
223
|
get(target, key) {
|
|
264
224
|
if (typeof target[key] === "function") {
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (!errorHandler)
|
|
269
|
-
return target[key].bind(target);
|
|
270
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
271
|
-
fmap.set(target[key], wrapper);
|
|
272
|
-
return wrapper;
|
|
225
|
+
if (!cache[key])
|
|
226
|
+
cache[key] = target[key].bind(this);
|
|
227
|
+
return cache[key];
|
|
273
228
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
229
|
+
if (target[key]?.__v_skip)
|
|
230
|
+
return target[key];
|
|
231
|
+
const cacheRef = cache[key];
|
|
232
|
+
if (cacheRef && cacheRef.r)
|
|
233
|
+
return cacheRef();
|
|
277
234
|
cache[key] = createSharedReactive(() => {
|
|
278
235
|
return toRef(target, key);
|
|
279
236
|
});
|
|
@@ -283,18 +240,20 @@ function useV(module) {
|
|
|
283
240
|
return false;
|
|
284
241
|
}
|
|
285
242
|
});
|
|
286
|
-
|
|
243
|
+
cache[REF_SYMBOL] = proxy;
|
|
244
|
+
if (!cacheMap.has(instance))
|
|
245
|
+
cacheMap.set(instance, cache);
|
|
287
246
|
return proxy;
|
|
288
247
|
}
|
|
289
248
|
__name(useV, "useV");
|
|
290
249
|
function useEvent(eventName, cb) {
|
|
291
250
|
onBeforeUnmount(() => {
|
|
292
|
-
|
|
251
|
+
emitter.off(eventName, cb);
|
|
293
252
|
});
|
|
294
|
-
|
|
253
|
+
emitter.on(eventName, cb);
|
|
295
254
|
return {
|
|
296
|
-
emit: (arg) =>
|
|
297
|
-
cancel: () =>
|
|
255
|
+
emit: (arg) => emitter.emit(eventName, arg),
|
|
256
|
+
cancel: () => emitter.off(eventName, cb)
|
|
298
257
|
};
|
|
299
258
|
}
|
|
300
259
|
__name(useEvent, "useEvent");
|
|
@@ -310,12 +269,23 @@ function initialize(module, deleteOtherProperty = true) {
|
|
|
310
269
|
}
|
|
311
270
|
}
|
|
312
271
|
__name(initialize, "initialize");
|
|
272
|
+
|
|
273
|
+
// src/decorator.ts
|
|
274
|
+
import { set } from "phecda-web";
|
|
275
|
+
function Shallow(module) {
|
|
276
|
+
set(module.prototype, "shallow", true);
|
|
277
|
+
}
|
|
278
|
+
__name(Shallow, "Shallow");
|
|
313
279
|
export {
|
|
314
|
-
PV,
|
|
315
280
|
RE,
|
|
281
|
+
Shallow,
|
|
316
282
|
createFilter,
|
|
317
283
|
createPhecda,
|
|
284
|
+
createSharedReactive,
|
|
318
285
|
initialize,
|
|
286
|
+
isObject,
|
|
287
|
+
markRaw2 as markRaw,
|
|
288
|
+
mergeReactiveObjects,
|
|
319
289
|
phecdaSymbol,
|
|
320
290
|
useEvent,
|
|
321
291
|
useO,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-vue",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.16",
|
|
4
4
|
"description": "provide phecda function to vue",
|
|
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
|
"vue": "^3.2.45",
|
|
16
|
-
"phecda-web": "1.0.1-
|
|
16
|
+
"phecda-web": "1.0.1-beta.10"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsup": "^6.5.0"
|