Remove window.Plugin and use import instead

Also moved the shared api element to gr-js-api-interface-element,
that's also where the componenet defined.

Change-Id: Icf4f48be3e3ce843a4b0ec6491aaa5a27342b3d8
This commit is contained in:
Tao Zhou
2020-07-15 16:25:56 +02:00
parent 12ddb05449
commit ad964155ef
4 changed files with 13 additions and 15 deletions

View File

@@ -15,18 +15,19 @@
* limitations under the License. * limitations under the License.
*/ */
import {sharedApiElement} from './gr-js-api-interface-element.js';
/** /**
* GrChangeReplyInterface, provides a set of handy methods on reply dialog. * GrChangeReplyInterface, provides a set of handy methods on reply dialog.
*/ */
export class GrChangeReplyInterface { export class GrChangeReplyInterface {
constructor(plugin) { constructor(plugin) {
this.plugin = plugin; this.plugin = plugin;
this._sharedApiEl = Plugin._sharedAPIElement;
} }
get _el() { get _el() {
return this._sharedApiEl.getElement( return sharedApiElement.getElement(
this._sharedApiEl.Element.REPLY_DIALOG); sharedApiElement.Element.REPLY_DIALOG);
} }
getLabelValue(label) { getLabelValue(label) {

View File

@@ -327,3 +327,6 @@ class GrJsApiInterface extends GestureEventListeners(
} }
customElements.define(GrJsApiInterface.is, GrJsApiInterface); customElements.define(GrJsApiInterface.is, GrJsApiInterface);
// The shared api element used across components
export const sharedApiElement = document.createElement('gr-js-api-interface');

View File

@@ -16,15 +16,13 @@ import {appContext} from '../../../services/app-context.js';
* 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.
*/ */
import './gr-api-utils.js';
import {importHref} from '../../../scripts/import-href.js'; import {importHref} from '../../../scripts/import-href.js';
import { import {
PLUGIN_LOADING_TIMEOUT_MS, PLUGIN_LOADING_TIMEOUT_MS,
PRELOADED_PROTOCOL, PRELOADED_PROTOCOL,
getPluginNameFromUrl, getPluginNameFromUrl,
} from './gr-api-utils.js'; } from './gr-api-utils.js';
import {Plugin} from './gr-public-js-api.js';
import {getBaseUrl} from '../../../utils/url-util.js'; import {getBaseUrl} from '../../../utils/url-util.js';
/** /**

View File

@@ -32,6 +32,7 @@ import {GrSettingsApi} from '../../plugins/gr-settings-api/gr-settings-api.js';
import {GrStylesApi} from '../../plugins/gr-styles-api/gr-styles-api.js'; import {GrStylesApi} from '../../plugins/gr-styles-api/gr-styles-api.js';
import {GrPluginActionContext} from './gr-plugin-action-context.js'; import {GrPluginActionContext} from './gr-plugin-action-context.js';
import {pluginEndpoints} from './gr-plugin-endpoints.js'; import {pluginEndpoints} from './gr-plugin-endpoints.js';
import {sharedApiElement} from './gr-js-api-interface-element.js';
import { import {
PRELOADED_PROTOCOL, PRELOADED_PROTOCOL,
@@ -162,7 +163,7 @@ export class Plugin {
} }
on(eventName, callback) { on(eventName, callback) {
Plugin._sharedAPIElement.addEventCallback(eventName, callback); sharedApiElement.addEventCallback(eventName, callback);
} }
url(opt_path) { url(opt_path) {
@@ -219,8 +220,8 @@ export class Plugin {
changeActions() { changeActions() {
return new GrChangeActionsInterface( return new GrChangeActionsInterface(
this, this,
Plugin._sharedAPIElement.getElement( sharedApiElement.getElement(
Plugin._sharedAPIElement.Element.CHANGE_ACTIONS sharedApiElement.Element.CHANGE_ACTIONS
) )
); );
} }
@@ -313,8 +314,6 @@ export class Plugin {
} }
} }
Plugin._sharedAPIElement = document.createElement('gr-js-api-interface');
// TODO: should be removed soon after all core plugins moved away from it. // TODO: should be removed soon after all core plugins moved away from it.
const deprecatedAPI = { const deprecatedAPI = {
_loadedGwt: () => {}, _loadedGwt: () => {},
@@ -432,6 +431,3 @@ const deprecatedAPI = {
); );
}, },
}; };
// TODO: Remove once no longer rely on global Plugin
window.Plugin = Plugin;