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
|
// Instead export variables from modules
|
||||||
// TODO(dmfilippov): Remove global variables from polygerrit
|
// TODO(dmfilippov): Remove global variables from polygerrit
|
||||||
"Gerrit": "readonly",
|
"Gerrit": "readonly",
|
||||||
"GrChangeMetadataApi": "readonly",
|
|
||||||
"GrChangeViewApi": "readonly",
|
"GrChangeViewApi": "readonly",
|
||||||
"GrEmailSuggestionsProvider": "readonly",
|
|
||||||
"GrEventHelper": "readonly",
|
"GrEventHelper": "readonly",
|
||||||
"GrGroupSuggestionsProvider": "readonly",
|
|
||||||
"GrPluginActionContext": "readonly",
|
"GrPluginActionContext": "readonly",
|
||||||
"GrPluginRestApi": "readonly",
|
"GrPluginRestApi": "readonly",
|
||||||
"GrRepoApi": "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 {GrAdminApi} from './plugins/gr-admin-api/gr-admin-api.js';
|
||||||
import {GrAnnotationActionsContext} from './shared/gr-js-api-interface/gr-annotation-actions-context.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 {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() {
|
export function initGlobalVariables() {
|
||||||
window.GrDisplayNameUtils = GrDisplayNameUtils;
|
window.GrDisplayNameUtils = GrDisplayNameUtils;
|
||||||
@@ -93,4 +96,7 @@ export function initGlobalVariables() {
|
|||||||
window.GrAdminApi = GrAdminApi;
|
window.GrAdminApi = GrAdminApi;
|
||||||
window.GrAnnotationActionsContext = GrAnnotationActionsContext;
|
window.GrAnnotationActionsContext = GrAnnotationActionsContext;
|
||||||
window.GrAnnotationActionsInterface = GrAnnotationActionsInterface;
|
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);
|
document.head.appendChild($_documentContainer.content);
|
||||||
|
|
||||||
(function(window) {
|
/** @constructor */
|
||||||
'use strict';
|
export function GrChangeMetadataApi(plugin) {
|
||||||
|
|
||||||
/** @constructor */
|
|
||||||
function GrChangeMetadataApi(plugin) {
|
|
||||||
this._hook = null;
|
this._hook = null;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrChangeMetadataApi.prototype._createHook = function() {
|
GrChangeMetadataApi.prototype._createHook = function() {
|
||||||
this._hook = this.plugin.hook('change-metadata-item');
|
this._hook = this.plugin.hook('change-metadata-item');
|
||||||
};
|
};
|
||||||
|
|
||||||
GrChangeMetadataApi.prototype.onLabelsChanged = function(callback) {
|
GrChangeMetadataApi.prototype.onLabelsChanged = function(callback) {
|
||||||
if (!this._hook) {
|
if (!this._hook) {
|
||||||
this._createHook();
|
this._createHook();
|
||||||
}
|
}
|
||||||
this._hook.onAttached(element =>
|
this._hook.onAttached(element =>
|
||||||
this.plugin.attributeHelper(element).bind('labels', callback));
|
this.plugin.attributeHelper(element).bind('labels', callback));
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.GrChangeMetadataApi = GrChangeMetadataApi;
|
|
||||||
})(window);
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
import '../../../scripts/bundled-polymer.js';
|
import '../../../scripts/bundled-polymer.js';
|
||||||
import '../../core/gr-reporting/gr-reporting.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-event-helper/gr-event-helper.js';
|
||||||
import '../../plugins/gr-repo-api/gr-repo-api.js';
|
import '../../plugins/gr-repo-api/gr-repo-api.js';
|
||||||
import '../../plugins/gr-settings-api/gr-settings-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 {GrPopupInterface} from '../../plugins/gr-popup-interface/gr-popup-interface.js';
|
||||||
import {GrAdminApi} from '../../plugins/gr-admin-api/gr-admin-api.js';
|
import {GrAdminApi} from '../../plugins/gr-admin-api/gr-admin-api.js';
|
||||||
import {GrAnnotationActionsInterface} from './gr-annotation-actions-js-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) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|||||||
@@ -16,14 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
import {GrDisplayNameUtils} from '../gr-display-name-utils/gr-display-name-utils.js';
|
import {GrDisplayNameUtils} from '../gr-display-name-utils/gr-display-name-utils.js';
|
||||||
|
|
||||||
(function(window) {
|
export class GrEmailSuggestionsProvider {
|
||||||
'use strict';
|
|
||||||
|
|
||||||
if (window.GrEmailSuggestionsProvider) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GrEmailSuggestionsProvider {
|
|
||||||
constructor(restAPI) {
|
constructor(restAPI) {
|
||||||
this._restAPI = restAPI;
|
this._restAPI = restAPI;
|
||||||
}
|
}
|
||||||
@@ -42,7 +35,5 @@ import {GrDisplayNameUtils} from '../gr-display-name-utils/gr-display-name-utils
|
|||||||
value: {account, count: 1},
|
value: {account, count: 1},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.GrEmailSuggestionsProvider = GrEmailSuggestionsProvider;
|
|
||||||
})(window);
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ limitations under the License.
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import '../../test/common-test-setup.js';
|
import '../../test/common-test-setup.js';
|
||||||
import '../../elements/shared/gr-rest-api-interface/gr-rest-api-interface.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', () => {
|
suite('GrEmailSuggestionsProvider tests', () => {
|
||||||
let sandbox;
|
let sandbox;
|
||||||
let restAPI;
|
let restAPI;
|
||||||
|
|||||||
@@ -14,14 +14,8 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
(function(window) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
if (window.GrGroupSuggestionsProvider) {
|
export class GrGroupSuggestionsProvider {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GrGroupSuggestionsProvider {
|
|
||||||
constructor(restAPI) {
|
constructor(restAPI) {
|
||||||
this._restAPI = restAPI;
|
this._restAPI = restAPI;
|
||||||
}
|
}
|
||||||
@@ -39,7 +33,4 @@
|
|||||||
return {name: suggestion.name,
|
return {name: suggestion.name,
|
||||||
value: {group: {name: suggestion.name, id: suggestion.id}}};
|
value: {group: {name: suggestion.name, id: suggestion.id}}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.GrGroupSuggestionsProvider = GrGroupSuggestionsProvider;
|
|
||||||
})(window);
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ limitations under the License.
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import '../../test/common-test-setup.js';
|
import '../../test/common-test-setup.js';
|
||||||
import '../../elements/shared/gr-rest-api-interface/gr-rest-api-interface.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', () => {
|
suite('GrGroupSuggestionsProvider tests', () => {
|
||||||
let sandbox;
|
let sandbox;
|
||||||
let restAPI;
|
let restAPI;
|
||||||
|
|||||||
Reference in New Issue
Block a user