haystack / listit

The listit lightweight notetaking client
http://listit.csail.mit.edu/
MIT License
9 stars 6 forks source link

Syncs notes when a note is saved or edited. #216

Open deannah opened 10 years ago

deannah commented 10 years ago

fixes #200

Stebalien commented 10 years ago

Instead of overriding those functions, you should be able to listen to "add" signals emitted by L.notebook.get("notes").

Also, while this is a stop-gap solution, it's really inefficient. A full sync (what you are doing here) first downloads all of the notes and then pushes the changed notes to the server. Instead, you should only push updated notes. You could do this by calling L.server.pushNotes(). However, if you do this, you will have to handle note conflicts.

Currently, L.server.commitNotes() only reports errors on the console, it doesn't return an error status if a note fails to push because (a) this can only happen if some other instance updated the note on the server since this instance last pulled the note and (b) it'll just get around to syncing that note on the next sync.

Instance A Instance B
pull notes -> [a, b, c, d]
pull notes -> [a, b, c, d]
push notes (update notes a, c, d) -> {a: success, c: success, d: success}
push notes (update note b, c) -> {b: success, c: failure}
.... next sync ....
pull notes -> [a, b, c', d]
push notes -> {c: success}

So you should probably modify commitNotes to return some "temporary failure" status to pushNotes (which can in turn call the error callback). You can then handle this transient error by triggering a full sync.