Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions ng-sample/app/performance/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ declare var __stopCPUProfiler: any;

export var ENABLE_PROFILING = true;

var anyGlobal = <any>global;

export function time(): number {
if (!ENABLE_PROFILING) {
return;
}

if (global.android) {
if (anyGlobal.android) {
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
}
else {
Expand All @@ -25,17 +27,17 @@ interface TimerInfo {
currentStart: number;
}

if (!global.timers) {
global.timers = new Map<string, TimerInfo>();
if (!anyGlobal.timers) {
anyGlobal.timers = new Map<string, TimerInfo>();
}
export function start(name: string): void {
if (!ENABLE_PROFILING) {
return;
}

var info: TimerInfo;
if (global.timers.has(name)) {
info = global.timers.get(name);
if (anyGlobal.timers.has(name)) {
info = anyGlobal.timers.get(name);
if (info.currentStart != 0) {
throw new Error(`Timer already started: ${name}`);
}
Expand All @@ -47,7 +49,7 @@ export function start(name: string): void {
count: 0,
currentStart: time()
};
global.timers.set(name, info);
anyGlobal.timers.set(name, info);
}
}

Expand All @@ -68,11 +70,11 @@ export function stop(name: string) {
var info = pauseInternal(name);
console.log(`---- [${name}] STOP total: ${info.totalTime} count:${info.count}`);

global.timers.delete(name);
anyGlobal.timers.delete(name);
}

function pauseInternal(name: string): TimerInfo {
var info = global.timers.get(name);
var info = anyGlobal.timers.get(name);
if (!info) {
throw new Error(`No timer started: ${name}`);
}
Expand All @@ -90,7 +92,7 @@ export function startCPUProfile(name: string) {
return;
}

if (global.android) {
if (anyGlobal.android) {
__startCPUProfiler(name);
}
}
Expand All @@ -100,7 +102,7 @@ export function stopCPUProfile(name: string) {
return;
}

if (global.android) {
if (anyGlobal.android) {
__stopCPUProfiler(name);
}
}
10 changes: 6 additions & 4 deletions ng-sample/app/starter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
declare var java: any;
declare var CACurrentMediaTime: any;

if (!global.timers) {
global.timers = new Map();
var anyGlobal = <any>global;

if (!anyGlobal.timers) {
anyGlobal.timers = new Map();
}

function time() {
if (global.android) {
if (anyGlobal.android) {
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
}
else {
Expand All @@ -20,6 +22,6 @@ var timerEntry = {
currentStart: time()
};

global.timers.set("application-start", timerEntry);
anyGlobal.timers.set("application-start", timerEntry);

import "./app.js"

This file was deleted.

2 changes: 1 addition & 1 deletion ng-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/NativeScript/template-hello-world",
"dependencies": {
"tns-core-modules": "^1.6.0-angular-2",
"tns-core-modules": "^1.6.0-angular-4",
"angular2": "2.0.0-beta.2",
"parse5": "1.4.2",
"punycode": "1.3.2",
Expand Down
30 changes: 29 additions & 1 deletion ng-sample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,37 @@
"noEmitOnError": true
},
"filesGlob": [
"node_modules/tns-core-modules/tns-core-modules.d.ts",
"app/**/*.ts"
],
"files": [
"node_modules/tns-core-modules/tns-core-modules.base.d.ts",
"app/nativescript-angular/application.ts",
"app/nativescript-angular/dom_adapter.ts",
"app/nativescript-angular/text-value-accessor.ts",
"app/nativescript-angular/element-registry.d.ts",
"app/nativescript-angular/zone.ts",
"app/nativescript-angular/application.d.ts",
"app/nativescript-angular/renderer.ts",
"app/nativescript-angular/element-registry.ts",
"app/nativescript-angular/xhr.ts",
"app/nativescript-angular/zone_patch.ts",
"app/nativescript-angular/directives/ns-directives.ts",
"app/nativescript-angular/directives/tab-view.ts",
"app/nativescript-angular/directives/list-view.ts",
"app/nativescript-angular/polyfills/array.ts",
"app/nativescript-angular/view-util.ts",
"app/examples/list/list-test.ts",
"app/examples/list/list-test-async.ts",
"app/examples/image/image-test.ts",
"app/examples/renderer-test.ts",
"app/main-page.ts",
"app/performance/benchmark.ts",
"app/performance/profiling.ts",
"app/main-view-model.ts",
"app/app.ts",
"app/global.d.ts",
"app/starter.ts"
],
"exclude": [
"node_modules",
"platforms"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {},
"dependencies": {
"tns-core-modules": "^1.6.0-angular-2",
"tns-core-modules": "^1.6.0-angular-4",
"angular2": "2.0.0-beta.2",
"es6-shim": "^0.33.3",
"parse5": "1.4.2",
Expand Down
8 changes: 5 additions & 3 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/// <reference path="../node_modules/tns-core-modules/tns-core-modules.d.ts" />
declare var assert: any;

interface Map<K, V> {
keys(): Array<K>;
values(): Array<V>;
}

declare type MapConstructor = typeof Map;
declare type SetConstructor = typeof Set;
declare type NativeScriptModule = NodeModule
declare type NativeScriptRequire = NodeRequire

//declare type MapConstructor = typeof Map;
//declare type SetConstructor = typeof Set;

interface NumberConstructor {
isInteger(number: number): boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/nativescript-angular/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class NativeScriptRenderer extends Renderer {

public listen(renderElement: util.NgView, eventName: string, callback: Function): Function {
console.log('NativeScriptRenderer.listen: ' + eventName);
let zonedCallback = global.zone.bind(callback);
let zonedCallback = (<any>global).zone.bind(callback);
renderElement.on(eventName, zonedCallback);
return () => renderElement.off(eventName, zonedCallback);
}
Expand Down
4 changes: 2 additions & 2 deletions src/nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class PageShim implements OnActivate, OnDeactivate {
resolve()
});

page.on('navigatingFrom', global.zone.bind((args: NavigatedData) => {
page.on('navigatingFrom', (<any>global).zone.bind((args: NavigatedData) => {
if (args.isBackNavigation) {
startGoBack();
this.locationStrategy.back();
Expand Down Expand Up @@ -313,4 +313,4 @@ class PageShim implements OnActivate, OnDeactivate {
private log(methodName: string) {
log("PageShim(" + this.id + ")." + methodName)
}
}
}
4 changes: 2 additions & 2 deletions src/nativescript-angular/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NativeScriptPatch from "./zone_patch"

var core = require('zone.js/lib/core.js');

global.Zone = core.Zone;
global.zone = new core.Zone();
(<any>global).Zone = core.Zone;
(<any>global).zone = new core.Zone();

NativeScriptPatch.apply();
4 changes: 2 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"querystring": "0.2.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"tns-core-modules": "1.6.0-angular-2",
"tns-core-modules": "1.6.0-angular-4",
"url": "0.10.3",
"zone.js": "0.5.10"
},
Expand All @@ -52,4 +52,4 @@
"shelljs": "^0.5.3",
"typescript": "^1.7.5"
}
}
}