Remove use of Promise.tap() from Bluebird and our own Promise.check()
This commit is contained in:
parent
e48d069687
commit
ca3fd80825
3 changed files with 12 additions and 28 deletions
|
@ -306,8 +306,9 @@
|
||||||
// Page count
|
// Page count
|
||||||
if (this.displayPages) {
|
if (this.displayPages) {
|
||||||
Zotero.Fulltext.getPages(this.item.id)
|
Zotero.Fulltext.getPages(this.item.id)
|
||||||
.tap(() => Zotero.Promise.check(this.item))
|
|
||||||
.then(function (pages) {
|
.then(function (pages) {
|
||||||
|
if (!this.item) return;
|
||||||
|
|
||||||
pages = pages ? pages.total : null;
|
pages = pages ? pages.total : null;
|
||||||
if (pages) {
|
if (pages) {
|
||||||
this._id("pages-label").value = Zotero.getString('itemFields.pages')
|
this._id("pages-label").value = Zotero.getString('itemFields.pages')
|
||||||
|
@ -337,8 +338,9 @@
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.item.attachmentModificationTime
|
this.item.attachmentModificationTime
|
||||||
.tap(() => Zotero.Promise.check(this._id))
|
|
||||||
.then(function (mtime) {
|
.then(function (mtime) {
|
||||||
|
if (!this._id) return;
|
||||||
|
|
||||||
if (mtime) {
|
if (mtime) {
|
||||||
this._id("dateModified").value = new Date(mtime).toLocaleString();
|
this._id("dateModified").value = new Date(mtime).toLocaleString();
|
||||||
}
|
}
|
||||||
|
@ -353,10 +355,10 @@
|
||||||
// Full-text index information
|
// Full-text index information
|
||||||
if (this.displayIndexed) {
|
if (this.displayIndexed) {
|
||||||
this.updateItemIndexedState()
|
this.updateItemIndexedState()
|
||||||
.tap(() => Zotero.Promise.check(this.item))
|
|
||||||
.then(function () {
|
.then(function () {
|
||||||
|
if (!this.item) return;
|
||||||
indexStatusRow.hidden = false;
|
indexStatusRow.hidden = false;
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
indexStatusRow.hidden = true;
|
indexStatusRow.hidden = true;
|
||||||
|
@ -533,8 +535,9 @@
|
||||||
var indexStatus = this._id('index-status');
|
var indexStatus = this._id('index-status');
|
||||||
var reindexButton = this._id('reindex');
|
var reindexButton = this._id('reindex');
|
||||||
|
|
||||||
var status = yield Zotero.Fulltext.getIndexedState(this.item)
|
var status = yield Zotero.Fulltext.getIndexedState(this.item);
|
||||||
.tap(() => Zotero.Promise.check(this.item));
|
if (!this.item) return;
|
||||||
|
|
||||||
var str = 'fulltext.indexState.';
|
var str = 'fulltext.indexState.';
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Zotero.Fulltext.INDEX_STATE_UNAVAILABLE:
|
case Zotero.Fulltext.INDEX_STATE_UNAVAILABLE:
|
||||||
|
@ -563,8 +566,8 @@
|
||||||
|
|
||||||
var show = false;
|
var show = false;
|
||||||
if (this.editable) {
|
if (this.editable) {
|
||||||
show = yield Zotero.Fulltext.canReindex(this.item)
|
show = yield Zotero.Fulltext.canReindex(this.item);
|
||||||
.tap(() => Zotero.Promise.check(this.item));
|
if (!this.item) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
|
|
|
@ -172,25 +172,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
this.uiReadyDeferred = Zotero.Promise.defer();
|
this.uiReadyDeferred = Zotero.Promise.defer();
|
||||||
this.uiReadyPromise = this.uiReadyDeferred.promise;
|
this.uiReadyPromise = this.uiReadyDeferred.promise;
|
||||||
|
|
||||||
// Add a function to Zotero.Promise to check whether a value is still defined, and if not
|
|
||||||
// to throw a specific error that's ignored by the unhandled rejection handler in
|
|
||||||
// bluebird.js. This allows for easily cancelling promises when they're no longer
|
|
||||||
// needed, for example after a binding is destroyed.
|
|
||||||
//
|
|
||||||
// Example usage:
|
|
||||||
//
|
|
||||||
// getAsync.tap(() => Zotero.Promise.check(this.mode))
|
|
||||||
//
|
|
||||||
// If the binding is destroyed while getAsync() is being resolved and this.mode no longer
|
|
||||||
// exists, subsequent lines won't be run, and nothing will be logged to the console.
|
|
||||||
this.Promise.check = function (val) {
|
|
||||||
if (!val && val !== 0) {
|
|
||||||
let e = new Error;
|
|
||||||
e.name = "ZoteroPromiseInterrupt";
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (options) {
|
if (options) {
|
||||||
let opts = [
|
let opts = [
|
||||||
'openPane',
|
'openPane',
|
||||||
|
|
|
@ -21,7 +21,7 @@ Promise.defer = function() {
|
||||||
}
|
}
|
||||||
// TEMP: Only turn on if debug logging enabled?
|
// TEMP: Only turn on if debug logging enabled?
|
||||||
Promise.onPossiblyUnhandledRejection((e, promise) => {
|
Promise.onPossiblyUnhandledRejection((e, promise) => {
|
||||||
if (e.name == 'ZoteroPromiseInterrupt' || e.handledRejection) {
|
if (e.handledRejection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue