Skip to content

Commit 2083407

Browse files
committed
Merge pull request #62 from NativeScript/hdeshev/dts-compat
Making d.ts files play nice with angular without needing regex replaces at build time
2 parents f0768cb + 99a280a commit 2083407

File tree

11 files changed

+61
-39
lines changed

11 files changed

+61
-39
lines changed

ng-sample/app/performance/profiling.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ declare var __stopCPUProfiler: any;
55

66
export var ENABLE_PROFILING = true;
77

8+
var anyGlobal = <any>global;
9+
810
export function time(): number {
911
if (!ENABLE_PROFILING) {
1012
return;
1113
}
1214

13-
if (global.android) {
15+
if (anyGlobal.android) {
1416
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
1517
}
1618
else {
@@ -25,17 +27,17 @@ interface TimerInfo {
2527
currentStart: number;
2628
}
2729

28-
if (!global.timers) {
29-
global.timers = new Map<string, TimerInfo>();
30+
if (!anyGlobal.timers) {
31+
anyGlobal.timers = new Map<string, TimerInfo>();
3032
}
3133
export function start(name: string): void {
3234
if (!ENABLE_PROFILING) {
3335
return;
3436
}
3537

3638
var info: TimerInfo;
37-
if (global.timers.has(name)) {
38-
info = global.timers.get(name);
39+
if (anyGlobal.timers.has(name)) {
40+
info = anyGlobal.timers.get(name);
3941
if (info.currentStart != 0) {
4042
throw new Error(`Timer already started: ${name}`);
4143
}
@@ -47,7 +49,7 @@ export function start(name: string): void {
4749
count: 0,
4850
currentStart: time()
4951
};
50-
global.timers.set(name, info);
52+
anyGlobal.timers.set(name, info);
5153
}
5254
}
5355

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

71-
global.timers.delete(name);
73+
anyGlobal.timers.delete(name);
7274
}
7375

7476
function pauseInternal(name: string): TimerInfo {
75-
var info = global.timers.get(name);
77+
var info = anyGlobal.timers.get(name);
7678
if (!info) {
7779
throw new Error(`No timer started: ${name}`);
7880
}
@@ -90,7 +92,7 @@ export function startCPUProfile(name: string) {
9092
return;
9193
}
9294

93-
if (global.android) {
95+
if (anyGlobal.android) {
9496
__startCPUProfiler(name);
9597
}
9698
}
@@ -100,7 +102,7 @@ export function stopCPUProfile(name: string) {
100102
return;
101103
}
102104

103-
if (global.android) {
105+
if (anyGlobal.android) {
104106
__stopCPUProfiler(name);
105107
}
106108
}

ng-sample/app/starter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
declare var java: any;
22
declare var CACurrentMediaTime: any;
33

4-
if (!global.timers) {
5-
global.timers = new Map();
4+
var anyGlobal = <any>global;
5+
6+
if (!anyGlobal.timers) {
7+
anyGlobal.timers = new Map();
68
}
79

810
function time() {
9-
if (global.android) {
11+
if (anyGlobal.android) {
1012
return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns
1113
}
1214
else {
@@ -20,6 +22,6 @@ var timerEntry = {
2022
currentStart: time()
2123
};
2224

23-
global.timers.set("application-start", timerEntry);
25+
anyGlobal.timers.set("application-start", timerEntry);
2426

2527
import "./app.js"

ng-sample/hooks/before-prepare/15-remove-unsupported-angular-typings.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

ng-sample/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/NativeScript/template-hello-world",
2525
"dependencies": {
26-
"tns-core-modules": "^1.6.0-angular-2",
26+
"tns-core-modules": "^1.6.0-angular-4",
2727
"angular2": "2.0.0-beta.2",
2828
"parse5": "1.4.2",
2929
"punycode": "1.3.2",

ng-sample/tsconfig.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,37 @@
1111
"noEmitOnError": true
1212
},
1313
"filesGlob": [
14-
"node_modules/tns-core-modules/tns-core-modules.d.ts",
1514
"app/**/*.ts"
1615
],
16+
"files": [
17+
"node_modules/tns-core-modules/tns-core-modules.base.d.ts",
18+
"app/nativescript-angular/application.ts",
19+
"app/nativescript-angular/dom_adapter.ts",
20+
"app/nativescript-angular/text-value-accessor.ts",
21+
"app/nativescript-angular/element-registry.d.ts",
22+
"app/nativescript-angular/zone.ts",
23+
"app/nativescript-angular/application.d.ts",
24+
"app/nativescript-angular/renderer.ts",
25+
"app/nativescript-angular/element-registry.ts",
26+
"app/nativescript-angular/xhr.ts",
27+
"app/nativescript-angular/zone_patch.ts",
28+
"app/nativescript-angular/directives/ns-directives.ts",
29+
"app/nativescript-angular/directives/tab-view.ts",
30+
"app/nativescript-angular/directives/list-view.ts",
31+
"app/nativescript-angular/polyfills/array.ts",
32+
"app/nativescript-angular/view-util.ts",
33+
"app/examples/list/list-test.ts",
34+
"app/examples/list/list-test-async.ts",
35+
"app/examples/image/image-test.ts",
36+
"app/examples/renderer-test.ts",
37+
"app/main-page.ts",
38+
"app/performance/benchmark.ts",
39+
"app/performance/profiling.ts",
40+
"app/main-view-model.ts",
41+
"app/app.ts",
42+
"app/global.d.ts",
43+
"app/starter.ts"
44+
],
1745
"exclude": [
1846
"node_modules",
1947
"platforms"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"scripts": {},
1616
"dependencies": {
17-
"tns-core-modules": "^1.6.0-angular-2",
17+
"tns-core-modules": "^1.6.0-angular-4",
1818
"angular2": "2.0.0-beta.2",
1919
"es6-shim": "^0.33.3",
2020
"parse5": "1.4.2",

src/global.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
/// <reference path="../node_modules/tns-core-modules/tns-core-modules.d.ts" />
21
declare var assert: any;
32

43
interface Map<K, V> {
54
keys(): Array<K>;
65
values(): Array<V>;
76
}
87

9-
declare type MapConstructor = typeof Map;
10-
declare type SetConstructor = typeof Set;
8+
declare type NativeScriptModule = NodeModule
9+
declare type NativeScriptRequire = NodeRequire
10+
11+
//declare type MapConstructor = typeof Map;
12+
//declare type SetConstructor = typeof Set;
1113

1214
interface NumberConstructor {
1315
isInteger(number: number): boolean;

src/nativescript-angular/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class NativeScriptRenderer extends Renderer {
149149

150150
public listen(renderElement: util.NgView, eventName: string, callback: Function): Function {
151151
console.log('NativeScriptRenderer.listen: ' + eventName);
152-
let zonedCallback = global.zone.bind(callback);
152+
let zonedCallback = (<any>global).zone.bind(callback);
153153
renderElement.on(eventName, zonedCallback);
154154
return () => renderElement.off(eventName, zonedCallback);
155155
}

src/nativescript-angular/router/page-router-outlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class PageShim implements OnActivate, OnDeactivate {
279279
resolve()
280280
});
281281

282-
page.on('navigatingFrom', global.zone.bind((args: NavigatedData) => {
282+
page.on('navigatingFrom', (<any>global).zone.bind((args: NavigatedData) => {
283283
if (args.isBackNavigation) {
284284
startGoBack();
285285
this.locationStrategy.back();
@@ -313,4 +313,4 @@ class PageShim implements OnActivate, OnDeactivate {
313313
private log(methodName: string) {
314314
log("PageShim(" + this.id + ")." + methodName)
315315
}
316-
}
316+
}

src/nativescript-angular/zone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import NativeScriptPatch from "./zone_patch"
44

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

7-
global.Zone = core.Zone;
8-
global.zone = new core.Zone();
7+
(<any>global).Zone = core.Zone;
8+
(<any>global).zone = new core.Zone();
99

1010
NativeScriptPatch.apply();

0 commit comments

Comments
 (0)