feat: OnDiscardedError typings and event (#6777)

* feat: OnDiscardedError typings and event

* remove ios and android from DiscardedErrorEventData
This commit is contained in:
Vasil Trifonov
2019-01-09 18:24:25 +02:00
committed by GitHub
parent 4cda0e7345
commit 28db2afbd4
5 changed files with 47 additions and 10 deletions

View File

@@ -38,10 +38,11 @@ import {
getRootView,
iOSApplication,
LoadAppCSSEventData,
UnhandledErrorEventData
UnhandledErrorEventData,
DiscardedErrorEventData
} from "./application";
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData };
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
export const launchEvent = "launch";
export const suspendEvent = "suspend";
@@ -50,6 +51,7 @@ export const resumeEvent = "resume";
export const exitEvent = "exit";
export const lowMemoryEvent = "lowMemory";
export const uncaughtErrorEvent = "uncaughtError";
export const discardedErrorEvent = "discardedError";
export const orientationChangedEvent = "orientationChanged";
let cssFile: string = "./app.css";
@@ -122,3 +124,7 @@ export function addCss(cssText: string): void {
global.__onUncaughtError = function (error: NativeScriptError) {
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
}
global.__onDiscardedError = function (error: NativeScriptError) {
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
}

View File

@@ -21,6 +21,11 @@ export var displayedEvent: string;
*/
export var uncaughtErrorEvent: string;
/**
* String value used when hooking to discardedError event.
*/
export var discardedErrorEvent: string;
/**
* String value used when hooking to suspend event.
*/
@@ -103,6 +108,13 @@ export interface UnhandledErrorEventData extends ApplicationEventData {
error: NativeScriptError;
}
/**
* Event data containing information about discarded application errors.
*/
export interface DiscardedErrorEventData extends ApplicationEventData {
error: NativeScriptError;
}
/**
* Event data containing information about application css change.
*/
@@ -137,7 +149,7 @@ export function setResources(res: any): void;
export function setResources(resources: any);
/**
* Sets css file name for the application.
* Sets css file name for the application.
*/
export function setCssFileName(cssFile: string): void;
@@ -199,7 +211,7 @@ export function shouldCreateRootFrame(): boolean;
/**
* 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 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.
*/
@@ -262,6 +274,11 @@ export function on(event: "lowMemory", callback: (args: ApplicationEventData) =>
*/
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
/**
* This event is raised when an discarded error occurs while the application is running.
*/
export function on(event: "discardedError", callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
/**
* This event is raised the orientation of the current device has changed.
*/
@@ -403,13 +420,13 @@ export class AndroidApplication extends Observable {
/**
* Initialized the android-specific application object with the native android.app.Application instance.
* This is useful when creating custom application types.
* @param nativeApp - the android.app.Application instance that started the app.
* @param nativeApp - the android.app.Application instance that started the app.
*/
init: (nativeApp) => void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @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.
*/
@@ -516,7 +533,7 @@ export class AndroidApplication extends Observable {
public static activityRequestPermissionsEvent: string;
/**
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
* @param intentFilter A string containing the intent filter.
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
@@ -524,7 +541,7 @@ export class AndroidApplication extends Observable {
registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
/**
* Unregister a previously registered BroadcastReceiver.
* Unregister a previously registered BroadcastReceiver.
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
*/