refactor(): deprecate web component controllers (#19109)

This commit is contained in:
Manu MA
2019-08-27 14:00:45 +02:00
committed by GitHub
parent 3e63b3c2c4
commit a65d897214
71 changed files with 1435 additions and 1461 deletions

View File

@ -1,24 +1,18 @@
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { Injectable } from '@angular/core';
import { menuController } from '@ionic/core';
import { proxyMethod } from '../util/util';
const CTRL = 'ion-menu-controller';
@Injectable({
providedIn: 'root',
})
export class MenuController {
constructor(@Inject(DOCUMENT) private doc: any) {
}
/**
* Programmatically open the Menu.
* @param [menuId] Optionally get the menu by its id, or side.
* @return returns a promise when the menu is fully opened
*/
open(menuId?: string): Promise<boolean> {
return proxyMethod(CTRL, this.doc, 'open', menuId);
open(menuId?: string) {
return menuController.open(menuId);
}
/**
@ -28,8 +22,8 @@ export class MenuController {
* @param [menuId] Optionally get the menu by its id, or side.
* @return returns a promise when the menu is fully closed
*/
close(menuId?: string): Promise<boolean> {
return proxyMethod(CTRL, this.doc, 'close', menuId);
close(menuId?: string) {
return menuController.close(menuId);
}
/**
@ -38,8 +32,8 @@ export class MenuController {
* @param [menuId] Optionally get the menu by its id, or side.
* @return returns a promise when the menu has been toggled
*/
toggle(menuId?: string): Promise<boolean> {
return proxyMethod(CTRL, this.doc, 'toggle', menuId);
toggle(menuId?: string) {
return menuController.toggle(menuId);
}
/**
@ -50,8 +44,8 @@ export class MenuController {
* @param [menuId] Optionally get the menu by its id, or side.
* @return Returns the instance of the menu, which is useful for chaining.
*/
enable(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
return proxyMethod(CTRL, this.doc, 'enable', shouldEnable, menuId);
enable(shouldEnable: boolean, menuId?: string) {
return menuController.enable(shouldEnable, menuId);
}
/**
@ -61,7 +55,7 @@ export class MenuController {
* @return Returns the instance of the menu, which is useful for chaining.
* @deprecated Use swipeGesture() instead
*/
swipeEnable(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
swipeEnable(shouldEnable: boolean, menuId?: string) {
console.warn('MenuController.swipeEnable is deprecated. Use MenuController.swipeGesture() instead');
return this.swipeGesture(shouldEnable, menuId);
}
@ -72,8 +66,8 @@ export class MenuController {
* @param [menuId] Optionally get the menu by its id, or side.
* @return Returns the instance of the menu, which is useful for chaining.
*/
swipeGesture(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
return proxyMethod(CTRL, this.doc, 'swipeGesture', shouldEnable, menuId);
swipeGesture(shouldEnable: boolean, menuId?: string) {
return menuController.swipeGesture(shouldEnable, menuId);
}
/**
@ -81,16 +75,16 @@ export class MenuController {
* @return Returns true if the specified menu is currently open, otherwise false.
* If the menuId is not specified, it returns true if ANY menu is currenly open.
*/
isOpen(menuId?: string): Promise<boolean> {
return proxyMethod(CTRL, this.doc, 'isOpen', menuId);
isOpen(menuId?: string) {
return menuController.isOpen(menuId);
}
/**
* @param [menuId] Optionally get the menu by its id, or side.
* @return Returns true if the menu is currently enabled, otherwise false.
*/
isEnabled(menuId?: string): Promise<boolean> {
return proxyMethod(CTRL, this.doc, 'isEnabled', menuId);
isEnabled(menuId?: string) {
return menuController.isEnabled(menuId);
}
/**
@ -102,21 +96,21 @@ export class MenuController {
* @param [menuId] Optionally get the menu by its id, or side.
* @return Returns the instance of the menu if found, otherwise `null`.
*/
get(menuId?: string): Promise<HTMLIonMenuElement> {
return proxyMethod(CTRL, this.doc, 'get', menuId);
get(menuId?: string) {
return menuController.get(menuId);
}
/**
* @return Returns the instance of the menu already opened, otherwise `null`.
*/
getOpen(): Promise<HTMLIonMenuElement> {
return proxyMethod(CTRL, this.doc, 'getOpen');
getOpen() {
return menuController.getOpen();
}
/**
* @return Returns an array of all menu instances.
*/
getMenus(): Promise<HTMLIonMenuElement[]> {
return proxyMethod(CTRL, this.doc, 'getMenus');
getMenus() {
return menuController.getMenus();
}
}

View File

@ -1,4 +1,3 @@
import { HTMLStencilElement } from '../types/interfaces';
declare const __zone_symbol__requestAnimationFrame: any;
declare const requestAnimationFrame: any;
@ -12,18 +11,3 @@ export const raf = (h: any) => {
}
return setTimeout(h);
};
export const proxyMethod = (ctrlName: string, doc: Document, methodName: string, ...args: any[]) => {
const controller = ensureElementInBody(ctrlName, doc);
return controller.componentOnReady()
.then(() => (controller as any)[methodName].apply(controller, args));
};
export const ensureElementInBody = (elementName: string, doc: Document) => {
let element = doc.querySelector(elementName);
if (!element) {
element = doc.createElement(elementName);
doc.body.appendChild(element);
}
return element as HTMLStencilElement;
};