Skip to content

studying sync.js to (start) to understand how Zotero does synchronization

This morning I was studying how Zotero performs synchronization among libraries distributed in different Firefox profiles via Zotero sync server. Specifically, I printed out /extension/tags/1.5-sync3.5/chrome/content/zotero/xpcom/sync.js to decipher some off its workings. My goal wasn't to understand all the code, which gets pretty complicated, because of the complexities of things like conflict resolution. Rather, my focus is on how collections and items are serialized.

Here are couple of things I figured out:

  • When you hit the sync button, you invoke Zotero.Sync.Runner.sync
  • Because I hadn't seen the use of __defineGetter__ and __defineSetter__ in the Zotero 1.0.7 code, I didn't realize that these functions are actually part of JavaScript 1.5 — but according to Defining Getters and Setters – MDC, "Prior to Firefox 3.0, getter and setter are not supported for DOM Elements. Older versions of Firefox silently fail. If exceptions are needed for those, changing the prototype of HTMLElement (HTMLElement.prototype.__define[SG]etter__) and throwing an exception is a workaround. "
  • Zotero.Item.prototype.serialize is worthwhile studying for how to package up Zotero items in preparation for serialization (to, say, XML)
  • sync.js was the first time I had seen the use of [ E4X] to process XML in JavaScript. ("E4X is implemented (at least partially) in SpiderMonkey (Gecko's JavaScript engine) and in Rhino (JavaScript engine written in Java)."
  • Zotero.Sync.Server.Data..itemToXML shows how Zotero items are serialized to XML interpreted by the Zotero sync server.

Post a Comment

You must be logged in to post a comment.