Skip to content

Migrate to RC4 #336

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
Jul 15, 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
2 changes: 1 addition & 1 deletion nativescript-angular/http/ns-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class NSXSRFStrategy {

@Injectable()
export class NSHttp extends Http {
constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private nsFileSystem: NSFileSystem) {
constructor(backend: ConnectionBackend, defaultOptions: any, private nsFileSystem: NSFileSystem) {
super(backend, defaultOptions);
}

Expand Down
16 changes: 8 additions & 8 deletions nativescript-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
},
"dependencies": {
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.4",
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/platform-server": "2.0.0-rc.4",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"@angular/router": "3.0.0-beta.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
Expand Down
11 changes: 5 additions & 6 deletions nativescript-angular/router/ns-router.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {Type} from '@angular/core/src/facade/lang';
import {provide, Injectable} from '@angular/core';
import {LocationStrategy, PlatformLocation, UrlChangeListener} from '@angular/common';
import {provide} from '@angular/core';
import {LocationStrategy, PlatformLocation} from '@angular/common';
import { RouterConfig } from '@angular/router';
import { provideRouter, ExtraOptions } from '@angular/router/common_router_providers';
import { provideRouter, ExtraOptions } from '@angular/router/src/common_router_providers';

import {NSRouterLink} from './ns-router-link';
import {PageRouterOutlet} from './page-router-outlet';
import {NSLocationStrategy} from './ns-location-strategy';
import {NativescriptPlatformLocation} from './ns-platform-location';
import {routerLog} from "../trace";

export {routerTraceCategory} from "../trace";

Expand All @@ -28,6 +27,6 @@ export const NS_ROUTER_DIRECTIVES: Type[] = [
export function nsProvideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
return [
...NS_ROUTER_PROVIDERS,
...provideRouter(config, opts)
]
...provideRouter(config, opts) // NOTE: use provideRouter form common_router_providers - it doesnt include BrowserPlatformLocation
];
};
61 changes: 43 additions & 18 deletions nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
Attribute, ComponentFactory, ComponentRef, Directive,
ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef,
Inject, ComponentResolver, provide} from '@angular/core';
Inject, ComponentResolver, provide, ComponentFactoryResolver,
NoComponentFactoryError} from '@angular/core';

import {isBlank, isPresent} from '@angular/core/src/facade/lang';

import {RouterOutletMap, ActivatedRoute, PRIMARY_OUTLET} from '@angular/router';
import {RouterOutlet} from '@angular/router/directives/router_outlet';
import {RouterOutletMap, ActivatedRoute, RouterOutlet, PRIMARY_OUTLET} from '@angular/router';
import {NSLocationStrategy} from "./ns-location-strategy";
import {DEVICE} from "../platform-providers";
import {Device} from "platform";
Expand Down Expand Up @@ -40,10 +40,8 @@ class RefCache {
}
}



