Optimize model field replacements

This commit is contained in:
miruka
2020-04-07 11:58:26 -04:00
parent 68e344ae21
commit fd8cf4ad8d
5 changed files with 64 additions and 61 deletions

View File

@@ -49,23 +49,24 @@ QtObject {
}
function onModelItemInserted(syncId, index, item) {
// print("insert", syncId, index, item)
ModelStore.get(syncId).insert(index, item)
}
function onModelItemSet(syncId, indexThen, indexNow, changedFields){
if (indexThen === undefined) {
print("insert", syncId, indexThen, indexNow,
JSON.stringify(changedFields))
ModelStore.get(syncId).insert(indexNow, changedFields)
function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){
// print("change", syncId, oldIndex, newIndex, field, value)
const model = ModelStore.get(syncId)
model.setProperty(oldIndex, field, value)
if (oldIndex !== newIndex) model.move(oldIndex, newIndex, 1)
} else {
print("set", syncId, indexThen, indexNow,
JSON.stringify(changedFields))
const model = ModelStore.get(syncId)
model.set(indexThen, changedFields)
if (indexThen !== indexNow) model.move(indexThen, indexNow, 1)
}
}
function onModelItemDeleted(syncId, index) {
// print("del", syncId, index)
// print("delete", syncId, index)
ModelStore.get(syncId).remove(index)
}