Skip to content

Commit 78d5d92

Browse files
author
vakrilov
committed
Migrate to RC4
1 parent 068925d commit 78d5d92

File tree

5 files changed

+73
-49
lines changed

5 files changed

+73
-49
lines changed

nativescript-angular/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
},
2020
"dependencies": {
2121
"nativescript-intl": "^0.0.2",
22-
"@angular/common": "2.0.0-rc.3",
23-
"@angular/compiler": "2.0.0-rc.3",
24-
"@angular/core": "2.0.0-rc.3",
25-
"@angular/http": "2.0.0-rc.3",
26-
"@angular/platform-browser": "2.0.0-rc.3",
27-
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
28-
"@angular/platform-server": "2.0.0-rc.3",
22+
"@angular/core": "2.0.0-rc.4",
23+
"@angular/common": "2.0.0-rc.4",
24+
"@angular/compiler": "2.0.0-rc.4",
25+
"@angular/http": "2.0.0-rc.4",
26+
"@angular/platform-browser": "2.0.0-rc.4",
27+
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
28+
"@angular/platform-server": "2.0.0-rc.4",
2929
"@angular/router-deprecated": "2.0.0-rc.2",
30-
"@angular/router": "3.0.0-alpha.7",
30+
"@angular/router": "3.0.0-beta.2",
3131
"rxjs": "5.0.0-beta.6",
3232
"zone.js": "^0.6.12",
3333
"reflect-metadata": "^0.1.3",

nativescript-angular/router/ns-router.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {Type} from '@angular/core/src/facade/lang';
2-
import {provide, Injectable} from '@angular/core';
3-
import {LocationStrategy, PlatformLocation, UrlChangeListener} from '@angular/common';
2+
import {provide} from '@angular/core';
3+
import {LocationStrategy, PlatformLocation} from '@angular/common';
44
import { RouterConfig } from '@angular/router';
5-
import { provideRouter, ExtraOptions } from '@angular/router/common_router_providers';
5+
import { provideRouter, ExtraOptions } from '@angular/router/src/common_router_providers';
66

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

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

@@ -28,6 +27,6 @@ export const NS_ROUTER_DIRECTIVES: Type[] = [
2827
export function nsProvideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
2928
return [
3029
...NS_ROUTER_PROVIDERS,
31-
...provideRouter(config, opts)
32-
]
30+
...provideRouter(config, opts) // NOTE: use provideRouter form common_router_providers - it doesnt include BrowserPlatformLocation
31+
];
3332
};

nativescript-angular/router/page-router-outlet.ts

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
22
Attribute, ComponentFactory, ComponentRef, Directive,
33
ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef,
4-
Inject, ComponentResolver, provide} from '@angular/core';
4+
Inject, ComponentResolver, provide, ComponentFactoryResolver,
5+
NoComponentFactoryError} from '@angular/core';
56

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

8-
import {RouterOutletMap, ActivatedRoute, PRIMARY_OUTLET} from '@angular/router';
9-
import {RouterOutlet} from '@angular/router/directives/router_outlet';
9+
import {RouterOutletMap, ActivatedRoute, RouterOutlet, PRIMARY_OUTLET} from '@angular/router';
1010
import {NSLocationStrategy} from "./ns-location-strategy";
1111
import {DEVICE} from "../platform-providers";
1212
import {Device} from "platform";
@@ -40,10 +40,8 @@ class RefCache {
4040
}
4141
}
4242

43-
44-
4543
@Directive({ selector: 'page-router-outlet' })
46-
export class PageRouterOutlet extends RouterOutlet {
44+
export class PageRouterOutlet {
4745
private viewUtil: ViewUtil;
4846
private refCache: RefCache = new RefCache();
4947
private isInitalPage: boolean = true;
@@ -52,6 +50,8 @@ export class PageRouterOutlet extends RouterOutlet {
5250
private currnetActivatedComp: ComponentRef<any>;
5351
private currentActivatedRoute: ActivatedRoute;
5452

53+
public outletMap: RouterOutletMap;
54+
5555
get isActivated(): boolean {
5656
return !!this.currnetActivatedComp;
5757
}
@@ -76,15 +76,17 @@ export class PageRouterOutlet extends RouterOutlet {
7676
private containerRef: ViewContainerRef,
7777
@Attribute('name') name: string,
7878
private locationStrategy: NSLocationStrategy,
79+
private componentFactoryResolver: ComponentFactoryResolver,
7980
compiler: ComponentResolver,
8081
@Inject(DEVICE) device: Device) {
81-
super(parentOutletMap, containerRef, name)
82+
83+
parentOutletMap.registerOutlet(name ? name : PRIMARY_OUTLET, <any>this);
8284

8385
this.viewUtil = new ViewUtil(device);
8486
compiler.resolveComponent(DetachedLoader).then((detachedLoaderFactory) => {
8587
log("DetachedLoaderFactory leaded");
8688
this.detachedLoaderFactory = detachedLoaderFactory;
87-
})
89+
});
8890
}
8991

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

126127
if (this.locationStrategy.isPageNavigatingBack()) {
127-
this.activateOnGoBack(factory, activatedRoute, providers);
128+
this.activateOnGoBack(activatedRoute, providers);
128129
} else {
129-
this.activateOnGoForward(factory, activatedRoute, providers);
130+
this.activateOnGoForward(activatedRoute, providers);
130131
}
131132
}
132133

