@live-change/vue3-components 0.2.29 → 0.2.31
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/data.js +1 -0
- package/logic/synchronized.js +17 -6
- package/logic/synchronizedList.js +13 -7
- package/package.json +3 -3
package/logic/data.js
CHANGED
|
@@ -37,6 +37,7 @@ export function validateData(definition, data, validationType = 'validation',
|
|
|
37
37
|
if(error) return error
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
if(!data) return undefined // No data, no errors, nonEmpty validator was already checked
|
|
40
41
|
if(definition.properties) {
|
|
41
42
|
const propertyErrors = {}
|
|
42
43
|
for(let name in definition.properties) {
|
package/logic/synchronized.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, ref, watch } from "vue"
|
|
2
|
-
import { useThrottleFn } from "@vueuse/core"
|
|
2
|
+
import { useThrottleFn, useDebounceFn } from "@vueuse/core"
|
|
3
3
|
|
|
4
4
|
function copy(value) {
|
|
5
5
|
let res = JSON.parse(JSON.stringify(value || {}))
|
|
@@ -23,7 +23,8 @@ function synchronized(options) {
|
|
|
23
23
|
onSaveError = (e) => { console.error("SAVE ERROR", e) },
|
|
24
24
|
resetOnError = true,
|
|
25
25
|
recursive = false,
|
|
26
|
-
throttle =
|
|
26
|
+
throttle = 0,
|
|
27
|
+
debounce = 300,
|
|
27
28
|
autoSave = true
|
|
28
29
|
} = options
|
|
29
30
|
if(!source) throw new Error('source must be defined')
|
|
@@ -61,11 +62,16 @@ function synchronized(options) {
|
|
|
61
62
|
}
|
|
62
63
|
return true
|
|
63
64
|
}
|
|
64
|
-
const throttledSave = throttle ? useThrottleFn(save, throttle) : save
|
|
65
|
+
const throttledSave = debounce ? () => {} : (throttle ? useThrottleFn(save, throttle) : save)
|
|
66
|
+
const debouncedSave = debounce ? useDebounceFn(save, throttle)
|
|
67
|
+
: (throttle ? useDebounceFn(save, throttle) : () => {}) // debounce after throttle
|
|
65
68
|
watch(() => synchronizedJSON.value, json => {
|
|
66
69
|
lastLocalUpdate.value = timeSource()
|
|
67
70
|
onChange()
|
|
68
|
-
if(autoSave)
|
|
71
|
+
if(autoSave) {
|
|
72
|
+
throttledSave()
|
|
73
|
+
debouncedSave()
|
|
74
|
+
}
|
|
69
75
|
})
|
|
70
76
|
//console.log("WATCH SOURCE VALUE", source.value)
|
|
71
77
|
watch(() => JSON.stringify(source.value), sourceJson => {
|
|
@@ -101,7 +107,9 @@ function synchronized(options) {
|
|
|
101
107
|
}
|
|
102
108
|
return true
|
|
103
109
|
}
|
|
104
|
-
const throttledSave = throttle ? useThrottleFn(save, throttle) : save
|
|
110
|
+
const throttledSave = debounce ? () => {} : (throttle ? useThrottleFn(save, throttle) : save)
|
|
111
|
+
const debouncedSave = debounce ? useDebounceFn(save, throttle)
|
|
112
|
+
: (throttle ? useDebounceFn(save, throttle) : () => {}) // debounce after throttle
|
|
105
113
|
const synchronizedComputed = computed({
|
|
106
114
|
get: () => {
|
|
107
115
|
const localTime = ((local.value && local.value[timeField]) ?? '')
|
|
@@ -111,7 +119,10 @@ function synchronized(options) {
|
|
|
111
119
|
set: newValue => {
|
|
112
120
|
local.value = { ...newValue, [timeField]: timeSource() }
|
|
113
121
|
onChange()
|
|
114
|
-
if(autoSave)
|
|
122
|
+
if(autoSave) {
|
|
123
|
+
throttledSave()
|
|
124
|
+
debouncedSave()
|
|
125
|
+
}
|
|
115
126
|
}
|
|
116
127
|
})
|
|
117
128
|
return { value: synchronizedComputed, save, changed }
|
|
@@ -45,6 +45,7 @@ function synchronizedList(options) {
|
|
|
45
45
|
move: moveAction,
|
|
46
46
|
identifiers = {},
|
|
47
47
|
objectIdentifiers = object => ({ id: object.id }),
|
|
48
|
+
prefix = '',
|
|
48
49
|
timeField = 'lastUpdate',
|
|
49
50
|
timeSource = () => (new Date()).toISOString(),
|
|
50
51
|
onChange = () => {},
|
|
@@ -114,14 +115,15 @@ function synchronizedList(options) {
|
|
|
114
115
|
return createSynchronizedElement(locallyAddedElement)
|
|
115
116
|
}
|
|
116
117
|
}, synchronizedList.value, source.value || [], locallyAdded.value, locallyDeleted.value)
|
|
117
|
-
|
|
118
|
+
console.log("OBSOLETE", obsoleteLocallyAdded, obsoleteLocallyDeleted)
|
|
119
|
+
if(obsoleteLocallyAdded.size > 0) {
|
|
118
120
|
locallyAdded.value = locallyAdded.value.filter(
|
|
119
|
-
locallyAddedElement => obsoleteLocallyAdded.has(locallyAddedElement.id)
|
|
121
|
+
locallyAddedElement => !obsoleteLocallyAdded.has(locallyAddedElement.id)
|
|
120
122
|
)
|
|
121
123
|
}
|
|
122
|
-
if(obsoleteLocallyDeleted.
|
|
124
|
+
if(obsoleteLocallyDeleted.size > 0) {
|
|
123
125
|
locallyDeleted.value = locallyDeleted.value.filter(
|
|
124
|
-
locallyDeletedElement => obsoleteLocallyDeleted.has(locallyDeletedElement.id)
|
|
126
|
+
locallyDeletedElement => !obsoleteLocallyDeleted.has(locallyDeletedElement.id)
|
|
125
127
|
)
|
|
126
128
|
}
|
|
127
129
|
synchronizedList.value = newSynchronized
|
|
@@ -142,8 +144,12 @@ function synchronizedList(options) {
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
async function insert(element) {
|
|
145
|
-
locallyAdded.value.push(
|
|
146
|
-
|
|
147
|
+
locallyAdded.value.push({
|
|
148
|
+
...element,
|
|
149
|
+
to: element.id,
|
|
150
|
+
id: prefix + element.id
|
|
151
|
+
})
|
|
152
|
+
await insertAction({ ...element, [timeField]: timeSource(), ...identifiers, ...objectIdentifiers(element) })
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
async function deleteElement(element) {
|
|
@@ -157,7 +163,7 @@ function synchronizedList(options) {
|
|
|
157
163
|
}
|
|
158
164
|
|
|
159
165
|
const synchronizedValue = computed(() => synchronizedList.value.map(synchronizedElement => synchronizedElement.value))
|
|
160
|
-
return { value: synchronizedValue, save, changed, insert, delete: deleteElement, move }
|
|
166
|
+
return { value: synchronizedValue, save, changed, insert, delete: deleteElement, move, locallyAdded }
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
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.31",
|
|
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.31",
|
|
25
25
|
"debug": "^4.3.4",
|
|
26
26
|
"mitt": "3.0.0",
|
|
27
27
|
"vue": "^3.2.47"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "5a36954b2ff7c5ec81fbbddb4d017d9127488540"
|
|
30
30
|
}
|