ES6ify /gr-js-api-interface/*

Bug: Issue 6179
Change-Id: I9e0672c64a6793ba019b7b4af65f22eaacd7e2f5
This commit is contained in:
Kasper Nilsson
2017-05-15 16:39:47 -07:00
parent 7bb7ef60ae
commit 75214af17f
6 changed files with 185 additions and 184 deletions

View File

@@ -22,13 +22,13 @@
}
GrChangeActionsInterface.prototype.addPrimaryActionKey = function(key) {
if (this._el.primaryActionKeys.indexOf(key) !== -1) { return; }
if (this._el.primaryActionKeys.includes(key)) { return; }
this._el.push('primaryActionKeys', key);
};
GrChangeActionsInterface.prototype.removePrimaryActionKey = function(key) {
this._el.primaryActionKeys = this._el.primaryActionKeys.filter(function(k) {
this._el.primaryActionKeys = this._el.primaryActionKeys.filter(k => {
return k !== key;
});
};

View File

@@ -37,43 +37,44 @@ breaking changes to gr-change-actions wont be noticed.
</test-fixture>
<script>
suite('gr-js-api-interface tests', function() {
var element;
var changeActions;
suite('gr-js-api-interface tests', () => {
let element;
let changeActions;
// Because deepEqual doesnt behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
for (let i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
setup(function() {
setup(() => {
element = fixture('basic');
element.change = {};
element._hasKnownChainState = false;
var plugin;
Gerrit.install(function(p) { plugin = p; }, '0.1',
let plugin;
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeActions = plugin.changeActions();
});
teardown(function() {
teardown(() => {
changeActions = null;
});
test('property existence', function() {
[
test('property existence', () => {
const properties = [
'ActionType',
'ChangeActions',
'RevisionActions',
].forEach(function(p) {
];
for (const p of properties) {
assertArraysEqual(changeActions[p], element[p]);
});
}
});
test('add/remove primary action keys', function() {
test('add/remove primary action keys', () => {
element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['foo']);
@@ -89,34 +90,34 @@ breaking changes to gr-change-actions wont be noticed.
assertArraysEqual(element.primaryActionKeys, []);
});
test('action buttons', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
var handler = sinon.spy();
test('action buttons', done => {
const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
const handler = sinon.spy();
changeActions.addTapListener(key, handler);
flush(function() {
flush(() => {
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.removeTapListener(key, handler);
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.remove(key);
flush(function() {
flush(() => {
assert.isNull(element.$$('[data-action-key="' + key + '"]'));
done();
});
});
});
test('action button properties', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
test('action button properties', done => {
const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(() => {
const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.equal(button.getAttribute('data-label'), 'Bork!');
assert.isNotOk(button.disabled);
changeActions.setLabel(key, 'Yo');
changeActions.setEnabled(key, false);
flush(function() {
flush(() => {
assert.equal(button.getAttribute('data-label'), 'Yo');
assert.isTrue(button.disabled);
done();
@@ -124,30 +125,30 @@ breaking changes to gr-change-actions wont be noticed.
});
});
test('hide action buttons', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
test('hide action buttons', done => {
const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(() => {
const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.isFalse(button.hasAttribute('hidden'));
changeActions.setActionHidden(
changeActions.ActionType.REVISION, key, true);
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
flush(() => {
const button = element.$$('[data-action-key="' + key + '"]');
assert.isNotOk(button);
done();
});
});
});
test('move action button to overflow', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(function() {
test('move action button to overflow', done => {
const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(() => {
assert.isTrue(element.$.moreActions.hidden);
assert.isOk(element.$$('[data-action-key="' + key + '"]'));
changeActions.setActionOverflow(
changeActions.ActionType.REVISION, key, true);
flush(function() {
flush(() => {
assert.isNotOk(element.$$('[data-action-key="' + key + '"]'));
assert.isFalse(element.$.moreActions.hidden);
assert.strictEqual(element.$.moreActions.items[0].name, 'Bork!');
@@ -156,17 +157,19 @@ breaking changes to gr-change-actions wont be noticed.
});
});
test('change actions priority', function(done) {
var key1 = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
var key2 = changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
flush(function() {
var buttons =
test('change actions priority', done => {
const key1 =
changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
const key2 =
changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
flush(() => {
let buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key1);
assert.equal(buttons[1].getAttribute('data-action-key'), key2);
changeActions.setActionPriority(
changeActions.ActionType.REVISION, key1, 10);
flush(function() {
flush(() => {
buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key2);

View File

@@ -37,35 +37,35 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-change-reply-js-api tests', function() {
var element;
var sandbox;
var changeReply;
suite('gr-change-reply-js-api tests', () => {
let element;
let sandbox;
let changeReply;
setup(function() {
setup(() => {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getAccount: function() { return Promise.resolve(null); },
getConfig() { return Promise.resolve({}); },
getAccount() { return Promise.resolve(null); },
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
var plugin;
Gerrit.install(function(p) { plugin = p; }, '0.1',
let plugin;
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeReply = plugin.changeReply();
});
teardown(function() {
teardown(() => {
changeReply = null;
sandbox.restore();
});
test('calls', function() {
var setLabelValueStub = sinon.stub(element, 'setLabelValue');
test('calls', () => {
const setLabelValueStub = sinon.stub(element, 'setLabelValue');
changeReply.setLabelValue('My-Label', '+1337');
assert(setLabelValueStub.calledWithExactly('My-Label', '+1337'));
var sendStub = sinon.stub(element, 'send');
const sendStub = sinon.stub(element, 'send');
changeReply.send(false);
assert(sendStub.calledWithExactly(false));
});

View File

@@ -14,7 +14,7 @@
(function() {
'use strict';
var EventType = {
const EventType = {
HISTORY: 'history',
LABEL_CHANGE: 'labelchange',
SHOW_CHANGE: 'showchange',
@@ -25,7 +25,7 @@
POST_REVERT: 'postrevert',
};
var Element = {
const Element = {
CHANGE_ACTIONS: 'changeactions',
REPLY_DIALOG: 'replydialog',
};
@@ -44,11 +44,11 @@
},
},
Element: Element,
EventType: EventType,
Element,
EventType,
handleEvent: function(type, detail) {
Gerrit.awaitPluginsLoaded().then(function() {
handleEvent(type, detail) {
Gerrit.awaitPluginsLoaded().then(() => {
switch (type) {
case EventType.HISTORY:
this._handleHistory(detail);
@@ -67,27 +67,27 @@
type);
break;
}
}.bind(this));
});
},
addElement: function(key, el) {
addElement(key, el) {
this._elements[key] = el;
},
getElement: function(key) {
getElement(key) {
return this._elements[key];
},
addEventCallback: function(eventName, callback) {
addEventCallback(eventName, callback) {
if (!this._eventCallbacks[eventName]) {
this._eventCallbacks[eventName] = [];
}
this._eventCallbacks[eventName].push(callback);
},
canSubmitChange: function(change, revision) {
var submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
var cancelSubmit = submitCallbacks.some(function(callback) {
canSubmitChange(change, revision) {
const submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
const cancelSubmit = submitCallbacks.some(callback => {
try {
return callback(change, revision) === false;
} catch (err) {
@@ -99,28 +99,29 @@
return !cancelSubmit;
},
_removeEventCallbacks: function() {
for (var k in EventType) {
_removeEventCallbacks() {
for (const k in EventType) {
if (!EventType.hasOwnProperty(k)) { continue; }
this._eventCallbacks[EventType[k]] = [];
}
},
_handleHistory: function(detail) {
this._getEventCallbacks(EventType.HISTORY).forEach(function(cb) {
_handleHistory(detail) {
for (const cb of this._getEventCallbacks(EventType.HISTORY)) {
try {
cb(detail.path);
} catch (err) {
console.error(err);
}
});
}
},
_handleShowChange: function(detail) {
this._getEventCallbacks(EventType.SHOW_CHANGE).forEach(function(cb) {
var change = detail.change;
var patchNum = detail.patchNum;
var revision;
for (var rev in change.revisions) {
_handleShowChange(detail) {
for (const cb of this._getEventCallbacks(EventType.SHOW_CHANGE)) {
const change = detail.change;
const patchNum = detail.patchNum;
let revision;
for (const rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
revision = change.revisions[rev];
break;
@@ -131,67 +132,63 @@
} catch (err) {
console.error(err);
}
});
}
},
handleCommitMessage: function(change, msg) {
this._getEventCallbacks(EventType.COMMIT_MSG_EDIT).forEach(
function(cb) {
try {
cb(change, msg);
} catch (err) {
console.error(err);
}
}
);
handleCommitMessage(change, msg) {
for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
try {
cb(change, msg);
} catch (err) {
console.error(err);
}
}
},
_handleComment: function(detail) {
this._getEventCallbacks(EventType.COMMENT).forEach(function(cb) {
_handleComment(detail) {
for (const cb of this._getEventCallbacks(EventType.COMMENT)) {
try {
cb(detail.node);
} catch (err) {
console.error(err);
}
});
}
},
_handleLabelChange: function(detail) {
this._getEventCallbacks(EventType.LABEL_CHANGE).forEach(function(cb) {
_handleLabelChange(detail) {
for (const cb of this._getEventCallbacks(EventType.LABEL_CHANGE)) {
try {
cb(detail.change);
} catch (err) {
console.error(err);
}
});
}
},
modifyRevertMsg: function(change, revertMsg, origMsg) {
this._getEventCallbacks(EventType.REVERT).forEach(function(callback) {
modifyRevertMsg(change, revertMsg, origMsg) {
for (const cb of this._getEventCallbacks(EventType.REVERT)) {
try {
revertMsg = callback(change, revertMsg, origMsg);
revertMsg = cb(change, revertMsg, origMsg);
} catch (err) {
console.error(err);
}
});
}
return revertMsg;
},
getLabelValuesPostRevert: function(change) {
var labels = {};
this._getEventCallbacks(EventType.POST_REVERT).forEach(
function(callback) {
try {
labels = callback(change);
} catch (err) {
console.error(err);
}
}
);
getLabelValuesPostRevert(change) {
let labels = {};
for (const cb of this._getEventCallbacks(EventType.POST_REVERT)) {
try {
labels = cb(change);
} catch (err) {
console.error(err);
}
}
return labels;
},
_getEventCallbacks: function(type) {
_getEventCallbacks(type) {
return this._eventCallbacks[type] || [];
},
});

View File

@@ -31,45 +31,45 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-js-api-interface tests', function() {
var element;
var plugin;
var errorStub;
var sandbox;
suite('gr-js-api-interface tests', () => {
let element;
let plugin;
let errorStub;
let sandbox;
var throwErrFn = function() {
const throwErrFn = function() {
throw Error('Unfortunately, this handler has stopped');
};
setup(function() {
setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
getAccount: function() {
getAccount() {
return Promise.resolve({name: 'Judy Hopps'});
},
});
element = fixture('basic');
errorStub = sandbox.stub(console, 'error');
Gerrit._setPluginsCount(1);
Gerrit.install(function(p) { plugin = p; }, '0.1',
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
});
teardown(function() {
teardown(() => {
sandbox.restore();
element._removeEventCallbacks();
plugin = null;
});
test('url', function() {
test('url', () => {
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
assert.equal(plugin.url('/static/test.js'),
'http://test.com/plugins/testplugin/static/test.js');
});
test('history event', function(done) {
test('history event', done => {
plugin.on(element.EventType.HISTORY, throwErrFn);
plugin.on(element.EventType.HISTORY, function(path) {
plugin.on(element.EventType.HISTORY, path => {
assert.equal(path, '/path/to/awesomesauce');
assert.isTrue(errorStub.calledOnce);
done();
@@ -78,13 +78,13 @@ limitations under the License.
{path: '/path/to/awesomesauce'});
});
test('showchange event', function(done) {
var testChange = {
test('showchange event', done => {
const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
plugin.on(element.EventType.SHOW_CHANGE, (change, revision) => {
assert.deepEqual(change, testChange);
assert.deepEqual(revision, testChange.revisions.abc);
assert.isTrue(errorStub.calledOnce);
@@ -94,28 +94,28 @@ limitations under the License.
{change: testChange, patchNum: 1});
});
test('handleEvent awaits plugins load', function(done) {
var testChange = {
test('handleEvent awaits plugins load', done => {
const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
var spy = sandbox.spy();
const spy = sandbox.spy();
Gerrit._setPluginsCount(1);
plugin.on(element.EventType.SHOW_CHANGE, spy);
element.handleEvent(element.EventType.SHOW_CHANGE,
{change: testChange, patchNum: 1});
assert.isFalse(spy.called);
Gerrit._setPluginsCount(0);
flush(function() {
flush(() => {
assert.isTrue(spy.called);
done();
});
});
test('comment event', function(done) {
var testCommentNode = {foo: 'bar'};
test('comment event', done => {
const testCommentNode = {foo: 'bar'};
plugin.on(element.EventType.COMMENT, throwErrFn);
plugin.on(element.EventType.COMMENT, function(commentNode) {
plugin.on(element.EventType.COMMENT, commentNode => {
assert.deepEqual(commentNode, testCommentNode);
assert.isTrue(errorStub.calledOnce);
done();
@@ -123,7 +123,7 @@ limitations under the License.
element.handleEvent(element.EventType.COMMENT, {node: testCommentNode});
});
test('revert event', function() {
test('revert event', () => {
function appendToRevertMsg(c, revertMsg, originalMsg) {
return revertMsg + '\n' + originalMsg.replace(/^/gm, '> ') + '\ninfo';
}
@@ -134,16 +134,16 @@ limitations under the License.
plugin.on(element.EventType.REVERT, throwErrFn);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
'test\n> origTest\ninfo');
'test\n> origTest\ninfo');
assert.isTrue(errorStub.calledOnce);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
'test\n> origTest\ninfo\n> origTest\ninfo');
'test\n> origTest\ninfo\n> origTest\ninfo');
assert.isTrue(errorStub.calledTwice);
});
test('postrevert event', function() {
test('postrevert event', () => {
function getLabels(c) {
return {'Code-Review': 1};
}
@@ -158,10 +158,10 @@ limitations under the License.
assert.isTrue(errorStub.calledOnce);
});
test('commitmsgedit event', function(done) {
var testMsg = 'Test CL commit message';
test('commitmsgedit event', done => {
const testMsg = 'Test CL commit message';
plugin.on(element.EventType.COMMIT_MSG_EDIT, throwErrFn);
plugin.on(element.EventType.COMMIT_MSG_EDIT, function(change, msg) {
plugin.on(element.EventType.COMMIT_MSG_EDIT, (change, msg) => {
assert.deepEqual(msg, testMsg);
assert.isTrue(errorStub.calledOnce);
done();
@@ -169,10 +169,10 @@ limitations under the License.
element.handleCommitMessage(null, testMsg);
});
test('labelchange event', function(done) {
var testChange = {_number: 42};
test('labelchange event', done => {
const testChange = {_number: 42};
plugin.on(element.EventType.LABEL_CHANGE, throwErrFn);
plugin.on(element.EventType.LABEL_CHANGE, function(change) {
plugin.on(element.EventType.LABEL_CHANGE, change => {
assert.deepEqual(change, testChange);
assert.isTrue(errorStub.calledOnce);
done();
@@ -180,41 +180,41 @@ limitations under the License.
element.handleEvent(element.EventType.LABEL_CHANGE, {change: testChange});
});
test('submitchange', function() {
test('submitchange', () => {
plugin.on(element.EventType.SUBMIT_CHANGE, throwErrFn);
plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isTrue(element.canSubmitChange());
assert.isTrue(errorStub.calledOnce);
plugin.on(element.EventType.SUBMIT_CHANGE, function() { return false; });
plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return false; });
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isFalse(element.canSubmitChange());
assert.isTrue(errorStub.calledTwice);
});
test('versioning', function() {
var callback = sandbox.spy();
test('versioning', () => {
const callback = sandbox.spy();
Gerrit.install(callback, '0.0pre-alpha');
assert(callback.notCalled);
});
test('getAccount', function(done) {
Gerrit.getLoggedIn().then(function(loggedIn) {
test('getAccount', done => {
Gerrit.getLoggedIn().then(loggedIn => {
assert.isTrue(loggedIn);
done();
});
});
test('_setPluginsCount', function(done) {
test('_setPluginsCount', done => {
stub('gr-reporting', {
pluginsLoaded: function() {
pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
}
},
});
Gerrit._setPluginsCount(0);
});
test('_arePluginsLoaded', function() {
test('_arePluginsLoaded', () => {
assert.isTrue(Gerrit._arePluginsLoaded());
Gerrit._setPluginsCount(1);
assert.isFalse(Gerrit._arePluginsLoaded());
@@ -222,12 +222,12 @@ limitations under the License.
assert.isTrue(Gerrit._arePluginsLoaded());
});
test('_pluginInstalled', function(done) {
test('_pluginInstalled', done => {
stub('gr-reporting', {
pluginsLoaded: function() {
pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
}
},
});
Gerrit._setPluginsCount(2);
Gerrit._pluginInstalled();
@@ -235,34 +235,34 @@ limitations under the License.
Gerrit._pluginInstalled();
});
test('install calls _pluginInstalled', function() {
test('install calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.install(function(p) { plugin = p; }, '0.1',
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
test('install calls _pluginInstalled on error', function() {
test('install calls _pluginInstalled on error', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.install(function() {}, '0.0pre-alpha');
Gerrit.install(() => {}, '0.0pre-alpha');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
test('installGwt calls _pluginInstalled', function() {
test('installGwt calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.installGwt();
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
test('installGwt returns a stub object', function() {
var plugin = Gerrit.installGwt();
test('installGwt returns a stub object', () => {
const plugin = Gerrit.installGwt();
sandbox.stub(console, 'warn');
assert.isAbove(Object.keys(plugin).length, 0);
Object.keys(plugin).forEach(function(name) {
for (const name of Object.keys(plugin)) {
console.warn.reset();
plugin[name]();
assert.isTrue(console.warn.calledOnce);
});
}
});
});
</script>

View File

@@ -14,17 +14,17 @@
(function(window) {
'use strict';
var warnNotSupported = function(opt_name) {
const warnNotSupported = function(opt_name) {
console.warn('Plugin API method ' + (opt_name || '') + ' is not supported');
};
var stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
var GWT_PLUGIN_STUB = {};
stubbedMethods.forEach(function(name) {
const stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
const GWT_PLUGIN_STUB = {};
for (const name of stubbedMethods) {
GWT_PLUGIN_STUB[name] = warnNotSupported.bind(null, name);
});
}
var API_VERSION = '0.1';
const API_VERSION = '0.1';
// GWT JSNI uses $wnd to refer to window.
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
@@ -38,7 +38,7 @@
}
this._url = new URL(opt_url);
if (this._url.pathname.indexOf('/plugins') !== 0) {
if (!this._url.pathname.startsWith('/plugins')) {
console.warn('Plugin not being loaded from /plugins base path:',
this._url.href, '— Unable to determine name.');
return;
@@ -54,14 +54,14 @@
return this._name;
};
Plugin.prototype.registerStyleModule =
function(stylingEndpointName, moduleName) {
Plugin.prototype.registerStyleModule = function(stylingEndpointName,
moduleName) {
if (!Gerrit._styleModules[stylingEndpointName]) {
Gerrit._styleModules[stylingEndpointName] = [];
}
Gerrit._styleModules[stylingEndpointName].push({
pluginUrl: this._url,
moduleName: moduleName,
moduleName,
});
};
@@ -87,7 +87,7 @@
Plugin._sharedAPIElement.Element.REPLY_DIALOG));
};
var Gerrit = window.Gerrit || {};
const Gerrit = window.Gerrit || {};
// Number of plugins to initialize, -1 means 'not yet known'.
Gerrit._pluginsPending = -1;
@@ -102,12 +102,13 @@
Gerrit.css = function(rulesStr) {
if (!Gerrit._customStyleSheet) {
var styleEl = document.createElement('style');
const styleEl = document.createElement('style');
document.head.appendChild(styleEl);
Gerrit._customStyleSheet = styleEl.sheet;
}
var name = '__pg_js_api_class_' + Gerrit._customStyleSheet.cssRules.length;
const name = '__pg_js_api_class_' +
Gerrit._customStyleSheet.cssRules.length;
Gerrit._customStyleSheet.insertRule('.' + name + '{' + rulesStr + '}', 0);
return name;
};
@@ -121,9 +122,9 @@
}
// TODO(andybons): Polyfill currentScript for IE10/11 (edge supports it).
var src = opt_src || (document.currentScript &&
const src = opt_src || (document.currentScript &&
document.currentScript.src || document.currentScript.baseURI);
var plugin = new Plugin(src);
const plugin = new Plugin(src);
try {
callback(plugin);
} catch (e) {
@@ -155,7 +156,7 @@
if (Gerrit._arePluginsLoaded()) {
Gerrit._allPluginsPromise = Promise.resolve();
} else {
Gerrit._allPluginsPromise = new Promise(function(resolve) {
Gerrit._allPluginsPromise = new Promise(resolve => {
Gerrit._resolveAllPluginsLoaded = resolve;
});
}