phecda-vue 3.0.0-beta.19 → 3.0.0-beta.21

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
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { Ref, App, UnwrapNestedRefs } from 'vue';
2
+ import { Ref, App, UnwrapNestedRefs, WatchOptions } from 'vue';
3
3
  import { Construct, Events } from 'phecda-web';
4
4
  export * from 'phecda-web';
5
5
 
@@ -62,5 +62,6 @@ declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event:
62
62
  declare function initialize<M extends Construct>(model: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
63
63
 
64
64
  declare function Shallow(model: any): void;
65
+ declare function WatchEffect(option?: WatchOptions): (proto: any, key: string) => void;
65
66
 
66
- export { DeepPartial, RE, Raw, RawSymbol, ReplaceInstanceValues, SchemaToObj, Shallow, createFilter, createPhecda, createSharedReactive, initialize, isObject, markRaw, mergeReactiveObjects, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
67
+ export { DeepPartial, RE, Raw, RawSymbol, ReplaceInstanceValues, SchemaToObj, Shallow, WatchEffect, createFilter, createPhecda, createSharedReactive, initialize, isObject, markRaw, mergeReactiveObjects, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ var src_exports = {};
24
24
  __export(src_exports, {
25
25
  RE: () => RE,
26
26
  Shallow: () => Shallow,
27
+ WatchEffect: () => WatchEffect,
27
28
  createFilter: () => createFilter,
28
29
  createPhecda: () => createPhecda,
29
30
  createSharedReactive: () => createSharedReactive,
@@ -222,21 +223,31 @@ __name(createSharedReactive, "createSharedReactive");
222
223
 
223
224
  // src/composable.ts
224
225
  var REF_SYMBOL = Symbol("ref");
226
+ function initInstance(model) {
227
+ const proxyFn = (0, import_phecda_web2.get)(model.prototype, "shallow") ? import_vue4.shallowReactive : import_vue4.reactive;
228
+ const instance = proxyFn(new model());
229
+ instance._promise = (0, import_phecda_web2.invokeHandler)("init", instance);
230
+ return instance;
231
+ }
232
+ __name(initInstance, "initInstance");
225
233
  function useO(model) {
226
234
  const { state, origin } = (0, import_phecda_web2.getActiveInstance)();
227
- const proxyFn = (0, import_phecda_web2.get)(model.prototype, "shallow") ? import_vue4.shallowReactive : import_vue4.reactive;
228
- if ((0, import_phecda_web2.get)(model.prototype, "isolate")) {
229
- const instance = proxyFn(new model());
230
- instance._promise = (0, import_phecda_web2.invokeHandler)("init", instance);
231
- return instance;
232
- }
235
+ if ((0, import_phecda_web2.get)(model.prototype, "isolate"))
236
+ return initInstance(model);
233
237
  const tag = (0, import_phecda_web2.getTag)(model);
234
- if (!(tag in state)) {
235
- const instance = proxyFn(new model());
236
- instance._promise = (0, import_phecda_web2.invokeHandler)("init", instance);
237
- state[tag] = instance;
238
- origin.set(instance, model);
238
+ if (tag in state) {
239
+ if (process.env.NODE_ENV === "development") {
240
+ if (origin.get(state[tag]) === model)
241
+ return state[tag];
242
+ } else {
243
+ if (origin.get(state[tag]) !== model)
244
+ console.warn(`Synonym model: Module taged "${String(tag)}" has been loaded before, so won't load Module "${model.name}"`);
245
+ return state[tag];
246
+ }
239
247
  }
248
+ const instance = initInstance(model);
249
+ state[tag] = instance;
250
+ origin.set(instance, model);
240
251
  return state[tag];
241
252
  }
242
253
  __name(useO, "useO");
@@ -312,14 +323,33 @@ __name(initialize, "initialize");
312
323
 
313
324
  // src/decorator.ts
314
325
  var import_phecda_web3 = require("phecda-web");
326
+ var import_vue5 = require("vue");
315
327
  function Shallow(model) {
316
328
  (0, import_phecda_web3.set)(model.prototype, "shallow", true);
317
329
  }
318
330
  __name(Shallow, "Shallow");
331
+ function WatchEffect(option) {
332
+ return (proto, key) => {
333
+ (0, import_phecda_web3.setStateKey)(proto, key);
334
+ let stopHandler;
335
+ (0, import_phecda_web3.setHandler)(proto, key, {
336
+ init(instance) {
337
+ if (typeof instance[key] !== "function")
338
+ throw new TypeError(" WatchEffect must decorate function");
339
+ stopHandler = (0, import_vue5.watchEffect)(instance[key].bind(instance), option);
340
+ },
341
+ unmount() {
342
+ return stopHandler?.();
343
+ }
344
+ });
345
+ };
346
+ }
347
+ __name(WatchEffect, "WatchEffect");
319
348
  // Annotate the CommonJS export names for ESM import in node:
320
349
  0 && (module.exports = {
321
350
  RE,
322
351
  Shallow,
352
+ WatchEffect,
323
353
  createFilter,
324
354
  createPhecda,
325
355
  createSharedReactive,
package/dist/index.mjs CHANGED
@@ -182,21 +182,31 @@ __name(createSharedReactive, "createSharedReactive");
182
182
 
183
183
  // src/composable.ts
184
184
  var REF_SYMBOL = Symbol("ref");
185
+ function initInstance(model) {
186
+ const proxyFn = get(model.prototype, "shallow") ? shallowReactive : reactive;
187
+ const instance = proxyFn(new model());
188
+ instance._promise = invokeHandler2("init", instance);
189
+ return instance;
190
+ }
191
+ __name(initInstance, "initInstance");
185
192
  function useO(model) {
186
193
  const { state, origin } = getActiveInstance2();
187
- const proxyFn = get(model.prototype, "shallow") ? shallowReactive : reactive;
188
- if (get(model.prototype, "isolate")) {
189
- const instance = proxyFn(new model());
190
- instance._promise = invokeHandler2("init", instance);
191
- return instance;
192
- }
194
+ if (get(model.prototype, "isolate"))
195
+ return initInstance(model);
193
196
  const tag = getTag(model);
194
- if (!(tag in state)) {
195
- const instance = proxyFn(new model());
196
- instance._promise = invokeHandler2("init", instance);
197
- state[tag] = instance;
198
- origin.set(instance, model);
197
+ if (tag in state) {
198
+ if (process.env.NODE_ENV === "development") {
199
+ if (origin.get(state[tag]) === model)
200
+ return state[tag];
201
+ } else {
202
+ if (origin.get(state[tag]) !== model)
203
+ console.warn(`Synonym model: Module taged "${String(tag)}" has been loaded before, so won't load Module "${model.name}"`);
204
+ return state[tag];
205
+ }
199
206
  }
207
+ const instance = initInstance(model);
208
+ state[tag] = instance;
209
+ origin.set(instance, model);
200
210
  return state[tag];
201
211
  }
202
212
  __name(useO, "useO");
@@ -271,14 +281,33 @@ function initialize(model, deleteOtherProperty = true) {
271
281
  __name(initialize, "initialize");
272
282
 
273
283
  // src/decorator.ts
274
- import { set } from "phecda-web";
284
+ import { set, setHandler, setStateKey } from "phecda-web";
285
+ import { watchEffect } from "vue";
275
286
  function Shallow(model) {
276
287
  set(model.prototype, "shallow", true);
277
288
  }
278
289
  __name(Shallow, "Shallow");
290
+ function WatchEffect(option) {
291
+ return (proto, key) => {
292
+ setStateKey(proto, key);
293
+ let stopHandler;
294
+ setHandler(proto, key, {
295
+ init(instance) {
296
+ if (typeof instance[key] !== "function")
297
+ throw new TypeError(" WatchEffect must decorate function");
298
+ stopHandler = watchEffect(instance[key].bind(instance), option);
299
+ },
300
+ unmount() {
301
+ return stopHandler?.();
302
+ }
303
+ });
304
+ };
305
+ }
306
+ __name(WatchEffect, "WatchEffect");
279
307
  export {
280
308
  RE,
281
309
  Shallow,
310
+ WatchEffect,
282
311
  createFilter,
283
312
  createPhecda,
284
313
  createSharedReactive,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "3.0.0-beta.19",
3
+ "version": "3.0.0-beta.21",
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-beta.12"
16
+ "phecda-web": "1.0.1-beta.13"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tsup": "^6.5.0"