Skip to content

Commit a68649d

Browse files
author
Nedyalko Nikolov
authored
Merge pull request #548 from NativeScript/nnikolov/Es6Modules
[DON'T MERGE] Make nativescript-angular modules es6.
2 parents 9af7f3d + 0b2c644 commit a68649d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+224
-172
lines changed

Diff for: .gitignore

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ tags
66

77
/hooks
88

9-
nativescript-angular/**/*.d.ts
10-
!nativescript-angular/global.d.ts
11-
nativescript-angular/**/*.js
12-
!nativescript-angular/postinstall.js
13-
!nativescript-angular/hooks/**/*.js
14-
!nativescript-angular/gulpfile.js
9+
/nativescript-angular/**/*.d.ts
10+
/nativescript-angular/**/*.js
11+
12+
!/nativescript-angular/global.d.ts
13+
!/nativescript-angular/postinstall.js
14+
!/nativescript-angular/hooks/**/*.js
15+
!/nativescript-angular/gulpfile.js
16+
!/nativescript-angular/rollup.config.js
17+
!/nativescript-angular/rollup-entry.js
18+
!/nativescript-angular/zone-js/**/*.js
1519

1620
.tscache
1721
.nvm

Diff for: nativescript-angular/animation-player.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { View } from "ui/core/view";
1010
import { AnimationCurve } from "ui/enums";
1111
import { ValueSource } from "ui/core/dependency-observable";
1212
import { isString } from "utils/types";
13-
import * as styleProperty from "ui/styling/style-property";
13+
import { getPropertyByCssName, KeyValuePair, Property } from "ui/styling/style-property";
1414

1515
export class NativeScriptAnimationPlayer implements AnimationPlayer {
1616

@@ -60,7 +60,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
6060
for (let style of keyframe.styles.styles) {
6161
for (let substyle in style) {
6262
let value = style[substyle];
63-
let property = styleProperty.getPropertyByCssName(substyle);
63+
let property = getPropertyByCssName(substyle);
6464
if (property) {
6565
if (typeof value === "string" && property.valueConverter) {
6666
value = property.valueConverter(<string>value);
@@ -218,7 +218,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
218218

219219
static parseTransform(value: string, animationInfo: KeyframeInfo) {
220220
let newTransform = NativeScriptAnimationPlayer.transformConverter(value);
221-
let array = new Array<styleProperty.KeyValuePair<styleProperty.Property, any>>();
221+
let array = new Array<KeyValuePair<Property, any>>();
222222
let values = undefined;
223223
for (let transform in newTransform) {
224224
switch (transform) {

Diff for: nativescript-angular/common/detached-loader.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {
22
ComponentRef, ComponentFactory, ViewContainerRef,
33
Component, Type, ComponentFactoryResolver, ChangeDetectorRef
44
} from "@angular/core";
5-
import * as trace from "trace";
5+
import { write } from "trace";
66

77
export const CATEGORY = "detached-loader";
88
function log(message: string) {
9-
trace.write(message, CATEGORY);
9+
write(message, CATEGORY);
1010
}
1111

1212

Diff for: nativescript-angular/directives/tab-view.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ElementRef, Directive, Input, TemplateRef, ViewContainerRef, OnInit, AfterViewInit } from "@angular/core";
22
import { TabView, TabViewItem } from "ui/tab-view";
3-
import * as utils from "../common/utils";
3+
import { convertToInt } from "../common/utils";
44
import { rendererLog } from "../trace";
55
import { isBlank } from "../lang-facade";
66

@@ -18,7 +18,7 @@ export class TabViewDirective implements AfterViewInit {
1818
}
1919

2020
set selectedIndex(value) {
21-
this._selectedIndex = utils.convertToInt(value);
21+
this._selectedIndex = convertToInt(value);
2222
if (this.viewInitialized) {
2323
this.tabView.selectedIndex = this._selectedIndex;
2424
}

Diff for: nativescript-angular/global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
1+
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es6.d.ts" />

Diff for: nativescript-angular/http.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { NSFileSystem } from "./file-system/ns-file-system";
77
import { NgModule } from "@angular/core";
88
import { HttpModule, XSRFStrategy } from "@angular/http";
99

10+
export { NSHttp } from "./http/ns-http";
11+
1012
export function nsHttpFactory(backend, options, nsFileSystem) {
1113
return new NSHttp(backend, options, nsFileSystem);
1214
};

Diff for: nativescript-angular/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import "application";
2+
3+
export * from "./platform-common";
14
export * from "./platform";
25
export * from "./platform-static";
36
export * from "./router";
47
export * from "./forms";
58
export * from "./http";
69
export * from "./directives";
710
export * from "./common/detached-loader";
11+
export * from "./trace";
12+
export * from "./platform-providers";
13+
export * from "./file-system/ns-file-system";
14+
export * from "./modal-dialog";
15+
export * from "./renderer";
16+
export * from "./view-util";
17+
export * from "./animation-driver";
18+
export * from "./resource-loader";
19+
export * from "./element-registry";

Diff for: nativescript-angular/initial-imports.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// always import application at first place in order to fix some cycle dependency hell in ios.
2+
import "application";

Diff for: nativescript-angular/nativescript.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "globals";
2-
import "./zone.js/dist/zone-nativescript";
2+
import "./zone-js/dist/zone-nativescript";
33

44
import "reflect-metadata";
55
import "./polyfills/array";

Diff for: nativescript-angular/package.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"private": true,
33
"name": "nativescript-angular",
44
"version": "1.3.0",
5+
"main": "bundle.all.js",
6+
"module": "index.js",
7+
"typings": "index.d.ts",
58
"description": "An Angular 2 renderer that lets you build mobile apps with NativeScript.",
69
"homepage": "http://www.telerik.com",
710
"bugs": "http://www.telerik.com",
@@ -18,10 +21,10 @@
1821
"postinstall": "node postinstall.js",
1922
"ngc": "ngc -p tsconfig.json",
2023
"tsc": "tsc -p tsconfig.json",
21-
"prepublish": "npm run tsc && npm run ngc"
24+
"prepublish": "npm run tsc && rollup -c && npm run ngc"
2225
},
2326
"dependencies": {
24-
"nativescript-intl": "~0.0.4",
27+
"nativescript-intl": "~0.0.5",
2528
"@angular/core": "~2.2.1",
2629
"@angular/common": "~2.2.1",
2730
"@angular/compiler": "~2.2.1",
@@ -35,15 +38,18 @@
3538
"parse5": "1.3.2",
3639
"punycode": "1.3.2",
3740
"querystring": "0.2.0",
41+
"rxjs": "5.0.0-beta.12",
3842
"url": "0.10.3"
3943
},
4044
"devDependencies": {
41-
"@angular/compiler-cli": "~2.2.1",
42-
"codelyzer": "^2.0.0-beta.1",
43-
"tns-core-modules": ">=2.4.0 || >=2.4.0-2016",
44-
"tslint": "~4.0.1",
45+
"tns-core-modules": ">=2.5.0 || >=2.5.0-2016",
46+
"zone.js": "^0.6.21",
4547
"typescript": "^2.0.2",
46-
"zone.js": "^0.6.21"
48+
"tslint": "~4.0.1",
49+
"codelyzer": "^2.0.0-beta.1",
50+
"@angular/compiler-cli": "~2.2.1",
51+
"rollup": "^0.36.3",
52+
"rollup-plugin-multi-entry": "^2.0.1"
4753
},
4854
"nativescript": {}
4955
}

Diff for: nativescript-angular/platform-common.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Initial imports and polyfills
22
import "globals";
3-
import "./zone.js/dist/zone-nativescript";
3+
import "./zone-js/dist/zone-nativescript";
44
import "reflect-metadata";
55
import "./polyfills/array";
66
import "./polyfills/console";
@@ -28,7 +28,7 @@ if (global.___TS_UNUSED) {
2828
import { rendererLog, rendererError } from "./trace";
2929
import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from "./platform-providers";
3030

31-
import * as application from "application";
31+
import { start, setCssFileName } from "application";
3232
import { topmost, NavigationEntry } from "ui/frame";
3333
import { Page } from "ui/page";
3434
import { TextView } from "ui/text-view";
@@ -91,12 +91,11 @@ export class NativeScriptPlatformRef extends PlatformRef {
9191
const mainPageEntry = this.createNavigationEntry(this._bootstrapper);
9292

9393
if (this.appOptions && typeof this.appOptions.cssFile === "string") {
94-
// TODO: All exported filed in ES6 modules should be read-only
94+
// TODO: All exported fields in ES6 modules should be read-only
9595
// Change the case when tns-core-modules become ES6 compatible and there is a legal way to set cssFile
96-
(<any>application).cssFile = this.appOptions.cssFile;
96+
setCssFileName(this.appOptions.cssFile);
9797
}
98-
99-
application.start(mainPageEntry);
98+
start(mainPageEntry);
10099
}
101100

102101
livesyncModule(): void {

Diff for: nativescript-angular/renderer.ts

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
import {
22
Inject, Injectable, Optional, NgZone,
3-
Renderer, RootRenderer, RenderComponentType,
3+
Renderer, RootRenderer, RenderComponentType, AnimationPlayer
44
} from "@angular/core";
5-
import { AnimationPlayer } from "@angular/core";
65
import { AnimationStyles, AnimationKeyframe } from "./private_import_core";
76
import { APP_ROOT_VIEW, DEVICE } from "./platform-providers";
87
import { isBlank } from "./lang-facade";
98
import { View } from "ui/core/view";
10-
import * as application from "application";
9+
import { addCss } from "application";
1110
import { topmost } from "ui/frame";
1211
import { Page } from "ui/page";
13-
import { ViewUtil, NgView } from "./view-util";
12+
import { ViewUtil } from "./view-util";
13+
import { NgView } from "./element-registry";
1414
import { rendererLog as traceLog } from "./trace";
1515
import { escapeRegexSymbols } from "utils/utils";
1616
import { Device } from "platform";
1717

18-
import * as nsAnimationDriver from "./animation-driver";
19-
let nsAnimationDriverModule: typeof nsAnimationDriver;
20-
21-
function ensureAnimationDriverModule() {
22-
if (!nsAnimationDriverModule) {
23-
nsAnimationDriverModule = require("./animation-driver");
24-
}
25-
}
18+
import { NativeScriptAnimationDriver } from "./animation-driver";
2619

2720
// CONTENT_ATTR not exported from dom_renderer - we need it for styles application.
2821
export const COMPONENT_VARIABLE = "%COMP%";
@@ -32,12 +25,11 @@ export const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
3225
@Injectable()
3326
export class NativeScriptRootRenderer implements RootRenderer {
3427
private _viewUtil: ViewUtil;
35-
private _animationDriver: nsAnimationDriver.NativeScriptAnimationDriver;
28+
private _animationDriver: NativeScriptAnimationDriver;
3629

37-
protected get animationDriver(): nsAnimationDriver.NativeScriptAnimationDriver {
30+
protected get animationDriver(): NativeScriptAnimationDriver {
3831
if (!this._animationDriver) {
39-
ensureAnimationDriverModule();
40-
this._animationDriver = new nsAnimationDriverModule.NativeScriptAnimationDriver();
32+
this._animationDriver = new NativeScriptAnimationDriver();
4133
}
4234
return this._animationDriver;
4335
}
@@ -89,18 +81,18 @@ export class NativeScriptRenderer extends Renderer {
8981

9082
constructor(
9183
private rootRenderer: NativeScriptRootRenderer,
92-
componentProto: RenderComponentType,
93-
private animationDriver: nsAnimationDriver.NativeScriptAnimationDriver,
84+
private componentProto: RenderComponentType,
85+
private animationDriver: NativeScriptAnimationDriver,
9486
private zone: NgZone) {
9587

9688
super();
97-
let stylesLength = componentProto.styles.length;
98-
this.componentProtoId = componentProto.id;
89+
let stylesLength = this.componentProto.styles.length;
90+
this.componentProtoId = this.componentProto.id;
9991
for (let i = 0; i < stylesLength; i++) {
10092
this.hasComponentStyles = true;
101-
let cssString = componentProto.styles[i] + "";
93+
let cssString = this.componentProto.styles[i] + "";
10294
const realCSS = this.replaceNgAttribute(cssString, this.componentProtoId);
103-
application.addCss(realCSS);
95+
addCss(realCSS);
10496
}
10597
traceLog("NativeScriptRenderer created");
10698
}

Diff for: nativescript-angular/rollup-entry.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export * from "./index";
2+
export * from "./lang-facade";
3+
export * from "./collection-facade";
4+
export * from "./router-url-tree";
5+
export * from "./router/ns-platform-location";
6+
export * from "./router/ns-router-link-active";
7+
export * from "./router/ns-router-link";
8+
export * from "./router/page-router-outlet";
9+
export * from "./router/router-extensions";
10+
export * from "./parse5_adapter";
11+
export * from "./private_import_core";
12+
export * from "./private_import_platform-browser";

Diff for: nativescript-angular/rollup.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class DebugInfoRoll {
2+
constructor(options){
3+
this.options = options;
4+
}
5+
resolveId(id, from){
6+
console.log(id, from);
7+
}
8+
}
9+
10+
const debugInfoRoll = (config) => new DebugInfoRoll(config);
11+
12+
export default {
13+
entry: "rollup-entry.js",
14+
dest: "bundle.all.js",
15+
format: "cjs",
16+
sourceMap: "inline",
17+
external: ["@angular"],
18+
treeshake: false,
19+
plugins: [
20+
//debugInfoRoll(),
21+
]
22+
}

Diff for: nativescript-angular/router.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { LocationStrategy, PlatformLocation } from "@angular/common";
44
import { NSRouterLink } from "./router/ns-router-link";
55
import { NSRouterLinkActive } from "./router/ns-router-link-active";
66
import { PageRouterOutlet } from "./router/page-router-outlet";
7-
import { NSLocationStrategy } from "./router/ns-location-strategy";
7+
import { NSLocationStrategy, LocationState } from "./router/ns-location-strategy";
88
import { NativescriptPlatformLocation } from "./router/ns-platform-location";
99
import { RouterExtensions } from "./router/router-extensions";
10-
export { routerTraceCategory } from "./trace";
11-
export { PageRoute } from "./router/page-router-outlet";
12-
export { RouterExtensions } from "./router/router-extensions";
1310
import { NativeScriptModule } from "./nativescript.module";
1411
import { NsModuleFactoryLoader } from "./router/ns-module-factory-loader";
1512

13+
export { PageRoute } from "./router/page-router-outlet";
14+
export { RouterExtensions } from "./router/router-extensions";
15+
export { NSLocationStrategy } from "./router/ns-location-strategy";
16+
export type LocationState = LocationState;
17+
1618
@NgModule({
1719
declarations: [
1820
NSRouterLink,

Diff for: nativescript-angular/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "commonjs",
3+
"target": "es6",
4+
"module": "es6",
5+
"moduleResolution": "node",
56
"sourceMap": true,
67
"emitDecoratorMetadata": true,
78
"experimentalDecorators": true,

Diff for: nativescript-angular/value-accessors/selectedIndex-value-accessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Directive, ElementRef, forwardRef, AfterViewInit, HostListener } from "
22
import { NG_VALUE_ACCESSOR } from "@angular/forms";
33
import { BaseValueAccessor } from "./base-value-accessor";
44
import { View } from "ui/core/view";
5-
import * as utils from "../common/utils";
5+
import { convertToInt } from "../common/utils";
66

77
const SELECTED_INDEX_VALUE_ACCESSOR = {provide: NG_VALUE_ACCESSOR,
88
useExisting: forwardRef(() => SelectedIndexValueAccessor), multi: true};
@@ -38,7 +38,7 @@ export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView
3838
private viewInitialized: boolean;
3939

4040
writeValue(value: any): void {
41-
this._normalizedValue = utils.convertToInt(value);
41+
this._normalizedValue = convertToInt(value);
4242
if (this.viewInitialized) {
4343
this.view.selectedIndex = this._normalizedValue;
4444
}

Diff for: nativescript-angular/view-util.ts

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const IOS_PREFX: string = ":ios:";
2222
const ANDROID_PREFX: string = ":android:";
2323
const whiteSpaceSplitter = /\s+/;
2424

25-
export type ViewExtensions = ViewExtensions;
26-
export type NgView = NgView;
2725
export type NgLayoutBase = LayoutBase & ViewExtensions;
2826
export type NgContentView = ContentView & ViewExtensions;
2927
export type BeforeAttachAction = (view: View) => void;

0 commit comments

Comments
 (0)