Get rid of some global variables - Part 6
* Replace the following global variables with named imports: - GrChangeMetadataApi - GrEmailSuggestionsProvider - GrGroupSuggestionsProvider * Update gr-app-global-var-init.js Change-Id: I3d019377f3af0ecb71f48a58ca43faddeb908083
This commit is contained in:
@@ -166,11 +166,8 @@ module.exports = {
|
||||
// Instead export variables from modules
|
||||
// TODO(dmfilippov): Remove global variables from polygerrit
|
||||
"Gerrit": "readonly",
|
||||
"GrChangeMetadataApi": "readonly",
|
||||
"GrChangeViewApi": "readonly",
|
||||
"GrEmailSuggestionsProvider": "readonly",
|
||||
"GrEventHelper": "readonly",
|
||||
"GrGroupSuggestionsProvider": "readonly",
|
||||
"GrPluginActionContext": "readonly",
|
||||
"GrPluginRestApi": "readonly",
|
||||
"GrRepoApi": "readonly",
|
||||
|
||||
@@ -55,6 +55,9 @@ import {EventEmitter} from './shared/gr-event-interface/gr-event-interface.js';
|
||||
import {GrAdminApi} from './plugins/gr-admin-api/gr-admin-api.js';
|
||||
import {GrAnnotationActionsContext} from './shared/gr-js-api-interface/gr-annotation-actions-context.js';
|
||||
import {GrAnnotationActionsInterface} from './shared/gr-js-api-interface/gr-annotation-actions-js-api.js';
|
||||
import {GrChangeMetadataApi} from './plugins/gr-change-metadata-api/gr-change-metadata-api.js';
|
||||
import {GrEmailSuggestionsProvider} from '../scripts/gr-email-suggestions-provider/gr-email-suggestions-provider.js';
|
||||
import {GrGroupSuggestionsProvider} from '../scripts/gr-group-suggestions-provider/gr-group-suggestions-provider.js';
|
||||
|
||||
export function initGlobalVariables() {
|
||||
window.GrDisplayNameUtils = GrDisplayNameUtils;
|
||||
@@ -93,4 +96,7 @@ export function initGlobalVariables() {
|
||||
window.GrAdminApi = GrAdminApi;
|
||||
window.GrAnnotationActionsContext = GrAnnotationActionsContext;
|
||||
window.GrAnnotationActionsInterface = GrAnnotationActionsInterface;
|
||||
window.GrChangeMetadataApi = GrChangeMetadataApi;
|
||||
window.GrEmailSuggestionsProvider = GrEmailSuggestionsProvider;
|
||||
window.GrGroupSuggestionsProvider = GrGroupSuggestionsProvider;
|
||||
}
|
||||
|
||||
@@ -24,27 +24,21 @@ $_documentContainer.innerHTML = `<dom-module id="gr-change-metadata-api">
|
||||
|
||||
document.head.appendChild($_documentContainer.content);
|
||||
|
||||
(function(window) {
|
||||
'use strict';
|
||||
/** @constructor */
|
||||
export function GrChangeMetadataApi(plugin) {
|
||||
this._hook = null;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/** @constructor */
|
||||
function GrChangeMetadataApi(plugin) {
|
||||
this._hook = null;
|
||||
this.plugin = plugin;
|
||||
GrChangeMetadataApi.prototype._createHook = function() {
|
||||
this._hook = this.plugin.hook('change-metadata-item');
|
||||
};
|
||||
|
||||
GrChangeMetadataApi.prototype.onLabelsChanged = function(callback) {
|
||||
if (!this._hook) {
|
||||
this._createHook();
|
||||
}
|
||||
|
||||
GrChangeMetadataApi.prototype._createHook = function() {
|
||||
this._hook = this.plugin.hook('change-metadata-item');
|
||||
};
|
||||
|
||||
GrChangeMetadataApi.prototype.onLabelsChanged = function(callback) {
|
||||
if (!this._hook) {
|
||||
this._createHook();
|
||||
}
|
||||
this._hook.onAttached(element =>
|
||||
this.plugin.attributeHelper(element).bind('labels', callback));
|
||||
return this;
|
||||
};
|
||||
|
||||
window.GrChangeMetadataApi = GrChangeMetadataApi;
|
||||
})(window);
|
||||
this._hook.onAttached(element =>
|
||||
this.plugin.attributeHelper(element).bind('labels', callback));
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
import '../../../scripts/bundled-polymer.js';
|
||||
import '../../core/gr-reporting/gr-reporting.js';
|
||||
import '../../plugins/gr-change-metadata-api/gr-change-metadata-api.js';
|
||||
import '../../plugins/gr-event-helper/gr-event-helper.js';
|
||||
import '../../plugins/gr-repo-api/gr-repo-api.js';
|
||||
import '../../plugins/gr-settings-api/gr-settings-api.js';
|
||||
|
||||
@@ -24,6 +24,7 @@ import {GrThemeApi} from '../../plugins/gr-theme-api/gr-theme-api.js';
|
||||
import {GrPopupInterface} from '../../plugins/gr-popup-interface/gr-popup-interface.js';
|
||||
import {GrAdminApi} from '../../plugins/gr-admin-api/gr-admin-api.js';
|
||||
import {GrAnnotationActionsInterface} from './gr-annotation-actions-js-api.js';
|
||||
import {GrChangeMetadataApi} from '../../plugins/gr-change-metadata-api/gr-change-metadata-api.js';
|
||||
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
@@ -16,33 +16,24 @@
|
||||
*/
|
||||
import {GrDisplayNameUtils} from '../gr-display-name-utils/gr-display-name-utils.js';
|
||||
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
if (window.GrEmailSuggestionsProvider) {
|
||||
return;
|
||||
export class GrEmailSuggestionsProvider {
|
||||
constructor(restAPI) {
|
||||
this._restAPI = restAPI;
|
||||
}
|
||||
|
||||
class GrEmailSuggestionsProvider {
|
||||
constructor(restAPI) {
|
||||
this._restAPI = restAPI;
|
||||
}
|
||||
|
||||
getSuggestions(input) {
|
||||
return this._restAPI.getSuggestedAccounts(`${input}`)
|
||||
.then(accounts => {
|
||||
if (!accounts) { return []; }
|
||||
return accounts;
|
||||
});
|
||||
}
|
||||
|
||||
makeSuggestionItem(account) {
|
||||
return {
|
||||
name: GrDisplayNameUtils.getAccountDisplayName(null, account),
|
||||
value: {account, count: 1},
|
||||
};
|
||||
}
|
||||
getSuggestions(input) {
|
||||
return this._restAPI.getSuggestedAccounts(`${input}`)
|
||||
.then(accounts => {
|
||||
if (!accounts) { return []; }
|
||||
return accounts;
|
||||
});
|
||||
}
|
||||
|
||||
window.GrEmailSuggestionsProvider = GrEmailSuggestionsProvider;
|
||||
})(window);
|
||||
makeSuggestionItem(account) {
|
||||
return {
|
||||
name: GrDisplayNameUtils.getAccountDisplayName(null, account),
|
||||
value: {account, count: 1},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../test/common-test-setup.js';
|
||||
import '../../elements/shared/gr-rest-api-interface/gr-rest-api-interface.js';
|
||||
import './gr-email-suggestions-provider.js';
|
||||
import {GrEmailSuggestionsProvider} from './gr-email-suggestions-provider.js';
|
||||
|
||||
suite('GrEmailSuggestionsProvider tests', () => {
|
||||
let sandbox;
|
||||
let restAPI;
|
||||
|
||||
@@ -14,32 +14,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
if (window.GrGroupSuggestionsProvider) {
|
||||
return;
|
||||
export class GrGroupSuggestionsProvider {
|
||||
constructor(restAPI) {
|
||||
this._restAPI = restAPI;
|
||||
}
|
||||
|
||||
class GrGroupSuggestionsProvider {
|
||||
constructor(restAPI) {
|
||||
this._restAPI = restAPI;
|
||||
}
|
||||
|
||||
getSuggestions(input) {
|
||||
return this._restAPI.getSuggestedGroups(`${input}`)
|
||||
.then(groups => {
|
||||
if (!groups) { return []; }
|
||||
const keys = Object.keys(groups);
|
||||
return keys.map(key => Object.assign({}, groups[key], {name: key}));
|
||||
});
|
||||
}
|
||||
|
||||
makeSuggestionItem(suggestion) {
|
||||
return {name: suggestion.name,
|
||||
value: {group: {name: suggestion.name, id: suggestion.id}}};
|
||||
}
|
||||
getSuggestions(input) {
|
||||
return this._restAPI.getSuggestedGroups(`${input}`)
|
||||
.then(groups => {
|
||||
if (!groups) { return []; }
|
||||
const keys = Object.keys(groups);
|
||||
return keys.map(key => Object.assign({}, groups[key], {name: key}));
|
||||
});
|
||||
}
|
||||
|
||||
window.GrGroupSuggestionsProvider = GrGroupSuggestionsProvider;
|
||||
})(window);
|
||||
makeSuggestionItem(suggestion) {
|
||||
return {name: suggestion.name,
|
||||
value: {group: {name: suggestion.name, id: suggestion.id}}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../test/common-test-setup.js';
|
||||
import '../../elements/shared/gr-rest-api-interface/gr-rest-api-interface.js';
|
||||
import './gr-group-suggestions-provider.js';
|
||||
import {GrGroupSuggestionsProvider} from './gr-group-suggestions-provider.js';
|
||||
|
||||
suite('GrGroupSuggestionsProvider tests', () => {
|
||||
let sandbox;
|
||||
let restAPI;
|
||||
|
||||
Reference in New Issue
Block a user