From a6fa0781f78d4044f102e51e324e43183522e9ce Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Mon, 6 Mar 2017 18:18:31 +0200 Subject: [PATCH] Observable needs __extends function which comes from globals in the case of Snapshot. --- .../application/application-common.ts | 17 ++++++----------- tns-core-modules/platform/platform.android.ts | 10 ++++------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tns-core-modules/application/application-common.ts b/tns-core-modules/application/application-common.ts index 76b67ebe1..8110203d3 100644 --- a/tns-core-modules/application/application-common.ts +++ b/tns-core-modules/application/application-common.ts @@ -1,16 +1,11 @@ -import { Observable, EventData } from "data/observable"; +// Require globals first so that snapshot takes __extends function. +require("globals"); + +import { Observable, EventData } from "data/observable"; const events = new Observable(); -function __export(m) { - for (var p in m) { if (!exports.hasOwnProperty(p)) { exports[p] = m[p]; } } -} - -__export(events); - -export { Observable }; - -// NOTE: This requires modules that requires application.on so the above should be done before globals is required. -import "globals"; +// First merge all functions from events into application-common so that later appModule.on will be defined. +global.moduleMerge(events, exports); import { NativeScriptError, UnhandledErrorEventData, iOSApplication, AndroidApplication, CssChangedEventData } from "application"; import { NavigationEntry } from "ui/frame"; diff --git a/tns-core-modules/platform/platform.android.ts b/tns-core-modules/platform/platform.android.ts index cf62f2aae..527e85f3f 100644 --- a/tns-core-modules/platform/platform.android.ts +++ b/tns-core-modules/platform/platform.android.ts @@ -101,12 +101,7 @@ class Device implements DeviceDefinition { class MainScreen implements ScreenMetricsDefinition { private _metrics: android.util.DisplayMetrics; - - constructor() { - // NOTE: This will be memory leak but we MainScreen is singleton - appModule.on("cssChanged", this.cssChanged, this); - } - + private cssChanged(args: appModule.CssChangedEventData): void { if (!this._metrics) { this._metrics = new android.util.DisplayMetrics(); @@ -121,6 +116,9 @@ class MainScreen implements ScreenMetricsDefinition { private get metrics(): android.util.DisplayMetrics { if (!this._metrics) { + // NOTE: This will be memory leak but we MainScreen is singleton + appModule.on("cssChanged", this.cssChanged, this); + this._metrics = new android.util.DisplayMetrics(); this.initMetrics(); }