Reorganize imports/exports in order to make snapshot happy

This commit is contained in:
Hristo Hristov
2017-02-28 14:32:40 +02:00
parent 7a56197ba7
commit 2224cd6150
4 changed files with 156 additions and 157 deletions

View File

@ -1,16 +1,21 @@
require("globals");
import { Observable, EventData } from "data/observable";
import { Observable, EventData } from "data/observable";
const events = new Observable();
global.moduleMerge(events, exports);
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";
import { NativeScriptError, UnhandledErrorEventData, iOSApplication, AndroidApplication, CssChangedEventData } from "application";
import { NavigationEntry } from "ui/frame";
import "../bundle-entry-points";
export { Observable };
export const launchEvent = "launch";
export const suspendEvent = "suspend";
export const resumeEvent = "resume";

View File

@ -3,6 +3,7 @@
AndroidApplication as AndroidApplicationDefinition
} from "application";
import {
notify, lowMemoryEvent, orientationChangedEvent, suspendEvent, resumeEvent,
setApplication, livesync, Observable
@ -158,14 +159,6 @@ global.__onLiveSync = function () {
livesync();
};
declare namespace com {
namespace tns {
class NativeScriptApplication extends android.app.Application {
static getInstance(): NativeScriptApplication;
}
}
}
function initLifecycleCallbacks() {
// TODO: Verify whether the logic for triggerring application-wide events based on Activity callbacks is working properly
const lifecycleCallbacks = new android.app.Application.ActivityLifecycleCallbacks({
@ -306,3 +299,11 @@ function ensureBroadCastReceiverClass() {
BroadcastReceiverClass = BroadcastReceiver;
}
declare namespace com {
namespace tns {
class NativeScriptApplication extends android.app.Application {
static getInstance(): NativeScriptApplication;
}
}
}

View File

@ -7,37 +7,160 @@ declare module "application" {
/**
* String value used when hooking to launch event.
*/
export var launchEvent: string;
export const launchEvent: string;
/**
* String value used when hooking to uncaughtError event.
*/
export var uncaughtErrorEvent: string;
export const uncaughtErrorEvent: string;
/**
* String value used when hooking to suspend event.
*/
export var suspendEvent: string;
export const suspendEvent: string;
/**
* String value used when hooking to resume event.
*/
export var resumeEvent: string;
export const resumeEvent: string;
/**
* String value used when hooking to exitevent.
*/
export var exitEvent: string;
export const exitEvent: string;
/**
* String value used when hooking to lowMemory event.
*/
export var lowMemoryEvent: string;
export const lowMemoryEvent: string;
/**
* String value used when hooking to orientationChanged event.
*/
export var orientationChangedEvent: string;
export const orientationChangedEvent: string;
/**
* The main page path (without the file extension) for the application starting from the application root.
* For example if you have page called "main.js" in a folder called "subFolder" and your root folder is "app" you can specify mainModule like this:
* var application = require("application");
* application.mainModule = "app/subFolder/main";
* application.start();
*/
export let mainModule: string;
/**
* The main navigation entry to be used when loading the main Page.
*/
export let mainEntry: NavigationEntry;
/**
* An application level static resources.
*/
export let resources: any;
/**
* The application level css file name (starting from the application root). Used to set css across all pages.
* Css will be applied for every page and page css will be applied after.
*/
export let cssFile: string;
/**
* Sets application level static resources.
*/
export function setResources(resources: any);
/**
* Sets css file name for the application.
*/
export function setCssFileName(cssFile: string): void;
export function addCss(cssText: string): void;
/**
* Notifies all the registered listeners for the event provided in the data.eventName.
* @param data The data associated with the event.
*/
export function notify(data: any): void;
/**
* Call this method to start the application. Important: All code after this method call will not be executed!
*/
export function start(entry?: NavigationEntry);
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
export function on(eventNames: string, callback: (data: any) => void, thisArg?: any);
/**
* Shortcut alias to the removeEventListener method.
* @param eventNames - String corresponding to events (e.g. "onLaunch").
* @param callback - Callback function which will be removed.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
export function off(eventNames: string, callback?: any, thisArg?: any);
/**
* This event is raised when application css is changed.
*/
export function on(event: "cssChanged", callback: (args: CssChangedEventData) => void, thisArg?: any);
/**
* Event raised then livesync operation is performed.
*/
export function on(event: "livesync", callback: (args: EventData) => void);
/**
* This event is raised on application launchEvent.
*/
export function on(event: "launch", callback: (args: LaunchEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is suspended.
*/
export function on(event: "suspend", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is resumed after it has been suspended.
*/
export function on(event: "resume", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is about to exitEvent.
*/
export function on(event: "exit", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when there is low memory on the target device.
*/
export function on(event: "lowMemory", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
/**
* This event is raised the orientation of the current device has changed.
*/
export function on(event: "orientationChanged", callback: (args: OrientationChangedEventData) => void, thisArg?: any);
/**
* This is the Android-specific application object instance.
* Encapsulates methods and properties specific to the Android platform.
* Will be undefined when TargetOS is iOS.
*/
export const android: AndroidApplication;
/**
* This is the iOS-specific application object instance.
* Encapsulates methods and properties specific to the iOS platform.
* Will be undefined when TargetOS is Android.
*/
export const ios: iOSApplication;
/**
* An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code.
@ -112,135 +235,6 @@ declare module "application" {
cssText?: string;
}
/**
* The main page path (without the file extension) for the application starting from the application root.
* For example if you have page called "main.js" in a folder called "subFolder" and your root folder is "app" you can specify mainModule like this:
* var application = require("application");
* application.mainModule = "app/subFolder/main";
* application.start();
*/
export var mainModule: string;
/**
* The main navigation entry to be used when loading the main Page.
*/
export var mainEntry: NavigationEntry;
/**
* An application level static resources.
*/
export var resources: any;
/**
* Sets application level static resources.
*/
export function setResources(resources: any);
/**
* The application level css file name (starting from the application root). Used to set css across all pages.
* Css will be applied for every page and page css will be applied after.
*/
export var cssFile: string;
/**
* Sets css file name for the application.
*/
export function setCssFileName(cssFile: string): void;
export function addCss(cssText: string): void;
/**
* This event is raised when application css is changed.
*/
export function on(event: "cssChanged", callback: (args: CssChangedEventData) => void, thisArg?: any);
/**
* Event raised then livesync operation is performed.
*/
export function on(event: "livesync", callback: (args: EventData) => void);
/**
* Call this method to start the application. Important: All code after this method call will not be executed!
*/
export function start(entry?: NavigationEntry);
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
export function on(eventNames: string, callback: (data: any) => void, thisArg?: any);
/**
* Shortcut alias to the removeEventListener method.
* @param eventNames - String corresponding to events (e.g. "onLaunch").
* @param callback - Callback function which will be removed.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
export function off(eventNames: string, callback?: any, thisArg?: any);
/**
* Notifies all the registered listeners for the event provided in the data.eventName.
* @param data The data associated with the event.
*/
export function notify(data: any): void;
/**
* Checks whether a listener is registered for the specified event name.
* @param eventName The name of the event to check for.
*/
export function hasListeners(eventName: string): boolean;
/**
* This event is raised on application launchEvent.
*/
export function on(event: "launch", callback: (args: LaunchEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is suspended.
*/
export function on(event: "suspend", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is resumed after it has been suspended.
*/
export function on(event: "resume", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is about to exitEvent.
*/
export function on(event: "exit", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when there is low memory on the target device.
*/
export function on(event: "lowMemory", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
/**
* This event is raised the orientation of the current device has changed.
*/
export function on(event: "orientationChanged", callback: (args: OrientationChangedEventData) => void, thisArg?: any);
/**
* This is the Android-specific application object instance.
* Encapsulates methods and properties specific to the Android platform.
* Will be undefined when TargetOS is iOS.
*/
export let android: AndroidApplication;
/**
* This is the iOS-specific application object instance.
* Encapsulates methods and properties specific to the iOS platform.
* Will be undefined when TargetOS is Android.
*/
export let ios: iOSApplication;
/**
* Data for the Android activity events.
*/
@ -542,4 +536,4 @@ declare module "application" {
}
export function getNativeApplication(): any;
}
}

View File

@ -19,6 +19,7 @@ interface MenuItemClickListener {
new (owner: ActionBar): android.support.v7.widget.Toolbar.OnMenuItemClickListener;
}
let appResources: android.content.res.Resources;
let MenuItemClickListener: MenuItemClickListener;
function initializeMenuItemClickListener(): void {
@ -40,6 +41,7 @@ function initializeMenuItemClickListener(): void {
}
MenuItemClickListener = MenuItemClickListenerImpl;
appResources = application.android.context.getResources();
}
export class ActionItem extends ActionItemBase {
@ -101,15 +103,12 @@ export class NavigationButton extends ActionItem {
}
export class ActionBar extends ActionBarBase {
private _appResources: android.content.res.Resources;
private _android: AndroidActionBarSettings;
private _toolbar: android.support.v7.widget.Toolbar;
private _menuItemClickListener: android.support.v7.widget.Toolbar.OnMenuItemClickListener;
constructor() {
super();
this._appResources = application.android.context.getResources();
this._android = new AndroidActionBarSettings(this);
}
@ -201,7 +200,7 @@ export class ActionBar extends ActionBarBase {
}
}
else if (navButton.icon) {
let drawableOrId = getDrawableOrResourceId(navButton.icon, this._appResources);
let drawableOrId = getDrawableOrResourceId(navButton.icon, appResources);
this.nativeView.setNavigationIcon(drawableOrId);
}
@ -225,7 +224,7 @@ export class ActionBar extends ActionBarBase {
if (visibility) {
let icon = this.android.icon;
if (icon !== undefined) {
let drawableOrId = getDrawableOrResourceId(icon, this._appResources);
let drawableOrId = getDrawableOrResourceId(icon, appResources);
if (drawableOrId) {
this.nativeView.setLogo(drawableOrId);
}
@ -280,7 +279,7 @@ export class ActionBar extends ActionBarBase {
}
}
else if (item.icon) {
let drawableOrId = getDrawableOrResourceId(item.icon, this._appResources);
let drawableOrId = getDrawableOrResourceId(item.icon, appResources);
if (drawableOrId) {
menuItem.setIcon(drawableOrId);
}