@live-change/vue3-components 0.2.6 → 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.
@@ -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.push(n)
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 (this.elements[i]) {
332
+ if(this.elements[i]) {
330
333
  this.elements[i].setValue(value[i])
331
334
  } else {
332
335
  let n = this.newElement()
@@ -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(JSON.parse(JSON.stringify(source.value || {})))
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
- watch(() => source.value, sourceData => {
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
- lastLocalUpdate.value = sourceData[timeField]
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,8 +63,10 @@ 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
@@ -75,11 +78,16 @@ function synchronizedList(options) {
75
78
  let newSynchronized = sortedArraysMerge(
76
79
  (synchronizedElement, sourceElement, locallyAddedElement, locallyDeletedElement) => {
77
80
 
81
+ /* console.log("MERGE ELEMENT", synchronizedElement)
82
+ console.log("SOURCE ELEMENT", sourceElement)
83
+ console.log("LOCALLY ADDED", locallyAddedElement)
84
+ console.log("LOCALLY DELETED", locallyDeletedElement)*/
85
+
78
86
  if(locallyAddedElement && sourceElement) {
79
87
  obsoleteLocallyAdded.add(locallyAddedElement.id)
80
88
  }
81
89
  if(locallyDeletedElement && !sourceElement) {
82
- obsoleteLocallyDeleted.add(locallyAddedElement.id)
90
+ obsoleteLocallyDeleted.add(locallyDeletedElement.id)
83
91
  }
84
92
 
85
93
  if(synchronizedElement) {
@@ -87,14 +95,17 @@ function synchronizedList(options) {
87
95
  return null // synchronized element locally
88
96
  }
89
97
  if(sourceElement) {
90
- synchronizedElement.source.value = sourceElement
98
+ synchronizedElement.source = sourceElement
99
+ watch(() => synchronizedElement.source.value, v => console.log("DD",v))
100
+ return synchronizedElement
91
101
  } else if(locallyAddedElement) {
92
- synchronizedElement.source.value = locallyAddedElement
102
+ synchronizedElement.source = locallyAddedElement
103
+ return synchronizedElement
93
104
  } else {
94
105
  return null // synchronized element deleted
95
106
  }
96
107
  } else if(sourceElement) {
97
- console.log("CREATE SYNCHRONIZED FROM SOURCE!")
108
+ //console.log("CREATE SYNCHRONIZED FROM SOURCE!")
98
109
  return createSynchronizedElement(sourceElement)
99
110
  } else if(locallyAddedElement) {
100
111
  return createSynchronizedElement(locallyAddedElement)
@@ -113,7 +124,10 @@ function synchronizedList(options) {
113
124
  synchronizedList.value = newSynchronized
114
125
  }
115
126
 
116
- watch(() => (source.value ?? []).map(({ id }) => id), sourceIds => synchronizeFromSource())
127
+ watch(() => (source.value ?? []).map(({ id }) => id), (sourceIds, oldSourceIds) => {
128
+ console.log("SOURCE IDs changed", oldSourceIds, '=>', sourceIds)
129
+ synchronizeFromSource()
130
+ })
117
131
  synchronizeFromSource()
118
132
 
119
133
  const changed = computed(() => (synchronizedList.value.some(({ changed }) => changed.value))
@@ -130,8 +144,9 @@ function synchronizedList(options) {
130
144
  }
131
145
 
132
146
  async function deleteElement(element) {
147
+ const deleted = JSON.parse(JSON.stringify(element))
133
148
  locallyDeleted.value.push(element)
134
- await deleteAction({ ...element, ...identifiers })
149
+ await deleteAction({ ...element, ...identifiers, ...objectIdentifiers(element) })
135
150
  }
136
151
 
137
152
  async function move(element, toId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue3-components",
3
- "version": "0.2.6",
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.6",
25
- "debug": "^4.3.2",
24
+ "@live-change/vue3-ssr": "^0.2.9",
25
+ "debug": "^4.3.4",
26
26
  "mitt": "3.0.0",
27
- "vue": "^3.2.31"
27
+ "vue": "^3.2.33"
28
28
  },
29
- "gitHead": "88f2d2f0dca78f3147db250a62999f1f90d20b85"
29
+ "gitHead": "efcb8e4afc03219f588d6e782f29e4f3f74af3cf"
30
30
  }