@live-change/vue3-components 0.2.5 → 0.2.6
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/logic/synchronizedList.js +20 -20
- package/package.json +3 -3
|
@@ -40,7 +40,7 @@ function synchronizedList(options) {
|
|
|
40
40
|
source,
|
|
41
41
|
update: updateAction,
|
|
42
42
|
insert: insertAction,
|
|
43
|
-
|
|
43
|
+
delete: deleteAction,
|
|
44
44
|
move: moveAction,
|
|
45
45
|
identifiers = {},
|
|
46
46
|
objectIdentifiers = object => ({ id: object.id }),
|
|
@@ -59,7 +59,7 @@ function synchronizedList(options) {
|
|
|
59
59
|
if(!source) throw new Error('source must be defined')
|
|
60
60
|
const synchronizedList = ref([])
|
|
61
61
|
const locallyAdded = ref([])
|
|
62
|
-
const
|
|
62
|
+
const locallyDeleted = ref([])
|
|
63
63
|
|
|
64
64
|
function createSynchronizedElement(sourceData) {
|
|
65
65
|
const elementSource = ref(sourceData)
|
|
@@ -69,19 +69,21 @@ function synchronizedList(options) {
|
|
|
69
69
|
return synchronizedElement
|
|
70
70
|
}
|
|
71
71
|
function synchronizeFromSource() {
|
|
72
|
+
console.log("SYNCHRONIZE FROM SOURCE!")
|
|
72
73
|
let obsoleteLocallyAdded = new Set()
|
|
73
|
-
let
|
|
74
|
+
let obsoleteLocallyDeleted = new Set()
|
|
74
75
|
let newSynchronized = sortedArraysMerge(
|
|
75
|
-
(synchronizedElement, sourceElement, locallyAddedElement,
|
|
76
|
+
(synchronizedElement, sourceElement, locallyAddedElement, locallyDeletedElement) => {
|
|
77
|
+
|
|
76
78
|
if(locallyAddedElement && sourceElement) {
|
|
77
79
|
obsoleteLocallyAdded.add(locallyAddedElement.id)
|
|
78
80
|
}
|
|
79
|
-
if(
|
|
80
|
-
|
|
81
|
+
if(locallyDeletedElement && !sourceElement) {
|
|
82
|
+
obsoleteLocallyDeleted.add(locallyAddedElement.id)
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
if(synchronizedElement) {
|
|
84
|
-
if(
|
|
86
|
+
if(locallyDeletedElement) {
|
|
85
87
|
return null // synchronized element locally
|
|
86
88
|
}
|
|
87
89
|
if(sourceElement) {
|
|
@@ -97,27 +99,25 @@ function synchronizedList(options) {
|
|
|
97
99
|
} else if(locallyAddedElement) {
|
|
98
100
|
return createSynchronizedElement(locallyAddedElement)
|
|
99
101
|
}
|
|
100
|
-
}, synchronizedList.value, source.value || [], locallyAdded.value,
|
|
102
|
+
}, synchronizedList.value, source.value || [], locallyAdded.value, locallyDeleted.value)
|
|
101
103
|
if(obsoleteLocallyAdded.length > 0) {
|
|
102
104
|
locallyAdded.value = locallyAdded.value.filter(
|
|
103
105
|
locallyAddedElement => obsoleteLocallyAdded.has(locallyAddedElement.id)
|
|
104
106
|
)
|
|
105
107
|
}
|
|
106
|
-
if(
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
if(obsoleteLocallyDeleted.length > 0) {
|
|
109
|
+
locallyDeleted.value = locallyDeleted.value.filter(
|
|
110
|
+
locallyDeletedElement => obsoleteLocallyDeleted.has(locallyDeletedElement.id)
|
|
109
111
|
)
|
|
110
112
|
}
|
|
111
113
|
synchronizedList.value = newSynchronized
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
watch(() => sourceIds, () => synchronizeFromSource())
|
|
116
|
-
|
|
116
|
+
watch(() => (source.value ?? []).map(({ id }) => id), sourceIds => synchronizeFromSource())
|
|
117
117
|
synchronizeFromSource()
|
|
118
118
|
|
|
119
119
|
const changed = computed(() => (synchronizedList.value.some(({ changed }) => changed.value))
|
|
120
|
-
|| locallyAdded.length ||
|
|
120
|
+
|| locallyAdded.length || locallyDeleted.length)
|
|
121
121
|
|
|
122
122
|
async function save() {
|
|
123
123
|
const results = await Promise.app(synchronizedList.value.map(synchronizedElement => synchronizedElement.save()))
|
|
@@ -125,13 +125,13 @@ function synchronizedList(options) {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
async function insert(element) {
|
|
128
|
-
locallyAdded.push(element)
|
|
128
|
+
locallyAdded.value.push(element)
|
|
129
129
|
await insertAction({ ...element, [timeField]: timeSource(), ...identifiers })
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
async function
|
|
133
|
-
|
|
134
|
-
await
|
|
132
|
+
async function deleteElement(element) {
|
|
133
|
+
locallyDeleted.value.push(element)
|
|
134
|
+
await deleteAction({ ...element, ...identifiers })
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
async function move(element, toId) {
|
|
@@ -139,7 +139,7 @@ function synchronizedList(options) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
const synchronizedValue = computed(() => synchronizedList.value.map(synchronizedElement => synchronizedElement.value))
|
|
142
|
-
return { value: synchronizedValue, save, changed, insert,
|
|
142
|
+
return { value: synchronizedValue, save, changed, insert, delete: deleteElement, move }
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
export default synchronizedList
|
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.6",
|
|
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.
|
|
24
|
+
"@live-change/vue3-ssr": "^0.2.6",
|
|
25
25
|
"debug": "^4.3.2",
|
|
26
26
|
"mitt": "3.0.0",
|
|
27
27
|
"vue": "^3.2.31"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "88f2d2f0dca78f3147db250a62999f1f90d20b85"
|
|
30
30
|
}
|