Skip to content

Integrate with angular rc.2 #294

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 2 commits into from
Jun 17, 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
53 changes: 33 additions & 20 deletions nativescript-angular/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import './polyfills/array';
import {rendererLog, rendererError} from "./trace";
import {SanitizationService} from '@angular/core/src/security';
import {isPresent, Type, print} from '@angular/core/src/facade/lang';
import {ReflectiveInjector, reflector, coreLoadAndBootstrap, createPlatform,
getPlatform, assertPlatform, ComponentRef, PlatformRef, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core';
import {ReflectiveInjector, coreLoadAndBootstrap, createPlatform,
getPlatform, assertPlatform, ComponentRef, PlatformRef, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core';
import {bind, provide, Provider} from '@angular/core/src/di';

import {RootRenderer, Renderer} from '@angular/core/src/render/api';
import {NativeScriptRootRenderer, NativeScriptRenderer} from './renderer';
import {NativeScriptDomAdapter, NativeScriptElementSchemaRegistry, NativeScriptSanitizationService} from './dom_adapter';
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS} from '@angular/compiler';
import {ElementSchemaRegistry, XHR, COMPILER_PROVIDERS, CompilerConfig} from '@angular/compiler';
import {FileSystemXHR} from './xhr';
import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';
import {ExceptionHandler} from '@angular/core/src/facade/exception_handler';
import {APPLICATION_COMMON_PROVIDERS} from '@angular/core/src/application_common_providers';
import {PLATFORM_COMMON_PROVIDERS} from '@angular/core/src/platform_common_providers';
import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from "@angular/common";
import {NS_DIRECTIVES} from './directives';
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';

import {Page} from 'ui/page';
import {TextView} from 'ui/text-view';
Expand All @@ -40,12 +39,27 @@ export interface AppOptions {
}

class ConsoleLogger {
log = print;
logError = print;
logGroup = print;
logGroupEnd() {}
log = print;
logError = print;
logGroup = print;
logGroupEnd() { }
}

// See: https://github.com/angular/angular/commit/1745366530266d298306b995ecd23dabd8569e28
export const NS_COMPILER_PROVIDERS: ProviderArray = [
COMPILER_PROVIDERS,
provide(CompilerConfig, {
useFactory: (platformDirectives: any[], platformPipes: any[]) => {
return new CompilerConfig({ platformDirectives, platformPipes });
},
deps: [PLATFORM_DIRECTIVES, PLATFORM_PIPES]
}),
provide(XHR, { useClass: FileSystemXHR }),
provide(PLATFORM_PIPES, { useValue: COMMON_PIPES, multi: true }),
provide(PLATFORM_DIRECTIVES, { useValue: COMMON_DIRECTIVES, multi: true }),
provide(PLATFORM_DIRECTIVES, { useValue: NS_DIRECTIVES, multi: true })
];

export function bootstrap(appComponentType: any,
customProviders: ProviderArray = null): Promise<ComponentRef<any>> {
NativeScriptDomAdapter.makeCurrent();
Expand All @@ -57,12 +71,11 @@ export function bootstrap(appComponentType: any,
let defaultAppProviders: ProviderArray = [
APPLICATION_COMMON_PROVIDERS,
FORM_PROVIDERS,
provide(PLATFORM_PIPES, { useValue: COMMON_PIPES, multi: true }),
provide(PLATFORM_DIRECTIVES, { useValue: COMMON_DIRECTIVES, multi: true }),
provide(PLATFORM_DIRECTIVES, { useValue: NS_DIRECTIVES, multi: true }),
provide(ExceptionHandler, { useFactory: () => {
return new ExceptionHandler(new ConsoleLogger(), true)
}, deps: [] }),
provide(ExceptionHandler, {
useFactory: () => {
return new ExceptionHandler(new ConsoleLogger(), true)
}, deps: []
}),

defaultPageProvider,
defaultDeviceProvider,
Expand All @@ -72,7 +85,7 @@ export function bootstrap(appComponentType: any,
provide(Renderer, { useClass: NativeScriptRenderer }),
provide(SanitizationService, { useClass: NativeScriptSanitizationService }),
provide(ElementSchemaRegistry, { useClass: NativeScriptElementSchemaRegistry }),
COMPILER_PROVIDERS,
NS_COMPILER_PROVIDERS,
provide(ElementSchemaRegistry, { useClass: NativeScriptElementSchemaRegistry }),
provide(XHR, { useClass: FileSystemXHR }),
]
Expand All @@ -82,14 +95,14 @@ export function bootstrap(appComponentType: any,
appProviders.push(customProviders);
}

var platform = getPlatform();
var platform = getPlatform();
if (!isPresent(platform)) {
platform = createPlatform(ReflectiveInjector.resolveAndCreate(platformProviders));
}
reflector.reflectionCapabilities = new ReflectionCapabilities();

// reflector.reflectionCapabilities = new ReflectionCapabilities();
var appInjector = ReflectiveInjector.resolveAndCreate(appProviders, platform.injector);
return coreLoadAndBootstrap(appInjector, appComponentType);
return coreLoadAndBootstrap(appComponentType, appInjector);
}

export function nativeScriptBootstrap(appComponentType: any, customProviders?: ProviderArray, appOptions?: AppOptions): Promise<ComponentRef<any>> {
Expand All @@ -105,7 +118,7 @@ export function nativeScriptBootstrap(appComponentType: any, customProviders?: P
page.actionBarHidden = appOptions.startPageActionBarHidden;
}

let onLoadedHandler = function(args) {
let onLoadedHandler = function (args) {
page.off('loaded', onLoadedHandler);
//profiling.stop('application-start');
rendererLog('Page loaded');
Expand Down
14 changes: 7 additions & 7 deletions nativescript-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
},
"dependencies": {
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/platform-server": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"@angular/platform-browser-dynamic": "2.0.0-rc.2",
"@angular/platform-server": "2.0.0-rc.2",
"@angular/router-deprecated": "2.0.0-rc.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
Expand Down
11 changes: 9 additions & 2 deletions nativescript-angular/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
RenderComponentType,
RenderDebugInfo
} from '@angular/core/src/render/api';
import { AnimationKeyframe } from '@angular/core/src/animation/animation_keyframe';
import { AnimationPlayer } from '@angular/core/src/animation/animation_player';
import { AnimationStyles } from '@angular/core/src/animation/animation_styles';
import {APP_ROOT_VIEW, DEVICE} from "./platform-providers";
import {isBlank} from '@angular/core/src/facade/lang';
import {CONTENT_ATTR} from '@angular/platform-browser/src/dom/dom_renderer';
Expand Down Expand Up @@ -217,13 +220,17 @@ export class NativeScriptRenderer extends Renderer {
let zonedCallback = (<any>global).Zone.current.wrap(callback);
renderElement.on(eventName, zonedCallback);
if (eventName === View.loadedEvent && renderElement.isLoaded) {
const notifyData = {eventName: View.loadedEvent, object: renderElement};
const notifyData = { eventName: View.loadedEvent, object: renderElement };
zonedCallback(notifyData);
}
return () => renderElement.off(eventName, zonedCallback);
}

public listenGlobal(target: string, eventName: string, callback: Function): Function {
throw new Error('Not implemented.');
throw new Error('NativeScriptRenderer.listenGlobal() - Not implemented.');
}

public animate(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer {
throw new Error("NativeScriptRenderer.animate() - Not implemented");
}
}
15 changes: 14 additions & 1 deletion nativescript-angular/router/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ export class NSLocationStrategy extends LocationStrategy {
return internal;
}


pushState(state: any, title: string, url: string, queryParams: string): void {
routerLog(`NSLocationStrategy.pushState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);
this.pushStateInternal(state, title, url, queryParams);
}

pushStateInternal(state: any, title: string, url: string, queryParams: string): void {
routerLog(`NSLocationStrategy.pushState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);

let isNewPage = this._isPageNavigatingForward;
this._isPageNavigatingForward = false;
Expand All @@ -47,7 +53,14 @@ export class NSLocationStrategy extends LocationStrategy {

replaceState(state: any, title: string, url: string, queryParams: string): void {
routerLog(`NSLocationStrategy.replaceState state: ${state}, title: ${title}, url: ${url}, queryParams: ${queryParams}`);
throw new Error("Not implemented");

if (this.states.length > 0) {
let oldState = this.states.pop();
routerLog(`NSLocationStrategy.replaceState POP state: ${oldState.state}, title: ${oldState.title}, url: ${oldState.url}, queryParams: ${oldState.queryParams}`);
this.callPopState(oldState, true);
}

this.pushStateInternal(state, title, url, queryParams);
}

forward(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {View} from "ui/core/view";
import {ControlValueAccessor} from '@angular/common/src/forms/directives/control_value_accessor';
import {ControlValueAccessor} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';

export class BaseValueAccessor<TView> implements ControlValueAccessor {
constructor(public view: TView) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor';
import {Switch} from "ui/switch";
Expand All @@ -18,7 +18,7 @@ const CHECKED_VALUE_ACCESSOR = provide(NG_VALUE_ACCESSOR, { useExisting: forward
@Directive({
selector: 'Switch[ngModel]',
host: { '(checkedChange)': 'onChange($event.value)' },
bindings: [CHECKED_VALUE_ACCESSOR]
providers: [CHECKED_VALUE_ACCESSOR]
})
export class CheckedValueAccessor extends BaseValueAccessor<Switch> {
onTouched = () => { };
Expand Down
9 changes: 6 additions & 3 deletions nativescript-angular/value-accessors/date-value-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank, isDate} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor';
import {DatePicker} from "ui/date-picker";
Expand All @@ -18,7 +18,7 @@ const DATE_VALUE_ACCESSOR = provide(NG_VALUE_ACCESSOR, { useExisting: forwardRef
@Directive({
selector: 'DatePicker[ngModel]',
host: { '(dateChange)': 'onChange($event.value)' },
bindings: [DATE_VALUE_ACCESSOR]
providers: [DATE_VALUE_ACCESSOR]
})
export class DateValueAccessor extends BaseValueAccessor<DatePicker> {
onTouched = () => { };
Expand All @@ -30,9 +30,12 @@ export class DateValueAccessor extends BaseValueAccessor<DatePicker> {
writeValue(value: any): void {
var normalizedValue = isBlank(value) ? new Date() : value;
if (!isDate(normalizedValue)) {
if (typeof normalizedValue === 'string' || typeof normalizedValue === 'number') {
if (typeof normalizedValue === 'string') {
normalizedValue = new Date(normalizedValue);
} else if (typeof normalizedValue === 'number') {
normalizedValue = new Date(normalizedValue);
}

if (!isDate(normalizedValue)) {
normalizedValue = new Date();
}
Expand Down
4 changes: 2 additions & 2 deletions nativescript-angular/value-accessors/number-value-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank, isNumber} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor';
import {Slider} from "ui/slider";
Expand All @@ -18,7 +18,7 @@ const NUMBER_VALUE_ACCESSOR = provide(NG_VALUE_ACCESSOR, { useExisting: forwardR
@Directive({
selector: 'Slider[ngModel]',
host: { '(valueChange)': 'onChange($event.value)' },
bindings: [NUMBER_VALUE_ACCESSOR]
providers: [NUMBER_VALUE_ACCESSOR]
})
export class NumberValueAccessor extends BaseValueAccessor<Slider> {
onTouched = () => { };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank, isNumber} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor';
import {View} from "ui/core/view";
Expand All @@ -21,7 +21,7 @@ export type SelectableView = {selectedIndex: number} & View;
@Directive({
selector: 'SegmentedBar[ngModel], ListPicker[ngModel], TabView[ngModel]',
host: { '(selectedIndexChange)': 'onChange($event.value)' },
bindings: [SELECTED_INDEX_VALUE_ACCESSOR]
providers: [SELECTED_INDEX_VALUE_ACCESSOR]
})
export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView> {
onTouched = () => { };
Expand Down
4 changes: 2 additions & 2 deletions nativescript-angular/value-accessors/text-value-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor'
import {View} from "ui/core/view";
Expand All @@ -20,7 +20,7 @@ export type TextView = {text: string} & View;
@Directive({
selector: 'TextField[ngModel], TextView[ngModel], SearchBar[ngModel]',
host: { '(textChange)': 'onChange($event.value)' },
bindings: [TEXT_VALUE_ACCESSOR]
providers: [TEXT_VALUE_ACCESSOR]
})
export class TextValueAccessor extends BaseValueAccessor<TextView> {
onTouched = () => { };
Expand Down
8 changes: 5 additions & 3 deletions nativescript-angular/value-accessors/time-value-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, Renderer, Self, forwardRef, provide} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms/directives/control_value_accessor';
import {NG_VALUE_ACCESSOR} from '@angular/common/src/forms-deprecated/directives/control_value_accessor';
import {isBlank, isDate} from '@angular/core/src/facade/lang';
import {BaseValueAccessor} from './base-value-accessor';
import {TimePicker} from "ui/time-picker";
Expand All @@ -18,7 +18,7 @@ const TIME_VALUE_ACCESSOR = provide(NG_VALUE_ACCESSOR, { useExisting: forwardRef
@Directive({
selector: 'TimePicker[ngModel]',
host: { '(timeChange)': 'onChange($event.value)' },
bindings: [TIME_VALUE_ACCESSOR]
providers: [TIME_VALUE_ACCESSOR]
})
export class TimeValueAccessor extends BaseValueAccessor<TimePicker> {
onTouched = () => { };
Expand All @@ -30,7 +30,9 @@ export class TimeValueAccessor extends BaseValueAccessor<TimePicker> {
writeValue(value: any): void {
var normalizedValue = isBlank(value) ? new Date() : value;
if (!isDate(normalizedValue)) {
if (typeof normalizedValue === 'string' || typeof normalizedValue === 'number') {
if (typeof normalizedValue === 'string') {
normalizedValue = new Date(normalizedValue);
} else if (typeof normalizedValue === 'number') {
normalizedValue = new Date(normalizedValue);
}
if (!isDate(normalizedValue)) {
Expand Down
29 changes: 14 additions & 15 deletions ng-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
},
"homepage": "https://github.com/NativeScript/template-hello-world",
"dependencies": {
"tns-core-modules": ">=2.0.0 || >=2.1.0-2016 || >=2.0.0-angular-7",
"nativescript-angular": "^0.1.6",
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/platform-server": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"tns-core-modules": ">=2.0.0 || >=2.1.0-2016 || 2.0.0-angular-7",
"nativescript-angular": "^0.1.6"
},
"devDependencies": {
"nativescript-dev-typescript": "^0.3.1",
"nativescript-dev-webpack": "0.0.13",
"typescript": "^1.8.10",
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"@angular/platform-browser-dynamic": "2.0.0-rc.2",
"@angular/platform-server": "2.0.0-rc.2",
"@angular/router-deprecated": "2.0.0-rc.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
Expand All @@ -42,11 +46,6 @@
"url": "0.10.3",
"shelljs": "^0.7.0"
},
"devDependencies": {
"nativescript-dev-typescript": "^0.3.1",
"nativescript-dev-webpack": "0.0.13",
"typescript": "^1.8.10"
},
"nativescript": {
"id": "org.nativescript.ngsample",
"tns-android": {
Expand Down
Loading