Replace this.importHref with Polymer 2 compatible switch

this.importHref is not available anymore in Polymer 2. You have to use
Polymer.importHref instead. After consulting Polymer experts the best
way to create a hybrid code base is to use a simple switch:
(this.importHref || Polymer.importHref)

See also the Polymer 2 upgrade docs:
https://polymer-library.polymer-project.org/2.0/docs/upgrade#importhref

Change-Id: I0ab3e9ad95528989208f650fdd9876d1399b031d
This commit is contained in:
Ben Rohlfs
2019-06-06 08:47:16 +02:00
parent 2cb8ad1010
commit 218bdf47d0
4 changed files with 16 additions and 8 deletions

View File

@@ -48,9 +48,12 @@
}
},
/**
* @suppress {checkTypes}
*/
_import(url) {
return new Promise((resolve, reject) => {
this.importHref(url, resolve, reject);
(this.importHref || Polymer.importHref)(url, resolve, reject);
});
},

View File

@@ -33,11 +33,14 @@
},
},
/**
* @suppress {checkTypes}
*/
_import(url) {
if (this._urlsImported.includes(url)) { return Promise.resolve(); }
this._urlsImported.push(url);
return new Promise((resolve, reject) => {
this.importHref(url, resolve, reject);
(this.importHref || Polymer.importHref)(url, resolve, reject);
});
},

View File

@@ -80,7 +80,7 @@
for (const url of plugins) {
// onload (second param) needs to be a function. When null or undefined
// were passed, plugins were not loaded correctly.
this.importHref(
(this.importHref || Polymer.importHref)(
this._urlFor(url), () => {},
Gerrit._pluginInstallError.bind(null, `${url} import error`),
async);

View File

@@ -66,14 +66,16 @@
* Loads the dark theme document. Returns a promise that resolves with a
* custom-style DOM element.
* @return {!Promise<Element>}
* @suppress {checkTypes}
*/
getDarkTheme() {
return new Promise((resolve, reject) => {
this.importHref(this._getLibRoot() + DARK_THEME_PATH, () => {
const module = document.createElement('style', 'custom-style');
module.setAttribute('include', 'dark-theme');
resolve(module);
});
(this.importHref || Polymer.importHref)(
this._getLibRoot() + DARK_THEME_PATH, () => {
const module = document.createElement('style', 'custom-style');
module.setAttribute('include', 'dark-theme');
resolve(module);
});
});
},