fix(menu): getInstance() is not longer needed

This commit is contained in:
Manuel Mtz-Almeida
2017-09-15 15:06:01 -05:00
parent 7223caffce
commit d8f2fa73f3
3 changed files with 19 additions and 23 deletions

View File

@ -21,11 +21,6 @@ export class MenuController {
this.registerAnimation('overlay', MenuOverlayAnimation);
}
@Method()
getInstance(): MenuController {
return this;
}
/**
* Programatically open the Menu.
* @param {string} [menuId] Optionally get the menu by its id, or side.

View File

@ -3,8 +3,9 @@ import { Config, Animation } from '../../index';
import { MenuController } from './menu-controller';
import { isRightSide, Side, assert, checkEdgeSide } from '../../utils/helpers';
export type Lazy<T> =
{[P in keyof T]: (...args: any[]) => Promise<any>; };
export type Lazy<T> = T &
{ componentOnReady(): Promise<T> } &
{ componentOnReady(done: (cmp: T) => void): void }
@Component({
tag: 'ion-menu',
@ -113,7 +114,8 @@ export class Menu {
}
ionViewWillLoad() {
return this.lazyMenuCtrl.getInstance().then(menu => this.menuCtrl = menu);
return this.lazyMenuCtrl.componentOnReady()
.then(menu => this.menuCtrl = menu);
}
/**
@ -205,7 +207,7 @@ export class Menu {
onBackdropClick(ev: UIEvent) {
ev.preventDefault();
ev.stopPropagation();
this.menuCtrl.close();
this.close();
}
/**
@ -235,7 +237,7 @@ export class Menu {
return Promise.resolve(this._isOpen);
}
this._before();
this.prepareAnimation()
return this.prepareAnimation()
.then(() => this._startAnimation(shouldOpen, animated))
.then(() => {
this._after(shouldOpen);
@ -558,8 +560,8 @@ export class Menu {
const onBackdropClick = this.onBackdropClick.bind(this);
if (shouldAdd && !this._unregBdClick) {
this._unregBdClick = Context.addListener(this._cntElm, 'click', onBackdropClick, { capture: true });
this._unregCntClick = Context.addListener(this._cntElm, 'click', onBackdropClick, { capture: true });
this._unregBdClick = Context.addListener(this._backdropEle, 'click', onBackdropClick, { capture: true });
this._unregCntClick = Context.addListener(this._backdropEle, 'click', onBackdropClick, { capture: true });
} else if (!shouldAdd && this._unregBdClick) {
this._unregBdClick();

View File

@ -116,20 +116,19 @@
</ion-page>
</ion-app>
<ion-menu-controller></ion-menu-controller>
<script>
function getMenu() {
return document.querySelector('ion-menu-controller');
const menu = document.querySelector('ion-menu-controller');
function openLeft() {
console.log('Open left menu');
menu.open('left');
}
function openLeft() {
console.log('Open left menu');
getMenu().open('left');
}
function openRight() {
console.log('Open right menu');
getMenu().open('right');
}
</script>
function openRight() {
console.log('Open right menu');
menu.open('right');
}
</script>
</body>
</html>