Get rid of some global variables - Part 1
* Replace the following global variables with named imports: - GrChangeReplyInterface - GrEditConstants - GrFileListConstants * Update gr-app-global-var-init.js Change-Id: I8f19739784789d1f26b893b9faab9d6a279bfc60
This commit is contained in:
		@@ -173,16 +173,13 @@ module.exports = {
 | 
			
		||||
    "GrAnnotationActionsContext": "readonly",
 | 
			
		||||
    "GrAnnotationActionsInterface": "readonly",
 | 
			
		||||
    "GrChangeMetadataApi": "readonly",
 | 
			
		||||
    "GrChangeReplyInterface": "readonly",
 | 
			
		||||
    "GrChangeViewApi": "readonly",
 | 
			
		||||
    "GrCountStringFormatter": "readonly",
 | 
			
		||||
    "GrDomHook": "readonly",
 | 
			
		||||
    "GrDomHooksManager": "readonly",
 | 
			
		||||
    "GrEditConstants": "readonly",
 | 
			
		||||
    "GrEmailSuggestionsProvider": "readonly",
 | 
			
		||||
    "GrEtagDecorator": "readonly",
 | 
			
		||||
    "GrEventHelper": "readonly",
 | 
			
		||||
    "GrFileListConstants": "readonly",
 | 
			
		||||
    "GrGroupSuggestionsProvider": "readonly",
 | 
			
		||||
    "GrLinkTextParser": "readonly",
 | 
			
		||||
    "GrPluginActionContext": "readonly",
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ import '../../../styles/shared-styles.js';
 | 
			
		||||
import '../../core/gr-navigation/gr-navigation.js';
 | 
			
		||||
import '../../core/gr-reporting/gr-reporting.js';
 | 
			
		||||
import '../../diff/gr-comment-api/gr-comment-api.js';
 | 
			
		||||
import '../../edit/gr-edit-constants.js';
 | 
			
		||||
import '../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.js';
 | 
			
		||||
import '../../plugins/gr-endpoint-param/gr-endpoint-param.js';
 | 
			
		||||
import '../../shared/gr-account-link/gr-account-link.js';
 | 
			
		||||
@@ -60,6 +59,7 @@ import {htmlTemplate} from './gr-change-view_html.js';
 | 
			
		||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
 | 
			
		||||
import {KeyboardShortcutBehavior} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
 | 
			
		||||
import {RESTClientBehavior} from '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
 | 
			
		||||
import {GrEditConstants} from '../../edit/gr-edit-constants.js';
 | 
			
		||||
 | 
			
		||||
import {PrimaryTabs, SecondaryTabs} from '../../../constants/constants.js';
 | 
			
		||||
import {NO_ROBOT_COMMENTS_THREADS_MSG} from '../../../constants/messages.js';
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,8 @@ import {PrimaryTabs, SecondaryTabs} from '../../../constants/constants.js';
 | 
			
		||||
 | 
			
		||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {KeyboardShortcutBinder} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
 | 
			
		||||
import {GrEditConstants} from '../../edit/gr-edit-constants.js';
 | 
			
		||||
 | 
			
		||||
suite('gr-change-view tests', () => {
 | 
			
		||||
  const kb = KeyboardShortcutBinder;
 | 
			
		||||
  kb.bindShortcut(kb.Shortcut.SEND_REPLY, 'ctrl+enter');
 | 
			
		||||
 
 | 
			
		||||
@@ -14,16 +14,12 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
(function(window) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  const GrFileListConstants = window.GrFileListConstants || {};
 | 
			
		||||
 | 
			
		||||
  GrFileListConstants.FilesExpandedState = {
 | 
			
		||||
export const GrFileListConstants = {
 | 
			
		||||
  FilesExpandedState: {
 | 
			
		||||
    ALL: 'all',
 | 
			
		||||
    NONE: 'none',
 | 
			
		||||
    SOME: 'some',
 | 
			
		||||
  };
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  window.GrFileListConstants = GrFileListConstants;
 | 
			
		||||
})(window);
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,6 @@ import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
 | 
			
		||||
import '../../shared/gr-select/gr-select.js';
 | 
			
		||||
import '../../shared/gr-button/gr-button.js';
 | 
			
		||||
import '../../shared/gr-icons/gr-icons.js';
 | 
			
		||||
import '../gr-file-list-constants.js';
 | 
			
		||||
import '../gr-commit-info/gr-commit-info.js';
 | 
			
		||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
 | 
			
		||||
@@ -37,6 +36,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element.js';
 | 
			
		||||
import {htmlTemplate} from './gr-file-list-header_html.js';
 | 
			
		||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
 | 
			
		||||
import {KeyboardShortcutBehavior} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
 | 
			
		||||
import {GrFileListConstants} from '../gr-file-list-constants.js';
 | 
			
		||||
 | 
			
		||||
// Maximum length for patch set descriptions.
 | 
			
		||||
const PATCH_DESC_MAX_LENGTH = 500;
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,8 @@ limitations under the License.
 | 
			
		||||
import '../../../test/common-test-setup.js';
 | 
			
		||||
import './gr-file-list-header.js';
 | 
			
		||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {GrFileListConstants} from '../gr-file-list-constants.js';
 | 
			
		||||
 | 
			
		||||
suite('gr-file-list-header tests', () => {
 | 
			
		||||
  let element;
 | 
			
		||||
  let sandbox;
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,6 @@ import '../../shared/gr-select/gr-select.js';
 | 
			
		||||
import '../../shared/gr-count-string-formatter/gr-count-string-formatter.js';
 | 
			
		||||
import '../../shared/gr-tooltip-content/gr-tooltip-content.js';
 | 
			
		||||
import '../../shared/gr-copy-clipboard/gr-copy-clipboard.js';
 | 
			
		||||
import '../gr-file-list-constants.js';
 | 
			
		||||
import {dom, flush} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
 | 
			
		||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
 | 
			
		||||
@@ -44,6 +43,7 @@ import {DomUtilBehavior} from '../../../behaviors/dom-util-behavior/dom-util-beh
 | 
			
		||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
 | 
			
		||||
import {PathListBehavior} from '../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.js';
 | 
			
		||||
import {KeyboardShortcutBehavior} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
 | 
			
		||||
import {GrFileListConstants} from '../gr-file-list-constants.js';
 | 
			
		||||
 | 
			
		||||
// Maximum length for patch set descriptions.
 | 
			
		||||
const PATCH_DESC_MAX_LENGTH = 500;
 | 
			
		||||
 
 | 
			
		||||
@@ -50,6 +50,8 @@ import './gr-file-list.js';
 | 
			
		||||
import '../../diff/gr-comment-api/gr-comment-api-mock_test.js';
 | 
			
		||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {KeyboardShortcutBinder} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
 | 
			
		||||
import {GrFileListConstants} from '../gr-file-list-constants.js';
 | 
			
		||||
 | 
			
		||||
suite('gr-file-list tests', () => {
 | 
			
		||||
  const kb = KeyboardShortcutBinder;
 | 
			
		||||
  kb.bindShortcut(kb.Shortcut.LEFT_PANE, 'shift+left');
 | 
			
		||||
 
 | 
			
		||||
@@ -14,18 +14,14 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
(function(window) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  const GrEditConstants = window.GrEditConstants || {};
 | 
			
		||||
 | 
			
		||||
  // Order corresponds to order in the UI.
 | 
			
		||||
  GrEditConstants.Actions = {
 | 
			
		||||
export const GrEditConstants = {
 | 
			
		||||
// Order corresponds to order in the UI.
 | 
			
		||||
  Actions: {
 | 
			
		||||
    OPEN: {label: 'Add/Open', id: 'open'},
 | 
			
		||||
    DELETE: {label: 'Delete', id: 'delete'},
 | 
			
		||||
    RENAME: {label: 'Rename', id: 'rename'},
 | 
			
		||||
    RESTORE: {label: 'Restore', id: 'restore'},
 | 
			
		||||
  };
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  window.GrEditConstants = GrEditConstants;
 | 
			
		||||
})(window);
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@ import '../../shared/gr-dialog/gr-dialog.js';
 | 
			
		||||
import '../../shared/gr-dropdown/gr-dropdown.js';
 | 
			
		||||
import '../../shared/gr-overlay/gr-overlay.js';
 | 
			
		||||
import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
 | 
			
		||||
import '../gr-edit-constants.js';
 | 
			
		||||
import '../../../styles/shared-styles.js';
 | 
			
		||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
 | 
			
		||||
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
 | 
			
		||||
@@ -33,6 +32,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
 | 
			
		||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
 | 
			
		||||
import {htmlTemplate} from './gr-edit-controls_html.js';
 | 
			
		||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
 | 
			
		||||
import {GrEditConstants} from '../gr-edit-constants.js';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @extends Polymer.Element
 | 
			
		||||
 
 | 
			
		||||
@@ -18,12 +18,12 @@ import '../../../scripts/bundled-polymer.js';
 | 
			
		||||
 | 
			
		||||
import '../../shared/gr-button/gr-button.js';
 | 
			
		||||
import '../../shared/gr-dropdown/gr-dropdown.js';
 | 
			
		||||
import '../gr-edit-constants.js';
 | 
			
		||||
import '../../../styles/shared-styles.js';
 | 
			
		||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
 | 
			
		||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
 | 
			
		||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
 | 
			
		||||
import {htmlTemplate} from './gr-edit-file-controls_html.js';
 | 
			
		||||
import {GrEditConstants} from '../gr-edit-constants.js';
 | 
			
		||||
 | 
			
		||||
/** @extends Polymer.Element */
 | 
			
		||||
class GrEditFileControls extends GestureEventListeners(
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,8 @@ limitations under the License.
 | 
			
		||||
import '../../../test/common-test-setup.js';
 | 
			
		||||
import '../gr-edit-constants.js';
 | 
			
		||||
import './gr-edit-file-controls.js';
 | 
			
		||||
import {GrEditConstants} from '../gr-edit-constants.js';
 | 
			
		||||
 | 
			
		||||
suite('gr-edit-file-controls tests', () => {
 | 
			
		||||
  let element;
 | 
			
		||||
  let sandbox;
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,9 @@ import {GrDiffBuilderImage} from './diff/gr-diff-builder/gr-diff-builder-image.j
 | 
			
		||||
import {GrDiffBuilderUnified} from './diff/gr-diff-builder/gr-diff-builder-unified.js';
 | 
			
		||||
import {GrDiffBuilderBinary} from './diff/gr-diff-builder/gr-diff-builder-binary.js';
 | 
			
		||||
import {GrChangeActionsInterface} from './shared/gr-js-api-interface/gr-change-actions-js-api.js';
 | 
			
		||||
import {GrChangeReplyInterface} from './shared/gr-js-api-interface/gr-change-reply-js-api.js';
 | 
			
		||||
import {GrEditConstants} from './edit/gr-edit-constants.js';
 | 
			
		||||
import {GrFileListConstants} from './change/gr-file-list-constants.js';
 | 
			
		||||
 | 
			
		||||
export function initGlobalVariables() {
 | 
			
		||||
  window.GrDisplayNameUtils = GrDisplayNameUtils;
 | 
			
		||||
@@ -46,4 +49,7 @@ export function initGlobalVariables() {
 | 
			
		||||
  window.GrDiffBuilderUnified = GrDiffBuilderUnified;
 | 
			
		||||
  window.GrDiffBuilderBinary = GrDiffBuilderBinary;
 | 
			
		||||
  window.GrChangeActionsInterface = GrChangeActionsInterface;
 | 
			
		||||
  window.GrChangeReplyInterface = GrChangeReplyInterface;
 | 
			
		||||
  window.GrEditConstants = GrEditConstants;
 | 
			
		||||
  window.GrFileListConstants = GrFileListConstants;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,66 +14,61 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
(function(window) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * GrChangeReplyInterface, provides a set of handy methods on reply dialog.
 | 
			
		||||
   */
 | 
			
		||||
  class GrChangeReplyInterface {
 | 
			
		||||
    constructor(plugin) {
 | 
			
		||||
      this.plugin = plugin;
 | 
			
		||||
      this._sharedApiEl = Plugin._sharedAPIElement;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    get _el() {
 | 
			
		||||
      return this._sharedApiEl.getElement(
 | 
			
		||||
          this._sharedApiEl.Element.REPLY_DIALOG);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getLabelValue(label) {
 | 
			
		||||
      return this._el.getLabelValue(label);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setLabelValue(label, value) {
 | 
			
		||||
      this._el.setLabelValue(label, value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    send(opt_includeComments) {
 | 
			
		||||
      this._el.send(opt_includeComments);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    addReplyTextChangedCallback(handler) {
 | 
			
		||||
      const hookApi = this.plugin.hook('reply-text');
 | 
			
		||||
      const registeredHandler = e => handler(e.detail.value);
 | 
			
		||||
      hookApi.onAttached(el => {
 | 
			
		||||
        if (!el.content) { return; }
 | 
			
		||||
        el.content.addEventListener('value-changed', registeredHandler);
 | 
			
		||||
      });
 | 
			
		||||
      hookApi.onDetached(el => {
 | 
			
		||||
        if (!el.content) { return; }
 | 
			
		||||
        el.content.removeEventListener('value-changed', registeredHandler);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    addLabelValuesChangedCallback(handler) {
 | 
			
		||||
      const hookApi = this.plugin.hook('reply-label-scores');
 | 
			
		||||
      const registeredHandler = e => handler(e.detail);
 | 
			
		||||
      hookApi.onAttached(el => {
 | 
			
		||||
        if (!el.content) { return; }
 | 
			
		||||
        el.content.addEventListener('labels-changed', registeredHandler);
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      hookApi.onDetached(el => {
 | 
			
		||||
        if (!el.content) { return; }
 | 
			
		||||
        el.content.removeEventListener('labels-changed', registeredHandler);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    showMessage(message) {
 | 
			
		||||
      return this._el.setPluginMessage(message);
 | 
			
		||||
    }
 | 
			
		||||
/**
 | 
			
		||||
 * GrChangeReplyInterface, provides a set of handy methods on reply dialog.
 | 
			
		||||
 */
 | 
			
		||||
export class GrChangeReplyInterface {
 | 
			
		||||
  constructor(plugin) {
 | 
			
		||||
    this.plugin = plugin;
 | 
			
		||||
    this._sharedApiEl = Plugin._sharedAPIElement;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  window.GrChangeReplyInterface = GrChangeReplyInterface;
 | 
			
		||||
})(window);
 | 
			
		||||
  get _el() {
 | 
			
		||||
    return this._sharedApiEl.getElement(
 | 
			
		||||
        this._sharedApiEl.Element.REPLY_DIALOG);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getLabelValue(label) {
 | 
			
		||||
    return this._el.getLabelValue(label);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setLabelValue(label, value) {
 | 
			
		||||
    this._el.setLabelValue(label, value);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  send(opt_includeComments) {
 | 
			
		||||
    this._el.send(opt_includeComments);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addReplyTextChangedCallback(handler) {
 | 
			
		||||
    const hookApi = this.plugin.hook('reply-text');
 | 
			
		||||
    const registeredHandler = e => handler(e.detail.value);
 | 
			
		||||
    hookApi.onAttached(el => {
 | 
			
		||||
      if (!el.content) { return; }
 | 
			
		||||
      el.content.addEventListener('value-changed', registeredHandler);
 | 
			
		||||
    });
 | 
			
		||||
    hookApi.onDetached(el => {
 | 
			
		||||
      if (!el.content) { return; }
 | 
			
		||||
      el.content.removeEventListener('value-changed', registeredHandler);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addLabelValuesChangedCallback(handler) {
 | 
			
		||||
    const hookApi = this.plugin.hook('reply-label-scores');
 | 
			
		||||
    const registeredHandler = e => handler(e.detail);
 | 
			
		||||
    hookApi.onAttached(el => {
 | 
			
		||||
      if (!el.content) { return; }
 | 
			
		||||
      el.content.addEventListener('labels-changed', registeredHandler);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    hookApi.onDetached(el => {
 | 
			
		||||
      if (!el.content) { return; }
 | 
			
		||||
      el.content.removeEventListener('labels-changed', registeredHandler);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  showMessage(message) {
 | 
			
		||||
    return this._el.setPluginMessage(message);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,6 @@ import './gr-api-utils.js';
 | 
			
		||||
import '../gr-event-interface/gr-event-interface.js';
 | 
			
		||||
import './gr-annotation-actions-context.js';
 | 
			
		||||
import './gr-annotation-actions-js-api.js';
 | 
			
		||||
import './gr-change-reply-js-api.js';
 | 
			
		||||
import './gr-js-api-interface-element.js';
 | 
			
		||||
import './gr-plugin-endpoints.js';
 | 
			
		||||
import './gr-plugin-action-context.js';
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@
 | 
			
		||||
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
 | 
			
		||||
import {GrAttributeHelper} from '../../plugins/gr-attribute-helper/gr-attribute-helper.js';
 | 
			
		||||
import {GrChangeActionsInterface} from './gr-change-actions-js-api.js';
 | 
			
		||||
import {GrChangeReplyInterface} from './gr-change-reply-js-api.js';
 | 
			
		||||
 | 
			
		||||
(function(window) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user