@razaman2/reactive-view 0.0.33 → 0.0.34

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.mts CHANGED
@@ -53,9 +53,7 @@ declare const _default: {
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {
57
- default: {};
58
- };
56
+ data: {};
59
57
  defaultData: {};
60
58
  getDefaultData: {
61
59
  type: FunctionConstructor;
package/dist/index.d.ts CHANGED
@@ -53,9 +53,7 @@ declare const _default: {
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {
57
- default: {};
58
- };
56
+ data: {};
59
57
  defaultData: {};
60
58
  getDefaultData: {
61
59
  type: FunctionConstructor;
package/dist/index.js CHANGED
@@ -168,7 +168,7 @@ var import_vue = require("vue");
168
168
 
169
169
  // package.json
170
170
  var name = "@razaman2/reactive-view";
171
- var version = "0.0.33";
171
+ var version = "0.0.34";
172
172
 
173
173
  // src/ReactiveView.ts
174
174
  var setup = {
@@ -189,9 +189,7 @@ var ReactiveView_default = {
189
189
  notifications: Object,
190
190
  subscriptions: Object,
191
191
  beforeSetData: Function,
192
- data: {
193
- default: {}
194
- },
192
+ data: {},
195
193
  defaultData: {},
196
194
  getDefaultData: {
197
195
  type: Function,
@@ -225,25 +223,26 @@ var ReactiveView_default = {
225
223
  );
226
224
  };
227
225
  const isValid = (0, import_vue.ref)(false);
228
- const ready = (0, import_vue.ref)(false);
229
- const vue = (0, import_vue.getCurrentInstance)();
226
+ const isReady = (0, import_vue.ref)(false);
227
+ const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
228
+ const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
229
+ const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
230
230
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
231
- const data = typeof props.data === "function" ? props.data() : props.data;
232
- const async = data instanceof Promise;
231
+ const vue = (0, import_vue.getCurrentInstance)();
233
232
  if (props.debug) {
234
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
233
+ console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
235
234
  }
236
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
237
- console.error("[ReactiveView]: defaultData is required for async data.");
235
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
236
+ console.error("[ReactiveView]: defaultData is required for function or async data.");
238
237
  }
239
238
  const defaultData = props.getDefaultData(
240
- ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : typeof ((_c = vue.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(vue.vnode.props.data) ? [] : {} : ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = vue.vnode.props) == null ? void 0 : _e.data : {}
239
+ ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
241
240
  );
242
241
  const datatype = Array.isArray(defaultData) ? [] : {};
243
242
  const config = {
244
- data: (0, import_vue.reactive)(
245
- import_object_manager.default.on(async ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? typeof data === "function" ? datatype : data : datatype).clone()
246
- ),
243
+ data: (0, import_vue.reactive)(import_object_manager.default.on(
244
+ isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
245
+ ).clone()),
247
246
  defaultData: import_object_manager.default.on(defaultData).clone(),
248
247
  notifications: props.notifications,
249
248
  subscriptions: props.subscriptions,
@@ -281,9 +280,9 @@ var ReactiveView_default = {
281
280
  }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
282
281
  };
283
282
  if (context.attrs["data:log"]) {
284
- console.log(`[data:prop]:`, config2);
283
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
285
284
  }
286
- (0, import_vue.watch)(typeof dataProp === "function" || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
285
+ (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
287
286
  var _a3;
288
287
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
289
288
  if (typeof config2.callback === "function") {
@@ -295,17 +294,20 @@ var ReactiveView_default = {
295
294
  };
296
295
  setTimeout(async () => {
297
296
  var _a2;
298
- const [dataProp] = await Promise.all([data, (_a2 = defer.value) != null ? _a2 : true]);
299
- watchDataProp(dataProp);
297
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
298
+ watchDataProp(data);
300
299
  });
301
300
  setTimeout(async () => {
302
301
  var _a2;
303
- ready.value = (_a2 = await defer.value) != null ? _a2 : true;
302
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
304
303
  });
305
304
  if (context.attrs["onUpdate:model"]) {
306
305
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
307
306
  callback: context.attrs["onUpdate:model"]
308
307
  } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
308
+ if (context.attrs["model:log"]) {
309
+ console.log(`[ReactiveView]:model`, { config: config2 });
310
+ }
309
311
  (0, import_vue.watch)(() => model.getData(), (after, before) => {
310
312
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
311
313
  config2.callback(diff, { component });
@@ -331,7 +333,7 @@ var ReactiveView_default = {
331
333
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
332
334
  return (vue2) => {
333
335
  var _a2, _b2;
334
- if (ready.value) {
336
+ if (isReady.value) {
335
337
  return access(component).template(component, vue2);
336
338
  } else {
337
339
  return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
package/dist/index.mjs CHANGED
@@ -125,7 +125,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
125
125
 
126
126
  // package.json
127
127
  var name = "@razaman2/reactive-view";
128
- var version = "0.0.33";
128
+ var version = "0.0.34";
129
129
 
130
130
  // src/ReactiveView.ts
131
131
  var setup = {
@@ -146,9 +146,7 @@ var ReactiveView_default = {
146
146
  notifications: Object,
147
147
  subscriptions: Object,
148
148
  beforeSetData: Function,
149
- data: {
150
- default: {}
151
- },
149
+ data: {},
152
150
  defaultData: {},
153
151
  getDefaultData: {
154
152
  type: Function,
@@ -182,25 +180,26 @@ var ReactiveView_default = {
182
180
  );
183
181
  };
184
182
  const isValid = ref(false);
185
- const ready = ref(false);
186
- const vue = getCurrentInstance();
183
+ const isReady = ref(false);
184
+ const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
185
+ const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
186
+ const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
187
187
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
188
- const data = typeof props.data === "function" ? props.data() : props.data;
189
- const async = data instanceof Promise;
188
+ const vue = getCurrentInstance();
190
189
  if (props.debug) {
191
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
190
+ console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
192
191
  }
193
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
194
- console.error("[ReactiveView]: defaultData is required for async data.");
192
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
193
+ console.error("[ReactiveView]: defaultData is required for function or async data.");
195
194
  }
196
195
  const defaultData = props.getDefaultData(
197
- ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : typeof ((_c = vue.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(vue.vnode.props.data) ? [] : {} : ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = vue.vnode.props) == null ? void 0 : _e.data : {}
196
+ ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
198
197
  );
199
198
  const datatype = Array.isArray(defaultData) ? [] : {};
200
199
  const config = {
201
- data: reactive(
202
- ObjectManager.on(async ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? typeof data === "function" ? datatype : data : datatype).clone()
203
- ),
200
+ data: reactive(ObjectManager.on(
201
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
202
+ ).clone()),
204
203
  defaultData: ObjectManager.on(defaultData).clone(),
205
204
  notifications: props.notifications,
206
205
  subscriptions: props.subscriptions,
@@ -238,9 +237,9 @@ var ReactiveView_default = {
238
237
  }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
239
238
  };
240
239
  if (context.attrs["data:log"]) {
241
- console.log(`[data:prop]:`, config2);
240
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
242
241
  }
243
- watch(typeof dataProp === "function" || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
242
+ watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
244
243
  var _a3;
245
244
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
246
245
  if (typeof config2.callback === "function") {
@@ -252,17 +251,20 @@ var ReactiveView_default = {
252
251
  };
253
252
  setTimeout(async () => {
254
253
  var _a2;
255
- const [dataProp] = await Promise.all([data, (_a2 = defer.value) != null ? _a2 : true]);
256
- watchDataProp(dataProp);
254
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
255
+ watchDataProp(data);
257
256
  });
258
257
  setTimeout(async () => {
259
258
  var _a2;
260
- ready.value = (_a2 = await defer.value) != null ? _a2 : true;
259
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
261
260
  });
262
261
  if (context.attrs["onUpdate:model"]) {
263
262
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
264
263
  callback: context.attrs["onUpdate:model"]
265
264
  } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
265
+ if (context.attrs["model:log"]) {
266
+ console.log(`[ReactiveView]:model`, { config: config2 });
267
+ }
266
268
  watch(() => model.getData(), (after, before) => {
267
269
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
268
270
  config2.callback(diff, { component });
@@ -288,7 +290,7 @@ var ReactiveView_default = {
288
290
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
289
291
  return (vue2) => {
290
292
  var _a2, _b2;
291
- if (ready.value) {
293
+ if (isReady.value) {
292
294
  return access(component).template(component, vue2);
293
295
  } else {
294
296
  return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",