mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added Application module comments. Modified Console module + comments. Changed the package name of the UnitTestApp for Android.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
export class ConsoleHelper {
|
||||
static TAG: string = 'JS';
|
||||
|
||||
static log(message: string): void {
|
||||
android.util.Log.v(ConsoleHelper.TAG, message);
|
||||
}
|
||||
|
||||
static info(message: string): void {
|
||||
android.util.Log.i(ConsoleHelper.TAG, message);
|
||||
}
|
||||
|
||||
static error(message: string): void {
|
||||
android.util.Log.e(ConsoleHelper.TAG, message);
|
||||
}
|
||||
|
||||
static warn(message: string): void {
|
||||
android.util.Log.w(ConsoleHelper.TAG, message);
|
||||
}
|
||||
|
||||
static timeMillis(): number {
|
||||
// NOTE: we might need to use currentTimeMillis if we have troubles with the long size
|
||||
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
|
||||
}
|
||||
}
|
||||
63
Console/console.d.ts
vendored
63
Console/console.d.ts
vendored
@@ -1,19 +1,50 @@
|
||||
export declare class TKConsole implements i.IConsole {
|
||||
/**
|
||||
* Encapsulates methods used to report some information to the console.
|
||||
* Instance of this class is declared in the global JavaScript context and is accessible by directly calling console.[xxx] methods.
|
||||
*/
|
||||
export declare class Console {
|
||||
/**
|
||||
* Begins counting a time span for a given name (key).
|
||||
*/
|
||||
public time(reportName: string): void;
|
||||
public timeEnd(reportName: string): void;
|
||||
public assert(test: boolean, message: string, ...optionalParams: any[]): void;
|
||||
public info(message: any, ...optionalParams: any[]): void;
|
||||
public warn(message: any, ...optionalParams: any[]): void;
|
||||
public error(message: any, ...optionalParams: any[]): void;
|
||||
public log(message: any, ...optionalParams: any[]): void;
|
||||
public trace(): void;
|
||||
public dump(obj: any): void;
|
||||
}
|
||||
|
||||
export declare class ConsoleHelper {
|
||||
static log(message: string): void;
|
||||
static info(message: string): void;
|
||||
static error(message: string): void;
|
||||
static warn(message: string): void;
|
||||
static timeMillis(): number;
|
||||
/**
|
||||
* Ends a previously started time span through the time method.
|
||||
*/
|
||||
public timeEnd(reportName: string): void;
|
||||
|
||||
/**
|
||||
* Asserts a boolean condition and prints a message in case the assert fails.
|
||||
*/
|
||||
public assert(test: boolean, message: string, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports some information.
|
||||
*/
|
||||
public info(message: any, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports a warning.
|
||||
*/
|
||||
public warn(message: any, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports an error.
|
||||
*/
|
||||
public error(message: any, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Verbously logs a message.
|
||||
*/
|
||||
public log(message: any, ...optionalParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Prints the current stack trace in the console.
|
||||
*/
|
||||
public trace(): void;
|
||||
|
||||
/**
|
||||
* Prints the state of the specified object to the console.
|
||||
*/
|
||||
public dump(obj: any): void;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
export class ConsoleHelper {
|
||||
// FIXME: we should use Foundation.NSLog() but it currently does not work
|
||||
static log(message: string): void {
|
||||
log('log: ' + message);
|
||||
}
|
||||
|
||||
static info(message: string): void {
|
||||
log('info: ' + message);
|
||||
}
|
||||
|
||||
static error(message: string): void {
|
||||
log('error: ' + message);
|
||||
}
|
||||
|
||||
static warn(message: string): void {
|
||||
log('warning: ' + message);
|
||||
}
|
||||
|
||||
static timeMillis(): number {
|
||||
return QuartzCore.CACurrentMediaTime() * 1000;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
import helperModule = require("Console/console_helper");
|
||||
|
||||
import native_module = require("Console/console");
|
||||
|
||||
export class TKConsole {
|
||||
private _nativeClass: any;
|
||||
export class Console {
|
||||
private _timers: any;
|
||||
|
||||
constructor() {
|
||||
this._nativeClass = native_module.ConsoleHelper;
|
||||
this._timers = {};
|
||||
}
|
||||
|
||||
@@ -216,7 +213,7 @@ export class TKConsole {
|
||||
public time(reportName: string): void {
|
||||
var name = reportName ? '__' + reportName : '__internal_console_time__';
|
||||
if (('undefined' === typeof (this._timers[name])) || (this._timers.hasOwnProperty(name))) {
|
||||
this._timers[name] = this._nativeClass.timeMillis();
|
||||
this._timers[name] = helperModule.timeMillis();
|
||||
}
|
||||
else {
|
||||
this.warn('invalid name for timer console.time(' + reportName + ')');
|
||||
@@ -228,7 +225,7 @@ export class TKConsole {
|
||||
if (this._timers.hasOwnProperty(name)) {
|
||||
var val = this._timers[name];
|
||||
if (val) {
|
||||
var time = this._nativeClass.timeMillis();
|
||||
var time = helperModule.timeMillis();
|
||||
this.info('console.time(' + reportName + '): %.6f ms', (time - val));
|
||||
this._timers[name] = undefined;
|
||||
}
|
||||
@@ -241,7 +238,7 @@ export class TKConsole {
|
||||
public assert(test: boolean, message: string, ...optionalParams: any[]): void {
|
||||
if (!test) {
|
||||
Array.prototype.shift.apply(arguments);
|
||||
this._nativeClass.error(this.formatParams.apply(this, arguments));
|
||||
helperModule.error(this.formatParams.apply(this, arguments));
|
||||
|
||||
// duplicating trace code here because android version shows only 2 frames and if we call trace()
|
||||
// this would be assert() and trace() which leaves all important stack frames out of our view
|
||||
@@ -269,19 +266,19 @@ export class TKConsole {
|
||||
}
|
||||
|
||||
public info(message: any, ...optionalParams: any[]): void {
|
||||
this._nativeClass.info(this.formatParams.apply(this, arguments));
|
||||
helperModule.info(this.formatParams.apply(this, arguments));
|
||||
}
|
||||
|
||||
public warn(message: any, ...optionalParams: any[]): void {
|
||||
this._nativeClass.warn(this.formatParams.apply(this, arguments));
|
||||
helperModule.warn(this.formatParams.apply(this, arguments));
|
||||
}
|
||||
|
||||
public error(message: any, ...optionalParams: any[]): void {
|
||||
this._nativeClass.error(this.formatParams.apply(this, arguments));
|
||||
helperModule.error(this.formatParams.apply(this, arguments));
|
||||
}
|
||||
|
||||
public log(message: any, ...optionalParams: any[]): void {
|
||||
this._nativeClass.log(this.formatParams.apply(this, arguments));
|
||||
helperModule.log(this.formatParams.apply(this, arguments));
|
||||
}
|
||||
|
||||
public trace(): void {
|
||||
22
Console/console_helper.android.ts
Normal file
22
Console/console_helper.android.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
var TAG = 'JS';
|
||||
|
||||
export var log = function (message: string) {
|
||||
android.util.Log.v(TAG, message);
|
||||
}
|
||||
|
||||
export var info = function (message: string) {
|
||||
android.util.Log.i(TAG, message);
|
||||
}
|
||||
|
||||
export var error = function (message: string) {
|
||||
android.util.Log.e(TAG, message);
|
||||
}
|
||||
|
||||
export var warn = function (message: string) {
|
||||
android.util.Log.w(TAG, message);
|
||||
}
|
||||
|
||||
export var timeMillis = function (): number {
|
||||
// NOTE: we might need to use currentTimeMillis if we have troubles with the long size
|
||||
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
|
||||
}
|
||||
5
Console/console_helper.d.ts
vendored
Normal file
5
Console/console_helper.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare var log: (message: string) => void;
|
||||
export declare var info: (message: string) => void;
|
||||
export declare var error: (message: string) => void;
|
||||
export declare var warn: (message: string) => void;
|
||||
export declare var timeMillis: () => number;
|
||||
22
Console/console_helper.ios.ts
Normal file
22
Console/console_helper.ios.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// TODO: we should use Foundation.NSLog() but it currently does not work
|
||||
// TODO: Is there a better way to implement the info/warn/error
|
||||
|
||||
export var log = function (message: string) {
|
||||
log('log: ' + message);
|
||||
}
|
||||
|
||||
export var info = function (message: string) {
|
||||
log('info: ' + message);
|
||||
}
|
||||
|
||||
export var error = function (message: string) {
|
||||
log('error: ' + message);
|
||||
}
|
||||
|
||||
export var warn = function (message: string) {
|
||||
log('warning: ' + message);
|
||||
}
|
||||
|
||||
export var timeMillis = function (): number {
|
||||
return QuartzCore.CACurrentMediaTime() * 1000;
|
||||
}
|
||||
Reference in New Issue
Block a user