@razaman2/reactive-view 0.1.0-beta.1 → 0.1.0-beta.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.js +39 -31
- package/dist/index.mjs +39 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -177,7 +177,7 @@ var import_vue = require("vue");
|
|
|
177
177
|
|
|
178
178
|
// package.json
|
|
179
179
|
var name = "@razaman2/reactive-view";
|
|
180
|
-
var version = "0.1.0-beta.
|
|
180
|
+
var version = "0.1.0-beta.2";
|
|
181
181
|
|
|
182
182
|
// src/ReactiveView.ts
|
|
183
183
|
var setup = {
|
|
@@ -223,16 +223,16 @@ var ReactiveView_default = {
|
|
|
223
223
|
setup(props, context) {
|
|
224
224
|
var _a, _b, _c;
|
|
225
225
|
const diff = (before, after) => {
|
|
226
|
+
const changed = (0, import_vue.ref)(false);
|
|
226
227
|
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
227
|
-
|
|
228
|
-
const change = paths.reduce((change2, path) => {
|
|
228
|
+
const changes = paths.reduce((changes2, path) => {
|
|
229
229
|
if (before.get(path) !== after.get(path)) {
|
|
230
|
-
|
|
231
|
-
changed = true;
|
|
230
|
+
changes2.set(path, after.get(path));
|
|
231
|
+
changed.value = true;
|
|
232
232
|
}
|
|
233
|
-
return
|
|
233
|
+
return changes2;
|
|
234
234
|
}, import_object_manager.default.on({}));
|
|
235
|
-
return { before: before.get(), after: after.get(), changes:
|
|
235
|
+
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
236
236
|
};
|
|
237
237
|
const dataPath2 = (path) => {
|
|
238
238
|
try {
|
|
@@ -253,9 +253,6 @@ var ReactiveView_default = {
|
|
|
253
253
|
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
254
254
|
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
255
255
|
const vue = (0, import_vue.getCurrentInstance)();
|
|
256
|
-
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
257
|
-
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
258
|
-
}
|
|
259
256
|
const defaultData = props.getDefaultData(
|
|
260
257
|
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.unref)(vue.vnode.props.data)) ? [] : {} : {}
|
|
261
258
|
);
|
|
@@ -340,34 +337,45 @@ var ReactiveView_default = {
|
|
|
340
337
|
const source = () => import_object_manager.default.on(model.getData()).clone();
|
|
341
338
|
(0, import_vue.watch)(source, (after, before) => {
|
|
342
339
|
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
340
|
+
if (props.debug) {
|
|
341
|
+
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
342
|
+
}
|
|
343
343
|
if (diff2.changed) {
|
|
344
344
|
config2.callback(diff2, { component });
|
|
345
345
|
}
|
|
346
|
-
});
|
|
346
|
+
}, config2.options);
|
|
347
347
|
}
|
|
348
348
|
setTimeout(async () => {
|
|
349
349
|
var _a3, _b2, _c2;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
]) : [props.data];
|
|
354
|
-
const isRefData = (0, import_vue.isRef)(data);
|
|
355
|
-
const isReactiveData = (0, import_vue.isReactive)(data);
|
|
356
|
-
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
357
|
-
(0, import_vue.watch)(source, async (after, before) => {
|
|
358
|
-
var _a4;
|
|
359
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
360
|
-
const callback = context.attrs["data:callback"];
|
|
361
|
-
if (typeof callback === "function") {
|
|
362
|
-
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
363
|
-
} else {
|
|
364
|
-
model.replaceData(after);
|
|
350
|
+
if (props.model !== false) {
|
|
351
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
352
|
+
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
365
353
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
354
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
355
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
356
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
357
|
+
]) : [props.data];
|
|
358
|
+
const isRefData = (0, import_vue.isRef)(data);
|
|
359
|
+
const isReactiveData = (0, import_vue.isReactive)(data);
|
|
360
|
+
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
361
|
+
(0, import_vue.watch)(source, async (after, before) => {
|
|
362
|
+
var _a4;
|
|
363
|
+
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
364
|
+
const callback = context.attrs["data:callback"];
|
|
365
|
+
if (props.debug) {
|
|
366
|
+
console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, isRefData, isReactiveData });
|
|
367
|
+
}
|
|
368
|
+
if (typeof callback === "function") {
|
|
369
|
+
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
370
|
+
} else {
|
|
371
|
+
model.replaceData(after);
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
375
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
376
|
+
once: context.attrs["data:once"]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
371
379
|
});
|
|
372
380
|
setTimeout(async () => {
|
|
373
381
|
var _a3;
|
package/dist/index.mjs
CHANGED
|
@@ -131,7 +131,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
|
|
|
131
131
|
|
|
132
132
|
// package.json
|
|
133
133
|
var name = "@razaman2/reactive-view";
|
|
134
|
-
var version = "0.1.0-beta.
|
|
134
|
+
var version = "0.1.0-beta.2";
|
|
135
135
|
|
|
136
136
|
// src/ReactiveView.ts
|
|
137
137
|
var setup = {
|
|
@@ -177,16 +177,16 @@ var ReactiveView_default = {
|
|
|
177
177
|
setup(props, context) {
|
|
178
178
|
var _a, _b, _c;
|
|
179
179
|
const diff = (before, after) => {
|
|
180
|
+
const changed = ref(false);
|
|
180
181
|
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
181
|
-
|
|
182
|
-
const change = paths.reduce((change2, path) => {
|
|
182
|
+
const changes = paths.reduce((changes2, path) => {
|
|
183
183
|
if (before.get(path) !== after.get(path)) {
|
|
184
|
-
|
|
185
|
-
changed = true;
|
|
184
|
+
changes2.set(path, after.get(path));
|
|
185
|
+
changed.value = true;
|
|
186
186
|
}
|
|
187
|
-
return
|
|
187
|
+
return changes2;
|
|
188
188
|
}, ObjectManager.on({}));
|
|
189
|
-
return { before: before.get(), after: after.get(), changes:
|
|
189
|
+
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
190
190
|
};
|
|
191
191
|
const dataPath2 = (path) => {
|
|
192
192
|
try {
|
|
@@ -207,9 +207,6 @@ var ReactiveView_default = {
|
|
|
207
207
|
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
208
208
|
const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
209
209
|
const vue = getCurrentInstance();
|
|
210
|
-
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
211
|
-
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
212
|
-
}
|
|
213
210
|
const defaultData = props.getDefaultData(
|
|
214
211
|
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
|
|
215
212
|
);
|
|
@@ -294,34 +291,45 @@ var ReactiveView_default = {
|
|
|
294
291
|
const source = () => ObjectManager.on(model.getData()).clone();
|
|
295
292
|
watch(source, (after, before) => {
|
|
296
293
|
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
294
|
+
if (props.debug) {
|
|
295
|
+
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
296
|
+
}
|
|
297
297
|
if (diff2.changed) {
|
|
298
298
|
config2.callback(diff2, { component });
|
|
299
299
|
}
|
|
300
|
-
});
|
|
300
|
+
}, config2.options);
|
|
301
301
|
}
|
|
302
302
|
setTimeout(async () => {
|
|
303
303
|
var _a3, _b2, _c2;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
]) : [props.data];
|
|
308
|
-
const isRefData = isRef(data);
|
|
309
|
-
const isReactiveData = isReactive(data);
|
|
310
|
-
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
311
|
-
watch(source, async (after, before) => {
|
|
312
|
-
var _a4;
|
|
313
|
-
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
314
|
-
const callback = context.attrs["data:callback"];
|
|
315
|
-
if (typeof callback === "function") {
|
|
316
|
-
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
317
|
-
} else {
|
|
318
|
-
model.replaceData(after);
|
|
304
|
+
if (props.model !== false) {
|
|
305
|
+
if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
|
|
306
|
+
console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
|
|
319
307
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
308
|
+
const [data] = isPromiseData ? await Promise.all([
|
|
309
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
310
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
311
|
+
]) : [props.data];
|
|
312
|
+
const isRefData = isRef(data);
|
|
313
|
+
const isReactiveData = isReactive(data);
|
|
314
|
+
const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
|
|
315
|
+
watch(source, async (after, before) => {
|
|
316
|
+
var _a4;
|
|
317
|
+
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
318
|
+
const callback = context.attrs["data:callback"];
|
|
319
|
+
if (props.debug) {
|
|
320
|
+
console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, isRefData, isReactiveData });
|
|
321
|
+
}
|
|
322
|
+
if (typeof callback === "function") {
|
|
323
|
+
model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
|
|
324
|
+
} else {
|
|
325
|
+
model.replaceData(after);
|
|
326
|
+
}
|
|
327
|
+
}, {
|
|
328
|
+
immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
|
|
329
|
+
deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
|
|
330
|
+
once: context.attrs["data:once"]
|
|
331
|
+
});
|
|
332
|
+
}
|
|
325
333
|
});
|
|
326
334
|
setTimeout(async () => {
|
|
327
335
|
var _a3;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razaman2/reactive-view",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
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",
|