@Directive({ selector: 'page-router-outlet' })
export class PageRouterOutlet extends RouterOutlet {
export class PageRouterOutlet {
private viewUtil: ViewUtil;
private refCache: RefCache = new RefCache();
private isInitalPage: boolean = true;
Expand All @@ -52,6 +50,8 @@ export class PageRouterOutlet extends RouterOutlet {
private currnetActivatedComp: ComponentRef<any>;
private currentActivatedRoute: ActivatedRoute;

public outletMap: RouterOutletMap;

get isActivated(): boolean {
return !!this.currnetActivatedComp;
}
Expand All @@ -76,15 +76,17 @@ export class PageRouterOutlet extends RouterOutlet {
private containerRef: ViewContainerRef,
@Attribute('name') name: string,
private locationStrategy: NSLocationStrategy,
private componentFactoryResolver: ComponentFactoryResolver,
compiler: ComponentResolver,
@Inject(DEVICE) device: Device) {
super(parentOutletMap, containerRef, name)

parentOutletMap.registerOutlet(name ? name : PRIMARY_OUTLET, <any>this);

this.viewUtil = new ViewUtil(device);
compiler.resolveComponent(DetachedLoader).then((detachedLoaderFactory) => {
log("DetachedLoaderFactory leaded");
this.detachedLoaderFactory = detachedLoaderFactory;
})
});
}

deactivate(): void {
Expand Down Expand Up @@ -115,7 +117,6 @@ export class PageRouterOutlet extends RouterOutlet {
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
*/
activate(
factory: ComponentFactory<any>,
activatedRoute: ActivatedRoute,
providers: ResolvedReflectiveProvider[],
outletMap: RouterOutletMap): void {
Expand All @@ -124,16 +125,16 @@ export class PageRouterOutlet extends RouterOutlet {
this.currentActivatedRoute = activatedRoute;

if (this.locationStrategy.isPageNavigatingBack()) {
this.activateOnGoBack(factory, activatedRoute, providers);
this.activateOnGoBack(activatedRoute, providers);
} else {
this.activateOnGoForward(factory, activatedRoute, providers);
this.activateOnGoForward(activatedRoute, providers);
}
}

private activateOnGoForward(
factory: ComponentFactory<any>,
activatedRoute: ActivatedRoute,
providers: ResolvedReflectiveProvider[]): void {
const factory = this.getComponentFactory(activatedRoute);

if (this.isInitalPage) {
log("PageRouterOutlet.activate() inital page - just load component: " + activatedRoute.component);
Expand All @@ -146,7 +147,7 @@ export class PageRouterOutlet extends RouterOutlet {
log("PageRouterOutlet.activate() forward navigation - create detached loader in the loader container: " + activatedRoute.component);

const page = new Page();
const pageResolvedProvider = ReflectiveInjector.resolve([provide(Page, { useValue: page })])
const pageResolvedProvider = ReflectiveInjector.resolve([provide(Page, { useValue: page })]);
const childInjector = ReflectiveInjector.fromResolvedProviders([...providers, ...pageResolvedProvider], this.containerRef.parentInjector);
const loaderRef = this.containerRef.createComponent(this.detachedLoaderFactory, this.containerRef.length, childInjector, []);

Expand All @@ -156,7 +157,7 @@ export class PageRouterOutlet extends RouterOutlet {
}
}

private activateOnGoBack(factory: ComponentFactory<any>,
private activateOnGoBack(
activatedRoute: ActivatedRoute,
providers: ResolvedReflectiveProvider[]): void {
log("PageRouterOutlet.activate() - Back naviation, so load from cache: " + activatedRoute.component);
Expand Down Expand Up @@ -189,11 +190,35 @@ export class PageRouterOutlet extends RouterOutlet {
create: () => { return page; }
});
}

// NOTE: Using private APIs - potential break point!
private getComponentFactory(activatedRoute: any): ComponentFactory<any> {
const snapshot = activatedRoute._futureSnapshot;
const component: any = <any>snapshot._routeConfig.component;
let factory: ComponentFactory<any>;
try {
factory = typeof component === 'string' ?
snapshot._resolvedComponentFactory :
this.componentFactoryResolver.resolveComponentFactory(component);
} catch (e) {
if (!(e instanceof NoComponentFactoryError)) {
throw e;
}
// TODO: vsavkin uncomment this once ComponentResolver is deprecated
// const componentName = component ? component.name : null;
// console.warn(
// `'${componentName}' not found in precompile array. To ensure all components referred
// to by the RouterConfig are compiled, you must add '${componentName}' to the
// 'precompile' array of your application component. This will be required in a future
// release of the router.`);

factory = snapshot._resolvedComponentFactory;
}
return factory;
}

}

function log(msg: string) {
routerLog(msg);
}



}
18 changes: 9 additions & 9 deletions ng-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
"nativescript-angular": "^0.2.0",
"nativescript-intl": "^0.0.2",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.4",
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/platform-server": "2.0.0-rc.4",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"@angular/router": "3.0.0-beta.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
Expand Down Expand Up @@ -63,4 +63,4 @@
"version": "2.1.0"
}
}
}
}
20 changes: 10 additions & 10 deletions tests/app/tests/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
beforeEach,
beforeEachProviders
} from '@angular/core/testing';
import {provide, ReflectiveInjector} from '@angular/core';
import {ReflectiveInjector} from '@angular/core';
import {BaseRequestOptions, ConnectionBackend, Http, HTTP_PROVIDERS, Response, ResponseOptions} from '@angular/http';
import 'rxjs/add/operator/map';
import {MockBackend} from '@angular/http/testing';
Expand All @@ -20,17 +20,17 @@ describe("Http", () => {

beforeEach(() => {
let injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
BaseRequestOptions,
MockBackend,
provide(NSFileSystem, { useClass: NSFileSystemMock }),
provide(Http, {
useFactory: function (backend: ConnectionBackend, defaultOptions: BaseRequestOptions, nsFileSystem: NSFileSystem) {
//HACK: cast backend to any to work around an angular typings problem
return new NSHttp(<any>backend, <any>defaultOptions, nsFileSystem);
},
deps: [MockBackend, BaseRequestOptions, NSFileSystem]
})
{ provide: NSFileSystem, useClass: NSFileSystemMock },
{
provide: Http,
useFactory: function (backend: ConnectionBackend, defaultOptions: BaseRequestOptions, nsFileSystem: NSFileSystem) {
//HACK: cast backend to any to work around an angular typings problem
return new NSHttp(<any>backend, defaultOptions, nsFileSystem);
},
deps: [MockBackend, BaseRequestOptions, NSFileSystem]
}
]);

backend = injector.get(MockBackend);
Expand Down
16 changes: 8 additions & 8 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"nativescript-unit-test-runner": "^0.3.3",
"tns-core-modules": ">=2.1.0",
"nativescript-angular": "^0.2.0",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.4",
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/platform-server": "2.0.0-rc.4",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/router": "3.0.0-alpha.7",
"@angular/router": "3.0.0-beta.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"reflect-metadata": "^0.1.3",
Expand Down