@live-change/vue3-components 0.2.8 → 0.2.9
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/form/DefinedForm.vue +5 -2
- package/logic/synchronized.js +21 -4
- package/logic/synchronizedList.js +8 -4
- package/package.json +5 -5
package/form/DefinedForm.vue
CHANGED
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
constructor(definition, component, data, property) {
|
|
116
116
|
super(definition, component, data, property)
|
|
117
117
|
|
|
118
|
+
if(!this.data[this.property]) this.data[this.property] = {}
|
|
118
119
|
this.object = this.data[this.property]
|
|
119
120
|
this.properties = {}
|
|
120
121
|
|
|
@@ -246,6 +247,7 @@
|
|
|
246
247
|
super(definition, component, data, property)
|
|
247
248
|
this.elementDefinition = definition.of
|
|
248
249
|
this.elements = []
|
|
250
|
+
if(!this.data[this.property]) this.data[this.property] = []
|
|
249
251
|
this.object = this.data[this.property]
|
|
250
252
|
}
|
|
251
253
|
setProperty(name) {
|
|
@@ -268,7 +270,7 @@
|
|
|
268
270
|
for(let i = 0; i < initialValue.length; i++) {
|
|
269
271
|
let n = this.newElement(this.elements.length)
|
|
270
272
|
n.reset(initialValue[i])
|
|
271
|
-
this.elements
|
|
273
|
+
this.elements[i] = n
|
|
272
274
|
}
|
|
273
275
|
super.setValue(initialValue)
|
|
274
276
|
}
|
|
@@ -299,6 +301,7 @@
|
|
|
299
301
|
clearValidation() {
|
|
300
302
|
super.clearValidation()
|
|
301
303
|
for(let element of this.elements) {
|
|
304
|
+
console.log("CLEAR ELEMENT", element, 'OF', this.elements, "IN", this.property)
|
|
302
305
|
element.clearValidation()
|
|
303
306
|
}
|
|
304
307
|
}
|
|
@@ -326,7 +329,7 @@
|
|
|
326
329
|
this.data[this.property] = value
|
|
327
330
|
if(!value) return;
|
|
328
331
|
for(let i = 0; i < value.length; i++) {
|
|
329
|
-
if
|
|
332
|
+
if(this.elements[i]) {
|
|
330
333
|
this.elements[i].setValue(value[i])
|
|
331
334
|
} else {
|
|
332
335
|
let n = this.newElement()
|
package/logic/synchronized.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { computed, ref, watch } from "vue"
|
|
2
2
|
import { useThrottleFn } from "@vueuse/core"
|
|
3
3
|
|
|
4
|
+
function copy(value) {
|
|
5
|
+
let res = JSON.parse(JSON.stringify(value || {}))
|
|
6
|
+
if(value) for(const key in value) {
|
|
7
|
+
if(typeof value[key] == 'function') {
|
|
8
|
+
res[key] = value[key]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return res
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
function synchronized(options) {
|
|
5
15
|
const {
|
|
6
16
|
source,
|
|
@@ -17,7 +27,7 @@ function synchronized(options) {
|
|
|
17
27
|
if(!source) throw new Error('source must be defined')
|
|
18
28
|
if(!update) throw new Error('update function must be defined')
|
|
19
29
|
if(recursive) {
|
|
20
|
-
const synchronizedValue = ref(
|
|
30
|
+
const synchronizedValue = ref(copy(source.value))
|
|
21
31
|
const synchronizedJSON = computed(() => JSON.stringify(synchronizedValue.value))
|
|
22
32
|
const lastLocalUpdate = ref(synchronized.value ? synchronizedValue.value[timeField] : '')
|
|
23
33
|
|
|
@@ -49,10 +59,17 @@ function synchronized(options) {
|
|
|
49
59
|
onChange()
|
|
50
60
|
if(autoSave) throttledSave()
|
|
51
61
|
})
|
|
52
|
-
|
|
62
|
+
console.log("WATCH SOURCE VALUE", source.value)
|
|
63
|
+
watch(() => JSON.stringify(source.value), sourceJson => {
|
|
64
|
+
const sourceData = JSON.parse(sourceJson)
|
|
53
65
|
if(sourceData) {
|
|
54
|
-
console.log("SRC DATA", sourceData)
|
|
55
|
-
|
|
66
|
+
//console.log("SRC DATA", JSON.stringify(sourceData))
|
|
67
|
+
//console.log("TIME", sourceData[timeField], '>', lastLocalUpdate.value)
|
|
68
|
+
if(sourceData[timeField] > lastLocalUpdate.value) {
|
|
69
|
+
lastLocalUpdate.value = sourceData[timeField]
|
|
70
|
+
synchronizedValue.value = copy(sourceData)
|
|
71
|
+
}
|
|
72
|
+
|
|
56
73
|
}
|
|
57
74
|
})
|
|
58
75
|
return { value: synchronizedValue, save, changed }
|
|
@@ -23,6 +23,7 @@ function sortedArraysMerge(merge, ...arrays) {
|
|
|
23
23
|
if(position < array.length && array[position].id == lowestId) {
|
|
24
24
|
objects[arrayIndex] = array[position]
|
|
25
25
|
positions[arrayIndex]++
|
|
26
|
+
incremented = true
|
|
26
27
|
} else {
|
|
27
28
|
objects[arrayIndex] = null
|
|
28
29
|
}
|
|
@@ -62,20 +63,22 @@ function synchronizedList(options) {
|
|
|
62
63
|
const locallyDeleted = ref([])
|
|
63
64
|
|
|
64
65
|
function createSynchronizedElement(sourceData) {
|
|
66
|
+
console.log("CREATE SYNCHRONIZED", JSON.stringify(sourceData))
|
|
65
67
|
const elementSource = ref(sourceData)
|
|
66
68
|
const synchronizedElement = mapper(elementSource)
|
|
69
|
+
console.log("SYNC ELEMENT", synchronizedElement)
|
|
67
70
|
synchronizedElement.source = elementSource
|
|
68
71
|
synchronizedElement.id = sourceData.id
|
|
69
72
|
return synchronizedElement
|
|
70
73
|
}
|
|
71
74
|
function synchronizeFromSource() {
|
|
72
|
-
|
|
75
|
+
console.log("SYNCHRONIZE FROM SOURCE!")
|
|
73
76
|
let obsoleteLocallyAdded = new Set()
|
|
74
77
|
let obsoleteLocallyDeleted = new Set()
|
|
75
78
|
let newSynchronized = sortedArraysMerge(
|
|
76
79
|
(synchronizedElement, sourceElement, locallyAddedElement, locallyDeletedElement) => {
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
/* console.log("MERGE ELEMENT", synchronizedElement)
|
|
79
82
|
console.log("SOURCE ELEMENT", sourceElement)
|
|
80
83
|
console.log("LOCALLY ADDED", locallyAddedElement)
|
|
81
84
|
console.log("LOCALLY DELETED", locallyDeletedElement)*/
|
|
@@ -92,10 +95,11 @@ function synchronizedList(options) {
|
|
|
92
95
|
return null // synchronized element locally
|
|
93
96
|
}
|
|
94
97
|
if(sourceElement) {
|
|
95
|
-
synchronizedElement.source
|
|
98
|
+
synchronizedElement.source = sourceElement
|
|
99
|
+
watch(() => synchronizedElement.source.value, v => console.log("DD",v))
|
|
96
100
|
return synchronizedElement
|
|
97
101
|
} else if(locallyAddedElement) {
|
|
98
|
-
synchronizedElement.source
|
|
102
|
+
synchronizedElement.source = locallyAddedElement
|
|
99
103
|
return synchronizedElement
|
|
100
104
|
} else {
|
|
101
105
|
return null // synchronized element deleted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/vue3-components",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Live Change Framework - vue components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/live-change-framework-vue3",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/vue3-ssr": "^0.2.
|
|
25
|
-
"debug": "^4.3.
|
|
24
|
+
"@live-change/vue3-ssr": "^0.2.9",
|
|
25
|
+
"debug": "^4.3.4",
|
|
26
26
|
"mitt": "3.0.0",
|
|
27
|
-
"vue": "^3.2.
|
|
27
|
+
"vue": "^3.2.33"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "efcb8e4afc03219f588d6e782f29e4f3f74af3cf"
|
|
30
30
|
}
|