fix(prerender): local references to window/document

This commit is contained in:
Manu Mtz.-Almeida
2018-04-19 13:26:49 +02:00
parent 86a6cde4a1
commit 78bd146ad2
42 changed files with 174 additions and 139 deletions

View File

@ -6,6 +6,8 @@ import { Component, Listen, Prop, State } from '@stencil/core';
})
export class MenuToggle {
@Prop({ context: 'document' }) doc: Document;
@State() visible = false;
/**
@ -25,7 +27,7 @@ export class MenuToggle {
@Listen('child:click')
async onClick() {
const menuCtrl = await getMenuController();
const menuCtrl = await getMenuController(this.doc);
if (menuCtrl) {
const menu = menuCtrl.get(this.menu);
if (menu && menu.isActive()) {
@ -38,7 +40,7 @@ export class MenuToggle {
@Listen('body:ionMenuChange')
@Listen('body:ionSplitPaneVisible')
async updateVisibility() {
const menuCtrl = await getMenuController();
const menuCtrl = await getMenuController(this.doc);
if (menuCtrl) {
const menu = menuCtrl.get(this.menu);
if (menu && menu.isActive()) {
@ -60,8 +62,8 @@ export class MenuToggle {
}
function getMenuController(): Promise<HTMLIonMenuControllerElement|undefined> {
const menuControllerElement = document.querySelector('ion-menu-controller');
function getMenuController(doc: Document): Promise<HTMLIonMenuControllerElement|undefined> {
const menuControllerElement = doc.querySelector('ion-menu-controller');
if (!menuControllerElement) {
return Promise.resolve(undefined);
}