Added current variable in the Application module (to provide a shortcut to the Application singleton).

This commit is contained in:
atanasovg
2014-05-07 15:50:06 +03:00
parent beba0ae4f4
commit 6e2eae411f
9 changed files with 37 additions and 39 deletions

View File

@@ -1,14 +1,13 @@
import app_common_module = require("Application/application_common");
import appModule = require("Application/application_common");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("Utils/module_merge").merge(app_common_module, exports);
require("Utils/module_merge").merge(appModule, exports);
var currentApp = app_common_module.Application.current;
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
var initEvents = function () {
var androidApp = app_common_module.Application.current.android;
var androidApp = appModule.current.android;
var lifecycleCallbacks = new callbacks({
onActivityCreated: function (activity: any, bundle: any) {
if (!androidApp.startActivity) {
@@ -92,8 +91,8 @@ var initEvents = function () {
export var init = function (nativeApp: android.app.Application) {
var app = new AndroidApplication(nativeApp);
currentApp.os = app_common_module.TargetOS.Android;
currentApp.android = app;
appModule.current.os = appModule.TargetOS.Android;
appModule.current.android = app;
app.init();
}

View File

@@ -3,8 +3,9 @@
Android
}
export declare var current: Application;
export declare class Application {
static current: Application;
public os: TargetOS;
public onLaunch: () => any;

View File

@@ -20,19 +20,17 @@ log("JavaScript loading ended.");
*/
import app_common_module = require("Application/application_common");
import appModule = require("Application/application_common");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("Utils/module_merge").merge(app_common_module, exports);
var currentApp = app_common_module.Application.current;
require("Utils/module_merge").merge(appModule, exports);
// TODO: Declarations
export var init = function (nativeApp: any) {
var app = new iOSApplication(nativeApp);
currentApp.os = app_common_module.TargetOS.iOS;
currentApp.ios = app;
appModule.current.os = appModule.TargetOS.iOS;
appModule.current.ios = app;
app.init();
}
@@ -57,10 +55,10 @@ class iOSApplication {
this.window.backgroundColor = UIKit.UIColor.whiteColor();
this.window.makeKeyAndVisible();
var iosApp = currentApp.ios;
var iosApp = appModule.current.ios;
if (currentApp.onLaunch) {
this.window.rootViewController = currentApp.onLaunch();
if (appModule.current.onLaunch) {
this.window.rootViewController = appModule.current.onLaunch();
} else {
log("Missing TK.UI.Application.current.onLaunch");
}
@@ -71,8 +69,8 @@ class iOSApplication {
applicationDidBecomeActive: function (application) {
log("applicationDidBecomeActive: " + application);
if (currentApp.onResume) {
currentApp.onResume();
if (appModule.current.onResume) {
appModule.current.onResume();
}
},
@@ -82,8 +80,8 @@ class iOSApplication {
applicationDidEnterBackground: function (application) {
log("applicationDidEnterBackground: " + application);
if (currentApp.onSuspend) {
currentApp.onSuspend();
if (appModule.current.onSuspend) {
appModule.current.onSuspend();
}
},
@@ -93,15 +91,15 @@ class iOSApplication {
applicationWillTerminate: function (application) {
log("applicationWillTerminate: " + application);
if (currentApp.onExit) {
currentApp.onExit();
if (appModule.current.onExit) {
appModule.current.onExit();
}
},
applicationDidReceiveMemoryWarning: function (application) {
log("applicationDidReceiveMemoryWarning: " + application);
if (currentApp.onLowMemory) {
currentApp.onLowMemory();
if (appModule.current.onLowMemory) {
appModule.current.onLowMemory();
}
}
}

View File

@@ -18,9 +18,9 @@ export class Application {
public onExit: () => any;
public onLowMemory: () => any;
public static current: Application = new Application();
// TODO: These fields are declared by the application.d.ts file and intellisense will come from there
public android: any;
public ios: any;
}
}
export var current = new Application();