phecda-vue 1.1.0 → 1.1.2

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
@@ -60,6 +60,7 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
60
60
  expressionRE?: RegExp;
61
61
  fnRE?: RegExp;
62
62
  exclude?: string[];
63
+ errorHandler?: (error?: Error, errorPath?: string) => any;
63
64
  }): {
64
65
  filter: <Schema>(obj: Schema) => SchemaToObj<Schema>;
65
66
  data: [Data] extends [vue.Ref<any>] ? Data : vue.Ref<vue.UnwrapRef<Data>>;
package/dist/index.js CHANGED
@@ -74,10 +74,10 @@ function createPhecda(symbol) {
74
74
  install(app) {
75
75
  app.provide(phecdaSymbol, phecda);
76
76
  app.config.globalProperties.$phecda = phecda;
77
- if (!window._phecda)
78
- window._phecda = {};
77
+ if (!window.__PHECDA_VUE__)
78
+ window.__PHECDA_VUE__ = {};
79
79
  if (symbol) {
80
- window._phecda[symbol] = {
80
+ window.__PHECDA_VUE__[symbol] = {
81
81
  instance: phecda,
82
82
  snapshot: () => {
83
83
  const ret = [];
@@ -99,7 +99,7 @@ function createPhecda(symbol) {
99
99
  ([eventName, handler]) => emitter.off(eventName, handler)
100
100
  );
101
101
  if (symbol)
102
- delete window._phecda[symbol];
102
+ delete window.__PHECDA_VUE__[symbol];
103
103
  originUnmount();
104
104
  };
105
105
  },
@@ -125,10 +125,10 @@ function getActivePhecda() {
125
125
  return activePhecda;
126
126
  }
127
127
  function getReactiveMap(symbol) {
128
- if (!window._phecda?.[symbol])
128
+ if (!window.__PHECDA_VUE__?.[symbol])
129
129
  return null;
130
130
  const ret = /* @__PURE__ */ new Map();
131
- window._phecda[symbol].snapshot.forEach(({ key, value }) => {
131
+ window.__PHECDA_VUE__[symbol].snapshot.forEach(({ key, value }) => {
132
132
  ret.set(key, value);
133
133
  });
134
134
  return ret;
@@ -324,19 +324,21 @@ function createFilter(initState = {}, option = {}) {
324
324
  const scope = (0, import_vue4.effectScope)(true);
325
325
  let data = scope.run(() => (0, import_vue4.ref)(initState));
326
326
  let store = {};
327
- function traverse(obj) {
327
+ function traverse(obj, path) {
328
328
  for (const i in obj) {
329
329
  if (Array.isArray(obj[i]) || resolveOption.exclude.includes(i))
330
330
  continue;
331
+ const errorPath = path ? `${path}.${i}` : i;
331
332
  if (typeof obj[i] === "object" && obj[i])
332
- traverse(obj[i]);
333
+ traverse(obj[i], errorPath);
333
334
  if (typeof obj[i] === "string") {
334
335
  if (resolveOption.expressionRE.test(obj[i])) {
335
336
  const body = obj[i].match(resolveOption.expressionRE)[1];
336
337
  Object.defineProperty(obj, i, {
337
338
  get() {
338
- return new Function(...Object.keys(data.value), `return ${body}`)(
339
- ...Object.values(data.value)
339
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{return ${body}}catch(e){return _eh(e,"${errorPath}")}` : `return ${body}`)(
340
+ ...Object.values(data.value),
341
+ resolveOption.errorHandler
340
342
  );
341
343
  }
342
344
  });
@@ -345,8 +347,9 @@ function createFilter(initState = {}, option = {}) {
345
347
  const body = obj[i].match(resolveOption.fnRE)[1];
346
348
  Object.defineProperty(obj, i, {
347
349
  get() {
348
- return new Function(...Object.keys(data.value), `${body}`)(
349
- ...Object.values(data.value)
350
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${body}}catch(e){return _eh(e,"${errorPath}")}` : `${body}`)(
351
+ ...Object.values(data.value),
352
+ resolveOption.errorHandler
350
353
  );
351
354
  }
352
355
  });
package/dist/index.mjs CHANGED
@@ -12,10 +12,10 @@ function createPhecda(symbol) {
12
12
  install(app) {
13
13
  app.provide(phecdaSymbol, phecda);
14
14
  app.config.globalProperties.$phecda = phecda;
15
- if (!window._phecda)
16
- window._phecda = {};
15
+ if (!window.__PHECDA_VUE__)
16
+ window.__PHECDA_VUE__ = {};
17
17
  if (symbol) {
18
- window._phecda[symbol] = {
18
+ window.__PHECDA_VUE__[symbol] = {
19
19
  instance: phecda,
20
20
  snapshot: () => {
21
21
  const ret = [];
@@ -37,7 +37,7 @@ function createPhecda(symbol) {
37
37
  ([eventName, handler]) => emitter.off(eventName, handler)
38
38
  );
39
39
  if (symbol)
40
- delete window._phecda[symbol];
40
+ delete window.__PHECDA_VUE__[symbol];
41
41
  originUnmount();
42
42
  };
43
43
  },
@@ -63,10 +63,10 @@ function getActivePhecda() {
63
63
  return activePhecda;
64
64
  }
65
65
  function getReactiveMap(symbol) {
66
- if (!window._phecda?.[symbol])
66
+ if (!window.__PHECDA_VUE__?.[symbol])
67
67
  return null;
68
68
  const ret = /* @__PURE__ */ new Map();
69
- window._phecda[symbol].snapshot.forEach(({ key, value }) => {
69
+ window.__PHECDA_VUE__[symbol].snapshot.forEach(({ key, value }) => {
70
70
  ret.set(key, value);
71
71
  });
72
72
  return ret;
@@ -262,19 +262,21 @@ function createFilter(initState = {}, option = {}) {
262
262
  const scope = effectScope2(true);
263
263
  let data = scope.run(() => ref(initState));
264
264
  let store = {};
265
- function traverse(obj) {
265
+ function traverse(obj, path) {
266
266
  for (const i in obj) {
267
267
  if (Array.isArray(obj[i]) || resolveOption.exclude.includes(i))
268
268
  continue;
269
+ const errorPath = path ? `${path}.${i}` : i;
269
270
  if (typeof obj[i] === "object" && obj[i])
270
- traverse(obj[i]);
271
+ traverse(obj[i], errorPath);
271
272
  if (typeof obj[i] === "string") {
272
273
  if (resolveOption.expressionRE.test(obj[i])) {
273
274
  const body = obj[i].match(resolveOption.expressionRE)[1];
274
275
  Object.defineProperty(obj, i, {
275
276
  get() {
276
- return new Function(...Object.keys(data.value), `return ${body}`)(
277
- ...Object.values(data.value)
277
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{return ${body}}catch(e){return _eh(e,"${errorPath}")}` : `return ${body}`)(
278
+ ...Object.values(data.value),
279
+ resolveOption.errorHandler
278
280
  );
279
281
  }
280
282
  });
@@ -283,8 +285,9 @@ function createFilter(initState = {}, option = {}) {
283
285
  const body = obj[i].match(resolveOption.fnRE)[1];
284
286
  Object.defineProperty(obj, i, {
285
287
  get() {
286
- return new Function(...Object.keys(data.value), `${body}`)(
287
- ...Object.values(data.value)
288
+ return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${body}}catch(e){return _eh(e,"${errorPath}")}` : `${body}`)(
289
+ ...Object.values(data.value),
290
+ resolveOption.errorHandler
288
291
  );
289
292
  }
290
293
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "mitt": "^3.0.0",
16
16
  "vue": "^3.2.45",
17
- "phecda-core": "1.0.4"
17
+ "phecda-core": "1.0.5"
18
18
  },
19
19
  "devDependencies": {
20
20
  "tsup": "^6.5.0"