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); this.registerAnimation('overlay', MenuOverlayAnimation);
} }
@Method()
getInstance(): MenuController {
return this;
}
/** /**
* Programatically open the Menu. * Programatically open the Menu.
* @param {string} [menuId] Optionally get the menu by its id, or side. * @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 { MenuController } from './menu-controller';
import { isRightSide, Side, assert, checkEdgeSide } from '../../utils/helpers'; import { isRightSide, Side, assert, checkEdgeSide } from '../../utils/helpers';
export type Lazy<T> = export type Lazy<T> = T &
{[P in keyof T]: (...args: any[]) => Promise<any>; }; { componentOnReady(): Promise<T> } &
{ componentOnReady(done: (cmp: T) => void): void }
@Component({ @Component({
tag: 'ion-menu', tag: 'ion-menu',
@ -113,7 +114,8 @@ export class Menu {
} }
ionViewWillLoad() { 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) { onBackdropClick(ev: UIEvent) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
this.menuCtrl.close(); this.close();
} }
/** /**
@ -235,7 +237,7 @@ export class Menu {
return Promise.resolve(this._isOpen); return Promise.resolve(this._isOpen);
} }
this._before(); this._before();
this.prepareAnimation() return this.prepareAnimation()
.then(() => this._startAnimation(shouldOpen, animated)) .then(() => this._startAnimation(shouldOpen, animated))
.then(() => { .then(() => {
this._after(shouldOpen); this._after(shouldOpen);
@ -558,8 +560,8 @@ export class Menu {
const onBackdropClick = this.onBackdropClick.bind(this); const onBackdropClick = this.onBackdropClick.bind(this);
if (shouldAdd && !this._unregBdClick) { if (shouldAdd && !this._unregBdClick) {
this._unregBdClick = Context.addListener(this._cntElm, 'click', onBackdropClick, { capture: true }); this._unregBdClick = Context.addListener(this._backdropEle, 'click', onBackdropClick, { capture: true });
this._unregCntClick = Context.addListener(this._cntElm, 'click', onBackdropClick, { capture: true }); this._unregCntClick = Context.addListener(this._backdropEle, 'click', onBackdropClick, { capture: true });
} else if (!shouldAdd && this._unregBdClick) { } else if (!shouldAdd && this._unregBdClick) {
this._unregBdClick(); this._unregBdClick();

View File

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