Skip to content

[DON'T MERGE] Make nativescript-angular modules es6. #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2016
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
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ tags

/hooks

nativescript-angular/**/*.d.ts
!nativescript-angular/global.d.ts
nativescript-angular/**/*.js
!nativescript-angular/postinstall.js
!nativescript-angular/hooks/**/*.js
!nativescript-angular/gulpfile.js
/nativescript-angular/**/*.d.ts
/nativescript-angular/**/*.js

!/nativescript-angular/global.d.ts
!/nativescript-angular/postinstall.js
!/nativescript-angular/hooks/**/*.js
!/nativescript-angular/gulpfile.js
!/nativescript-angular/rollup.config.js
!/nativescript-angular/rollup-entry.js
!/nativescript-angular/zone-js/**/*.js

.tscache
.nvm
Expand Down
6 changes: 3 additions & 3 deletions nativescript-angular/animation-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { View } from "ui/core/view";
import { AnimationCurve } from "ui/enums";
import { ValueSource } from "ui/core/dependency-observable";
import { isString } from "utils/types";
import * as styleProperty from "ui/styling/style-property";
import { getPropertyByCssName, KeyValuePair, Property } from "ui/styling/style-property";

export class NativeScriptAnimationPlayer implements AnimationPlayer {

Expand Down Expand Up @@ -60,7 +60,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
for (let style of keyframe.styles.styles) {
for (let substyle in style) {
let value = style[substyle];
let property = styleProperty.getPropertyByCssName(substyle);
let property = getPropertyByCssName(substyle);
if (property) {
if (typeof value === "string" && property.valueConverter) {
value = property.valueConverter(<string>value);
Expand Down Expand Up @@ -218,7 +218,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {

static parseTransform(value: string, animationInfo: KeyframeInfo) {
let newTransform = NativeScriptAnimationPlayer.transformConverter(value);
let array = new Array<styleProperty.KeyValuePair<styleProperty.Property, any>>();
let array = new Array<KeyValuePair<Property, any>>();
let values = undefined;
for (let transform in newTransform) {
switch (transform) {
Expand Down
4 changes: 2 additions & 2 deletions nativescript-angular/common/detached-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
ComponentRef, ComponentFactory, ViewContainerRef,
Component, Type, ComponentFactoryResolver, ChangeDetectorRef
} from "@angular/core";
import * as trace from "trace";
import { write } from "trace";

export const CATEGORY = "detached-loader";
function log(message: string) {
trace.write(message, CATEGORY);
write(message, CATEGORY);
}


Expand Down
4 changes: 2 additions & 2 deletions nativescript-angular/directives/tab-view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ElementRef, Directive, Input, TemplateRef, ViewContainerRef, OnInit, AfterViewInit } from "@angular/core";
import { TabView, TabViewItem } from "ui/tab-view";
import * as utils from "../common/utils";
import { convertToInt } from "../common/utils";
import { rendererLog } from "../trace";
import { isBlank } from "../lang-facade";

Expand All @@ -18,7 +18,7 @@ export class TabViewDirective implements AfterViewInit {
}

set selectedIndex(value) {
this._selectedIndex = utils.convertToInt(value);
this._selectedIndex = convertToInt(value);
if (this.viewInitialized) {
this.tabView.selectedIndex = this._selectedIndex;
}
Expand Down
2 changes: 1 addition & 1 deletion nativescript-angular/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es6.d.ts" />
2 changes: 2 additions & 0 deletions nativescript-angular/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { NSFileSystem } from "./file-system/ns-file-system";
import { NgModule } from "@angular/core";
import { HttpModule, XSRFStrategy } from "@angular/http";

export { NSHttp } from "./http/ns-http";

export function nsHttpFactory(backend, options, nsFileSystem) {
return new NSHttp(backend, options, nsFileSystem);
};
Expand Down
12 changes: 12 additions & 0 deletions nativescript-angular/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import "application";

export * from "./platform-common";
export * from "./platform";
export * from "./platform-static";
export * from "./router";
export * from "./forms";
export * from "./http";
export * from "./directives";
export * from "./common/detached-loader";
export * from "./trace";
export * from "./platform-providers";
export * from "./file-system/ns-file-system";
export * from "./modal-dialog";
export * from "./renderer";
export * from "./view-util";
export * from "./animation-driver";
export * from "./resource-loader";
export * from "./element-registry";
2 changes: 2 additions & 0 deletions nativescript-angular/initial-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// always import application at first place in order to fix some cycle dependency hell in ios.
import "application";
2 changes: 1 addition & 1 deletion nativescript-angular/nativescript.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "globals";
import "./zone.js/dist/zone-nativescript";
import "./zone-js/dist/zone-nativescript";

import "reflect-metadata";
import "./polyfills/array";
Expand Down
20 changes: 13 additions & 7 deletions nativescript-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"private": true,
"name": "nativescript-angular",
"version": "1.3.0",
"main": "bundle.all.js",
"module": "index.js",
"typings": "index.d.ts",
"description": "An Angular 2 renderer that lets you build mobile apps with NativeScript.",
"homepage": "http://www.telerik.com",
"bugs": "http://www.telerik.com",
Expand All @@ -18,10 +21,10 @@
"postinstall": "node postinstall.js",
"ngc": "ngc -p tsconfig.json",
"tsc": "tsc -p tsconfig.json",
"prepublish": "npm run tsc && npm run ngc"
"prepublish": "npm run tsc && rollup -c && npm run ngc"
},
"dependencies": {
"nativescript-intl": "~0.0.4",
"nativescript-intl": "~0.0.5",
"@angular/core": "~2.2.1",
"@angular/common": "~2.2.1",
"@angular/compiler": "~2.2.1",
Expand All @@ -35,15 +38,18 @@
"parse5": "1.3.2",
"punycode": "1.3.2",
"querystring": "0.2.0",
"rxjs": "5.0.0-beta.12",
"url": "0.10.3"
},
"devDependencies": {
"@angular/compiler-cli": "~2.2.1",
"codelyzer": "^2.0.0-beta.1",
"tns-core-modules": ">=2.4.0 || >=2.4.0-2016",
"tslint": "~4.0.1",
"tns-core-modules": ">=2.5.0 || >=2.5.0-2016",
"zone.js": "^0.6.21",
"typescript": "^2.0.2",
"zone.js": "^0.6.21"
"tslint": "~4.0.1",
"codelyzer": "^2.0.0-beta.1",
"@angular/compiler-cli": "~2.2.1",
"rollup": "^0.36.3",
"rollup-plugin-multi-entry": "^2.0.1"
},
"nativescript": {}
}
11 changes: 5 additions & 6 deletions nativescript-angular/platform-common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Initial imports and polyfills
import "globals";
import "./zone.js/dist/zone-nativescript";
import "./zone-js/dist/zone-nativescript";
import "reflect-metadata";
import "./polyfills/array";
import "./polyfills/console";
Expand Down Expand Up @@ -28,7 +28,7 @@ if (global.___TS_UNUSED) {
import { rendererLog, rendererError } from "./trace";
import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from "./platform-providers";

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

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

application.start(mainPageEntry);
start(mainPageEntry);
}

livesyncModule(): void {
Expand Down
36 changes: 14 additions & 22 deletions nativescript-angular/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import {
Inject, Injectable, Optional, NgZone,
Renderer, RootRenderer, RenderComponentType,
Renderer, RootRenderer, RenderComponentType, AnimationPlayer
} from "@angular/core";
import { AnimationPlayer } from "@angular/core";
import { AnimationStyles, AnimationKeyframe } from "./private_import_core";
import { APP_ROOT_VIEW, DEVICE } from "./platform-providers";
import { isBlank } from "./lang-facade";
import { View } from "ui/core/view";
import * as application from "application";
import { addCss } from "application";
import { topmost } from "ui/frame";
import { Page } from "ui/page";
import { ViewUtil, NgView } from "./view-util";
import { ViewUtil } from "./view-util";
import { NgView } from "./element-registry";
import { rendererLog as traceLog } from "./trace";
import { escapeRegexSymbols } from "utils/utils";
import { Device } from "platform";

import * as nsAnimationDriver from "./animation-driver";
let nsAnimationDriverModule: typeof nsAnimationDriver;

function ensureAnimationDriverModule() {
if (!nsAnimationDriverModule) {
nsAnimationDriverModule = require("./animation-driver");
}
}
import { NativeScriptAnimationDriver } from "./animation-driver";

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

protected get animationDriver(): nsAnimationDriver.NativeScriptAnimationDriver {
protected get animationDriver(): NativeScriptAnimationDriver {
if (!this._animationDriver) {
ensureAnimationDriverModule();
this._animationDriver = new nsAnimationDriverModule.NativeScriptAnimationDriver();
this._animationDriver = new NativeScriptAnimationDriver();
}
return this._animationDriver;
}
Expand Down Expand Up @@ -89,18 +81,18 @@ export class NativeScriptRenderer extends Renderer {

constructor(
private rootRenderer: NativeScriptRootRenderer,
componentProto: RenderComponentType,
private animationDriver: nsAnimationDriver.NativeScriptAnimationDriver,
private componentProto: RenderComponentType,
private animationDriver: NativeScriptAnimationDriver,
private zone: NgZone) {

super();
let stylesLength = componentProto.styles.length;
this.componentProtoId = componentProto.id;
let stylesLength = this.componentProto.styles.length;
this.componentProtoId = this.componentProto.id;
for (let i = 0; i < stylesLength; i++) {
this.hasComponentStyles = true;
let cssString = componentProto.styles[i] + "";
let cssString = this.componentProto.styles[i] + "";
const realCSS = this.replaceNgAttribute(cssString, this.componentProtoId);
application.addCss(realCSS);
addCss(realCSS);
}
traceLog("NativeScriptRenderer created");
}
Expand Down
12 changes: 12 additions & 0 deletions nativescript-angular/rollup-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export * from "./index";
export * from "./lang-facade";
export * from "./collection-facade";
export * from "./router-url-tree";
export * from "./router/ns-platform-location";
export * from "./router/ns-router-link-active";
export * from "./router/ns-router-link";
export * from "./router/page-router-outlet";
export * from "./router/router-extensions";
export * from "./parse5_adapter";
export * from "./private_import_core";
export * from "./private_import_platform-browser";
22 changes: 22 additions & 0 deletions nativescript-angular/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class DebugInfoRoll {
constructor(options){
this.options = options;
}
resolveId(id, from){
console.log(id, from);
}
}

const debugInfoRoll = (config) => new DebugInfoRoll(config);

export default {
entry: "rollup-entry.js",
dest: "bundle.all.js",
format: "cjs",
sourceMap: "inline",
external: ["@angular"],
treeshake: false,
plugins: [
//debugInfoRoll(),
]
}
10 changes: 6 additions & 4 deletions nativescript-angular/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { LocationStrategy, PlatformLocation } from "@angular/common";
import { NSRouterLink } from "./router/ns-router-link";
import { NSRouterLinkActive } from "./router/ns-router-link-active";
import { PageRouterOutlet } from "./router/page-router-outlet";
import { NSLocationStrategy } from "./router/ns-location-strategy";
import { NSLocationStrategy, LocationState } from "./router/ns-location-strategy";
import { NativescriptPlatformLocation } from "./router/ns-platform-location";
import { RouterExtensions } from "./router/router-extensions";
export { routerTraceCategory } from "./trace";
export { PageRoute } from "./router/page-router-outlet";
export { RouterExtensions } from "./router/router-extensions";
import { NativeScriptModule } from "./nativescript.module";
import { NsModuleFactoryLoader } from "./router/ns-module-factory-loader";

export { PageRoute } from "./router/page-router-outlet";
export { RouterExtensions } from "./router/router-extensions";
export { NSLocationStrategy } from "./router/ns-location-strategy";
export type LocationState = LocationState;

@NgModule({
declarations: [
NSRouterLink,
Expand Down
5 changes: 3 additions & 2 deletions nativescript-angular/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Directive, ElementRef, forwardRef, AfterViewInit, HostListener } from "
import { NG_VALUE_ACCESSOR } from "@angular/forms";
import { BaseValueAccessor } from "./base-value-accessor";
import { View } from "ui/core/view";
import * as utils from "../common/utils";
import { convertToInt } from "../common/utils";

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

writeValue(value: any): void {
this._normalizedValue = utils.convertToInt(value);
this._normalizedValue = convertToInt(value);
if (this.viewInitialized) {
this.view.selectedIndex = this._normalizedValue;
}
Expand Down
2 changes: 0 additions & 2 deletions nativescript-angular/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const IOS_PREFX: string = ":ios:";
const ANDROID_PREFX: string = ":android:";
const whiteSpaceSplitter = /\s+/;

export type ViewExtensions = ViewExtensions;
export type NgView = NgView;
export type NgLayoutBase = LayoutBase & ViewExtensions;
export type NgContentView = ContentView & ViewExtensions;
export type BeforeAttachAction = (view: View) => void;
Expand Down
Loading