Skip to content

Commit ec88841

Browse files
committed
workaround to make unchanged $updated available
closes #27
1 parent 9fec78d commit ec88841

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/add.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export default async function add(table, path, options = {}) {
2525
debug('create hook', { tableName: table.name, doc: { ...doc }})
2626
})
2727

28-
// Update sync properties on any document update
29-
table.hook('updating', (updates, id) => {
28+
// Update sync properties on any document update (workaound to keep the current $updated value)
29+
table.hook('updating', (updates, id, doc) => {
3030
const additionalUpdates = {
31-
$updated: updates.$updated || Date.now(),
32-
$synchronized: updates.$synchronized || 0
31+
$updated: updates.$updated === 'keep' ? doc.$updated : (updates.$updated || Date.now()),
32+
$synchronized: updates.$synchronized || 0,
3333
}
3434
debug('update hook', { tableName: table.name, id, updates: { ...updates, ...additionalUpdates } })
3535
return additionalUpdates

lib/syncToRemote.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export default async function syncToRemote(table, api, remoteTable) {
6464
// Deletion flag is not set
6565
} else {
6666

67-
// Define the updated local doc
68-
const updatedLocalDoc = { $updated: localDoc.$updated, $synchronized: Date.now() }
67+
// Define the updated local doc (workaround to keep the current $updated value)
68+
const updatedLocalDoc = { $updated: 'keep', $synchronized: Date.now() }
6969

7070
// Update the local doc
7171
await table.update(localDoc.id, updatedLocalDoc)

0 commit comments

Comments
 (0)