133134
private activateOnGoForward(
134-
factory: ComponentFactory<any>,
135135
activatedRoute: ActivatedRoute,
136136
providers: ResolvedReflectiveProvider[]): void {
137+
const factory = this.getComponentFactory(activatedRoute);
137138

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

148149
const page = new Page();
149-
const pageResolvedProvider = ReflectiveInjector.resolve([provide(Page, { useValue: page })])
150+
const pageResolvedProvider = ReflectiveInjector.resolve([provide(Page, { useValue: page })]);
150151
const childInjector = ReflectiveInjector.fromResolvedProviders([...providers, ...pageResolvedProvider], this.containerRef.parentInjector);
151152
const loaderRef = this.containerRef.createComponent(this.detachedLoaderFactory, this.containerRef.length, childInjector, []);
152153

@@ -156,7 +157,7 @@ export class PageRouterOutlet extends RouterOutlet {
156157
}
157158
}
158159

159-
private activateOnGoBack(factory: ComponentFactory<any>,
160+
private activateOnGoBack(
160161
activatedRoute: ActivatedRoute,
161162
providers: ResolvedReflectiveProvider[]): void {
162163
log("PageRouterOutlet.activate() - Back naviation, so load from cache: " + activatedRoute.component);
@@ -189,11 +190,35 @@ export class PageRouterOutlet extends RouterOutlet {
189190
create: () => { return page; }
190191
});
191192
}
193+
194+
// NOTE: Using private APIs - potential break point!
195+
private getComponentFactory(activatedRoute: any): ComponentFactory<any> {
196+
const snapshot = activatedRoute._futureSnapshot;
197+
const component: any = <any>snapshot._routeConfig.component;
198+
let factory: ComponentFactory<any>;
199+
try {
200+
factory = typeof component === 'string' ?
201+
snapshot._resolvedComponentFactory :
202+
this.componentFactoryResolver.resolveComponentFactory(component);
203+
} catch (e) {
204+
if (!(e instanceof NoComponentFactoryError)) {
205+
throw e;
206+
}
207+
// TODO: vsavkin uncomment this once ComponentResolver is deprecated
208+
// const componentName = component ? component.name : null;
209+
// console.warn(
210+
// `'${componentName}' not found in precompile array. To ensure all components referred
211+
// to by the RouterConfig are compiled, you must add '${componentName}' to the
212+
// 'precompile' array of your application component. This will be required in a future
213+
// release of the router.`);
214+
215+
factory = snapshot._resolvedComponentFactory;
216+
}
217+
return factory;
218+
}
219+
192220
}
193221

194222
function log(msg: string) {
195223
routerLog(msg);
196-
}
197-
198-
199-
224+
}

ng-sample/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
"tns-core-modules": ">=2.1.0 || >=2.1.0-2016",
2727
"nativescript-angular": "^0.2.0",
2828
"nativescript-intl": "^0.0.2",
29-
"@angular/common": "2.0.0-rc.3",
30-
"@angular/compiler": "2.0.0-rc.3",
31-
"@angular/core": "2.0.0-rc.3",
32-
"@angular/http": "2.0.0-rc.3",
33-
"@angular/platform-browser": "2.0.0-rc.3",
34-
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
35-
"@angular/platform-server": "2.0.0-rc.3",
29+
"@angular/core": "2.0.0-rc.4",
30+
"@angular/common": "2.0.0-rc.4",
31+
"@angular/compiler": "2.0.0-rc.4",
32+
"@angular/http": "2.0.0-rc.4",
33+
"@angular/platform-browser": "2.0.0-rc.4",
34+
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
35+
"@angular/platform-server": "2.0.0-rc.4",
3636
"@angular/router-deprecated": "2.0.0-rc.2",
37-
"@angular/router": "3.0.0-alpha.7",
37+
"@angular/router": "3.0.0-beta.2",
3838
"rxjs": "5.0.0-beta.6",
3939
"zone.js": "^0.6.12",
4040
"reflect-metadata": "^0.1.3",
@@ -63,4 +63,4 @@
6363
"version": "2.1.0"
6464
}
6565
}
66-
}
66+
}

tests/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
"nativescript-unit-test-runner": "^0.3.3",
3030
"tns-core-modules": ">=2.1.0",
3131
"nativescript-angular": "^0.2.0",
32-
"@angular/common": "2.0.0-rc.3",
33-
"@angular/compiler": "2.0.0-rc.3",
34-
"@angular/core": "2.0.0-rc.3",
35-
"@angular/http": "2.0.0-rc.3",
36-
"@angular/platform-browser": "2.0.0-rc.3",
37-
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
38-
"@angular/platform-server": "2.0.0-rc.3",
32+
"@angular/core": "2.0.0-rc.4",
33+
"@angular/common": "2.0.0-rc.4",
34+
"@angular/compiler": "2.0.0-rc.4",
35+
"@angular/http": "2.0.0-rc.4",
36+
"@angular/platform-browser": "2.0.0-rc.4",
37+
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
38+
"@angular/platform-server": "2.0.0-rc.4",
3939
"@angular/router-deprecated": "2.0.0-rc.2",
40-
"@angular/router": "3.0.0-alpha.7",
40+
"@angular/router": "3.0.0-beta.2",
4141
"rxjs": "5.0.0-beta.6",
4242
"zone.js": "^0.6.12",
4343
"reflect-metadata": "^0.1.3",

0 commit comments

Comments
 (0)