Skip to content

Commit 7f8ce06

Browse files
author
vakrilov
committed
ES2015 compatible imports
1 parent ca5b5d8 commit 7f8ce06

17 files changed

+129
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ bin/dist
22
node_modules
33
tags
44
**/*.js.map
5+
**/*.metadata.json
56

67
/hooks
78

nativescript-angular/animation-driver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { AnimationPlayer, AnimationStyles, AnimationKeyframe } from "./private_import_core";
1+
import { AnimationPlayer, AnimationStyles, AnimationKeyframe } from "./private_import_core";
22
import { NativeScriptAnimationPlayer } from './animation-player';
3-
import {View} from "ui/core/view";
4-
import styleProperty = require('ui/styling/style-property');
3+
import { View } from "ui/core/view";
4+
import { getPropertyByCssName } from 'ui/styling/style-property';
55

66
export abstract class AnimationDriver {
77
abstract animate(
@@ -12,7 +12,7 @@ export abstract class AnimationDriver {
1212
export class NativeScriptAnimationDriver implements AnimationDriver {
1313

1414
computeStyle(element: any, prop: string): string {
15-
return (<View>element).style._getValue(styleProperty.getPropertyByCssName(prop));
15+
return (<View>element).style._getValue(getPropertyByCssName(prop));
1616
}
1717

1818
animate(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer {

nativescript-angular/animation-player.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { AnimationPlayer, AnimationKeyframe } from "./private_import_core";
1+
import { AnimationPlayer, AnimationKeyframe } from "./private_import_core";
22
import { KeyframeAnimation, KeyframeAnimationInfo, KeyframeInfo, KeyframeDeclaration } from 'ui/animation/keyframe-animation';
33
import { View } from "ui/core/view";
4-
import enums = require("ui/enums");
5-
import styleProperty = require('ui/styling/style-property');
6-
import observable = require('ui/core/dependency-observable');
7-
import types = require("utils/types");
4+
import { AnimationCurve } from "ui/enums";
5+
import { ValueSource } from 'ui/core/dependency-observable';
6+
import { isString } from "utils/types";
7+
import * as styleProperty from 'ui/styling/style-property';
88

99
export class NativeScriptAnimationPlayer implements AnimationPlayer {
1010

@@ -35,7 +35,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
3535
keyframeAnimationInfo.duration = duration;
3636
keyframeAnimationInfo.delay = delay;
3737
keyframeAnimationInfo.iterations = 1;
38-
keyframeAnimationInfo.curve = easing ? NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) : enums.AnimationCurve.ease;
38+
keyframeAnimationInfo.curve = easing ? NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) : AnimationCurve.ease;
3939
keyframeAnimationInfo.keyframes = new Array<KeyframeInfo>();
4040
keyframeAnimationInfo.isForwards = true;
4141

@@ -61,7 +61,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
6161
keyframeAnimationInfo.keyframes.push(keyframeInfo);
6262
}
6363

64-
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(keyframeAnimationInfo, observable.ValueSource.VisualState);
64+
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(keyframeAnimationInfo, ValueSource.VisualState);
6565
}
6666

6767
init(): void {
@@ -136,24 +136,24 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
136136
static animationTimingFunctionConverter(value): any {
137137
switch (value) {
138138
case "ease":
139-
return enums.AnimationCurve.ease;
139+
return AnimationCurve.ease;
140140
case "linear":
141-
return enums.AnimationCurve.linear;
141+
return AnimationCurve.linear;
142142
case "ease-in":
143-
return enums.AnimationCurve.easeIn;
143+
return AnimationCurve.easeIn;
144144
case "ease-out":
145-
return enums.AnimationCurve.easeOut;
145+
return AnimationCurve.easeOut;
146146
case "ease-in-out":
147-
return enums.AnimationCurve.easeInOut;
147+
return AnimationCurve.easeInOut;
148148
case "spring":
149-
return enums.AnimationCurve.spring;
149+
return AnimationCurve.spring;
150150
default:
151151
if (value.indexOf("cubic-bezier(") === 0) {
152152
let bezierArr = value.substring(13).split(/[,]+/);
153153
if (bezierArr.length !== 4) {
154154
throw new Error("Invalid value for animation: " + value);
155155
}
156-
return enums.AnimationCurve.cubicBezier(
156+
return AnimationCurve.cubicBezier(
157157
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[0]),
158158
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[1]),
159159
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[2]),
@@ -178,7 +178,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
178178
operations[value] = value;
179179
return operations;
180180
}
181-
else if (types.isString(value)) {
181+
else if (isString(value)) {
182182
let operations = {};
183183
let operator = "";
184184
let pos = 0;

nativescript-angular/common/detached-loader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {
22
ComponentRef, ComponentFactory, ViewContainerRef,
3-
Component, Type, ViewChild, Compiler,
4-
ComponentFactoryResolver, ChangeDetectorRef, Host
3+
Component, Type, ComponentFactoryResolver, ChangeDetectorRef
54
} from '@angular/core';
6-
import trace = require("trace");
5+
import * as trace from "trace";
76

87
type AnyComponentRef = ComponentRef<any>;
98
interface PendingLoadEntry {

nativescript-angular/directives/action-bar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Directive, Component, ContentChildren, ElementRef, Optional} from '@angular/core';
2-
import {ActionItem, ActionBar, NavigationButton} from "ui/action-bar";
3-
import {isBlank} from "../lang-facade";
1+
import { Directive, Component, ElementRef, Optional } from '@angular/core';
2+
import { ActionItem, ActionBar, NavigationButton } from "ui/action-bar";
3+
import { isBlank } from "../lang-facade";
44
import {Page} from "ui/page";
5-
import {View} from 'ui/core/view';
6-
import {registerElement, ViewClassMeta, NgView } from '../element-registry';
5+
import { View } from 'ui/core/view';
6+
import { registerElement, ViewClassMeta, NgView } from '../element-registry';
77

88
var actionBarMeta: ViewClassMeta = {
99
skipAddToDom: true,
@@ -95,7 +95,7 @@ export class ActionItemDirective {
9595
this.ownerScope.onActionInit(this);
9696
}
9797
}
98-
98+
9999
ngOnDestroy() {
100100
if (this.ownerScope) {
101101
this.ownerScope.onActionDestroy(this);

nativescript-angular/http.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import {
2-
Http, XHRBackend, RequestOptions
2+
Http, XHRBackend, RequestOptions
33
} from '@angular/http';
44
import { NSXSRFStrategy, NSHttp } from "./http/ns-http";
55
import { NSFileSystem } from "./file-system/ns-file-system";
66

77
import { NgModule } from "@angular/core";
88
import { HttpModule, XSRFStrategy } from "@angular/http";
99

10+
export function nsHttpFactory(backend, options, nsFileSystem) {
11+
return new NSHttp(backend, options, nsFileSystem);
12+
};
13+
14+
export function nsXSRFStrategyFactory() {
15+
return new NSXSRFStrategy();
16+
};
17+
1018
@NgModule({
1119
providers: [
12-
{ provide: XSRFStrategy, useValue: new NSXSRFStrategy() },
13-
NSFileSystem,
14-
{
15-
provide: Http, useFactory: (backend, options, nsFileSystem) => {
16-
return new NSHttp(backend, options, nsFileSystem);
17-
}, deps: [XHRBackend, RequestOptions, NSFileSystem]
18-
}
20+
{ provide: XSRFStrategy, useFactory: nsXSRFStrategyFactory },
21+
NSFileSystem,
22+
{ provide: Http, useFactory: nsHttpFactory, deps: [XHRBackend, RequestOptions, NSFileSystem] }
1923
],
2024
imports: [
2125
HttpModule,

nativescript-angular/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from "./platform";
2+
export * from "./router";
3+
export * from "./forms";
4+
export * from "./http";
5+
export * from "./directives";
6+
export * from "./common/detached-loader";

nativescript-angular/nativescript.module.ts

Lines changed: 5 additions & 10 deletions
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';
@@ -15,7 +15,7 @@ import {
1515
Renderer,
1616
RootRenderer,
1717
Sanitizer,
18-
NgModule
18+
NgModule, NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA
1919
} from '@angular/core';
2020
import {
2121
defaultPageProvider, defaultFrameProvider, defaultDeviceProvider
@@ -26,13 +26,7 @@ import { NS_DIRECTIVES } from './directives';
2626
import * as nativescriptIntl from "nativescript-intl";
2727
global.Intl = nativescriptIntl;
2828

29-
export interface AppOptions {
30-
bootInExistingPage: boolean,
31-
cssFile?: string;
32-
startPageActionBarHidden?: boolean;
33-
}
34-
35-
export const errorHandlerFactory = () => {
29+
export function errorHandlerFactory() {
3630
return new ErrorHandler(true);
3731
};
3832

@@ -67,7 +61,8 @@ export const errorHandlerFactory = () => {
6761
DetachedLoader,
6862
ModalDialogHost,
6963
...NS_DIRECTIVES,
70-
]
64+
],
65+
schemas: [NO_ERRORS_SCHEMA]
7166
})
7267
export class NativeScriptModule {
7368
}

nativescript-angular/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
},
1616
"scripts": {
1717
"postinstall": "node postinstall.js",
18-
"prepublish": "tsc"
18+
"ngc": "ngc -p tsconfig.json",
19+
"tsc": "tsc -p tsconfig.json",
20+
"prepublish": "npm run tsc && npm run ngc"
1921
},
2022
"dependencies": {
2123
"nativescript-intl": "~0.0.4",
@@ -37,7 +39,8 @@
3739
"devDependencies": {
3840
"tns-core-modules": ">=2.2.0 || >=2.2.0-2016",
3941
"zone.js": "^0.6.21",
40-
"typescript": "^1.8.10"
42+
"typescript": "^2.0.2",
43+
"@angular/compiler-cli": "2.1.0"
4144
},
4245
"nativescript": {}
4346
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import {topmost, Frame} from 'ui/frame';
2-
import {Page} from 'ui/page';
3-
import {Provider, OpaqueToken} from '@angular/core';
4-
import {device, Device} from "platform";
5-
import {NativeScriptAnimationDriver} from './animation-driver';
1+
import { topmost, Frame } from 'ui/frame';
2+
import { Page } from 'ui/page';
3+
import { OpaqueToken } from '@angular/core';
4+
import { device, Device } from "platform";
65

76
export const APP_ROOT_VIEW = new OpaqueToken('App Root View');
87
export const DEVICE = new OpaqueToken('platfrom device');
98

10-
export const defaultPageProvider = {provide: Page, useFactory: getDefaultPage};
9+
export const defaultPageProvider = { provide: Page, useFactory: getDefaultPage };
1110

1211
export function getDefaultPage(): Page {
1312
const frame = topmost();
@@ -18,6 +17,6 @@ export function getDefaultPage(): Page {
1817
}
1918
}
2019

21-
export const defaultFrameProvider = {provide: Frame, useFactory: topmost};
20+
export const defaultFrameProvider = { provide: Frame, useFactory: topmost };
2221

23-
export const defaultDeviceProvider = {provide: DEVICE, useValue: device};
22+
export const defaultDeviceProvider = { provide: DEVICE, useValue: device };

nativescript-angular/platform.ts

Lines changed: 31 additions & 10 deletions
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';
@@ -11,7 +11,7 @@ import {
1111
COMPILER_PROVIDERS,
1212
platformCoreDynamic
1313
} from '@angular/compiler';
14-
import { Provider } from '@angular/core';
14+
import { Provider, platformCore } from '@angular/core';
1515
import {
1616
Type,
1717
Injector,
@@ -60,6 +60,9 @@ export const NS_COMPILER_PROVIDERS = [
6060
}
6161
];
6262

63+
export const onBeforeLivesync = new EventEmitter<NgModuleRef<any>>();
64+
export const onAfterLivesync = new EventEmitter<NgModuleRef<any>>();
65+
6366
type BootstrapperAction = () => Promise<NgModuleRef<any>>;
6467

6568
let lastBootstrappedModule: WeakRef<NgModuleRef<any>>;
@@ -69,26 +72,34 @@ interface BootstrapParams {
6972
}
7073

7174
class NativeScriptPlatformRef extends PlatformRef {
75+
private _bootstrapper: BootstrapperAction;
76+
7277
constructor(private platform: PlatformRef, private appOptions?: AppOptions) {
7378
super();
7479
}
7580

7681
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
77-
throw new Error("Not implemented.");
82+
this._bootstrapper = () => this.platform.bootstrapModuleFactory(moduleFactory);
83+
84+
this.bootstrapApp();
85+
86+
return null; //Make the compiler happy
7887
}
7988

80-
private _bootstrapper: BootstrapperAction;
81-
8289
bootstrapModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions | CompilerOptions[] = []): Promise<NgModuleRef<M>> {
8390
this._bootstrapper = () => this.platform.bootstrapModule(moduleType, compilerOptions);
84-
// Patch livesync
91+
92+
this.bootstrapApp();
93+
94+
return null; //Make the compiler happy
95+
}
96+
97+
private bootstrapApp() {
8598
global.__onLiveSyncCore = () => this.livesyncModule();
8699

87100
const mainPageEntry = this.createNavigationEntry(this._bootstrapper);
88101

89102
application.start(mainPageEntry);
90-
91-
return null; //Make the compiler happy
92103
}
93104

94105
livesyncModule(): void {
@@ -186,6 +197,7 @@ class NativeScriptPlatformRef extends PlatformRef {
186197
}
187198
}
188199

200+
// Dynamic platfrom
189201
const _platformNativeScriptDynamic: PlatformFactory = createPlatformFactory(
190202
platformCoreDynamic, 'nativeScriptDynamic', NS_COMPILER_PROVIDERS);
191203

@@ -198,6 +210,15 @@ export function platformNativeScriptDynamic(options?: AppOptions, extraProviders
198210
}
199211
}
200212

201-
export const onBeforeLivesync = new EventEmitter<NgModuleRef<any>>();
202-
export const onAfterLivesync = new EventEmitter<NgModuleRef<any>>();
213+
// "Static" platform
214+
const _platformNativeScript: PlatformFactory = createPlatformFactory(
215+
platformCore, 'nativeScript');
203216

217+
export function platformNativeScript(options?: AppOptions, extraProviders?: any[]): PlatformRef {
218+
//Return raw platform to advanced users only if explicitly requested
219+
if (options && options.bootInExistingPage === true) {
220+
return _platformNativeScript(extraProviders);
221+
} else {
222+
return new NativeScriptPlatformRef(_platformNativeScript(extraProviders), options);
223+
}
224+
}

0 commit comments

Comments
 (0)