www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit f8ac21d89134869321c1eadcfdeac0b6f6d96f31
parent 90f4996d9d8f2d3b426deef0d073e4aede6fe92c
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sat, 25 Apr 2015 02:18:11 -0400

Return object instead of array from Zotero.DataObjects.getLibraryAndKeyFromID()

Object contains 'libraryID' and 'key' properties

This is due to changed array destructuring behavior in Firefox. Previously,
`var [foo, bar] = maybeArrayMaybeFalse()` always worked, leaving foo and bar
undefined if the function returned false. Now (with ES6, I assume), if the
function returns false it results in a "false[Symbol.iterator] is not a
function" error. But `var {libraryID, key} = false` works as expected, leaving
both values undefined, so instead we can just return an object with those
properties from getLibraryAndKeyFromID(). To assign to different variables, use
`var {libraryID, key: parentItemKey} = ...`.

Diffstat:
Mchrome/content/zotero/xpcom/api.js | 2+-
Mchrome/content/zotero/xpcom/attachments.js | 16++++++++++------
Mchrome/content/zotero/xpcom/data/dataObject.js | 2+-
Mchrome/content/zotero/xpcom/data/dataObjects.js | 7++++---
Mchrome/content/zotero/xpcom/data/item.js | 2+-
Mchrome/content/zotero/xpcom/search.js | 4++--
Mchrome/content/zotero/zoteroPane.js | 2+-
7 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/chrome/content/zotero/xpcom/api.js b/chrome/content/zotero/xpcom/api.js @@ -130,7 +130,7 @@ Zotero.API = { // Filter results by item key if (params.itemKey) { ids = ids.filter(function (id) { - var [libraryID, key] = Zotero.Items.getLibraryAndKeyFromID(id); + var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(id); return params.itemKey.indexOf(key) !== -1; }); } diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js @@ -50,7 +50,8 @@ Zotero.Attachments = new function(){ // Create a new attachment var attachmentItem = new Zotero.Item('attachment'); if (parentItemID) { - let [parentLibraryID, parentKey] = Zotero.Items.getLibraryAndKeyFromID(parentItemID); + let {libraryID: parentLibraryID, key: parentKey} = + Zotero.Items.getLibraryAndKeyFromID(parentItemID); attachmentItem.libraryID = parentLibraryID; } else if (libraryID) { @@ -151,7 +152,7 @@ Zotero.Attachments = new function(){ yield Zotero.DB.executeTransaction(function* () { // Create a new attachment var attachmentItem = new Zotero.Item('attachment'); - let [libraryID, parentKey] = Zotero.Items.getLibraryAndKeyFromID(parentItemID); + let {libraryID, key: parentKey} = Zotero.Items.getLibraryAndKeyFromID(parentItemID); attachmentItem.libraryID = libraryID; attachmentItem.setField('title', title); attachmentItem.setField('url', url); @@ -318,7 +319,8 @@ Zotero.Attachments = new function(){ attachmentItem.libraryID = libraryID; } else if (parentItemID) { - let [parentLibraryID, parentKey] = Zotero.Items.getLibraryAndKeyFromID(parentItemID); + let {libraryID: parentLibraryID, key: parentKey} = + Zotero.Items.getLibraryAndKeyFromID(parentItemID); attachmentItem.libraryID = parentLibraryID; } attachmentItem.setField('title', title ? title : fileName); @@ -627,7 +629,8 @@ Zotero.Attachments = new function(){ attachmentItem.libraryID = libraryID; } else if (parentItemID) { - let [parentLibraryID, parentKey] = Zotero.Items.getLibraryAndKeyFromID(parentItemID); + let {libraryID: parentLibraryID, key: parentKey} = + Zotero.Items.getLibraryAndKeyFromID(parentItemID); Zotero.debug('==-='); Zotero.debug(parentItemID); Zotero.debug(parentLibraryID); @@ -862,7 +865,7 @@ Zotero.Attachments = new function(){ if (!itemID) { throw new Error("itemID not provided"); } - var [libraryID, key] = Zotero.Items.getLibraryAndKeyFromID(itemID); + var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID); if (!key) { throw new Error("Item " + itemID + " not found"); } @@ -1287,7 +1290,8 @@ Zotero.Attachments = new function(){ return Zotero.DB.executeTransaction(function* () { var attachmentItem = new Zotero.Item('attachment'); if (parentItemID) { - let [parentLibraryID, parentKey] = Zotero.Items.getLibraryAndKeyFromID(parentItemID); + let {libraryID: parentLibraryID, key: parentKey} = + Zotero.Items.getLibraryAndKeyFromID(parentItemID); if (parentLibraryID && linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) { throw new Error("Cannot save linked file in non-local library"); } diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js @@ -161,7 +161,7 @@ Zotero.DataObject.prototype._getParentID = function () { Zotero.DataObject.prototype._setParentID = function (id) { return this._setParentKey( id - ? this.ObjectsClass.getLibraryAndKeyFromID(Zotero.DataObjectUtilities.checkDataID(id))[1] + ? this.ObjectsClass.getLibraryAndKeyFromID(Zotero.DataObjectUtilities.checkDataID(id)).key : null ); } diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -270,10 +270,11 @@ Zotero.DataObjects.prototype.exists = function (itemID) { /** - * @return {Array} Array with libraryID and key + * @return {Object} Object with 'libraryID' and 'key' */ Zotero.DataObjects.prototype.getLibraryAndKeyFromID = function (id) { - return this._objectKeys[id] ? this._objectKeys[id] : false; + var lk = this._objectKeys[id]; + return lk ? { libraryID: lk[0], key: lk[1] } : false; } @@ -413,7 +414,7 @@ Zotero.DataObjects.prototype.unload = function () { var ids = Zotero.flattenArguments(arguments); for (var i=0; i<ids.length; i++) { let id = ids[i]; - let [libraryID, key] = this.getLibraryAndKeyFromID(id); + let {libraryID, key} = this.getLibraryAndKeyFromID(id); if (key) { delete this._objectIDs[libraryID][key]; delete this._objectKeys[id]; diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -4103,7 +4103,7 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options, patc // Collections yield this.loadCollections(); obj.collections = this.getCollections().map(function (id) { - return this.ContainerObjectsClass.getLibraryAndKeyFromID(id)[1]; + return this.ContainerObjectsClass.getLibraryAndKeyFromID(id).key; }.bind(this)); // Relations diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js @@ -347,7 +347,7 @@ Zotero.Search.prototype.addCondition = function (condition, operator, value, req } // Shortcut to add a collection (which must be loaded first) else if (condition == 'collectionID') { - let [libraryID, key] = Zotero.Collections.getLibraryAndKeyFromID(value); + let {libraryID, key} = Zotero.Collections.getLibraryAndKeyFromID(value); if (!key) { let msg = "Collection " + value + " not found"; Zotero.debug(msg, 2); @@ -362,7 +362,7 @@ Zotero.Search.prototype.addCondition = function (condition, operator, value, req } // Shortcut to add a saved search (which must be loaded first) else if (condition == 'savedSearchID') { - let [libraryID, key] = Zotero.Searches.getLibraryAndKeyFromID(value); + let {libraryID, key} = Zotero.Searches.getLibraryAndKeyFromID(value); if (!key) { let msg = "Saved search " + value + " not found"; Zotero.debug(msg, 2); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -3126,7 +3126,7 @@ var ZoteroPane = new function() var str = event.currentTarget.ownerDocument.popupNode.ownerDocument.defaultView.getSelection().toString(); var uri = event.currentTarget.ownerDocument.popupNode.ownerDocument.location.href; var itemID = ZoteroPane.addItemFromPage(); - var [libraryID, key] = Zotero.Items.getLibraryAndKeyFromID(itemID); + var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID); ZoteroPane.newNote(false, key, str, uri) };