Index: third_party/pkg/angular/lib/routing/routing.dart |
diff --git a/third_party/pkg/angular/lib/routing/routing.dart b/third_party/pkg/angular/lib/routing/routing.dart |
index 4a26bf6f862b80d2533cda4e7ec4fb5eb8734fbf..c40aa068402f68e7274be79a5749e0553cd80115 100644 |
--- a/third_party/pkg/angular/lib/routing/routing.dart |
+++ b/third_party/pkg/angular/lib/routing/routing.dart |
@@ -3,39 +3,42 @@ part of angular.routing; |
/** |
* A factory of route to template bindings. |
*/ |
-class ViewFactory { |
+class RouteViewFactory { |
NgRoutingHelper locationService; |
- ViewFactory(this.locationService); |
+ RouteViewFactory(this.locationService); |
call(String templateUrl) => |
(RouteEnterEvent event) => _enterHandler(event, templateUrl); |
- _enterHandler(RouteEnterEvent event, String templateUrl, [List<Module> modules]) => |
- locationService._route(event.route, templateUrl, fromEvent: true, modules: modules); |
+ _enterHandler(RouteEnterEvent event, String templateUrl, |
+ {List<Module> modules, String templateHtml}) => |
+ locationService._route(event.route, templateUrl, fromEvent: true, |
+ modules: modules, templateHtml: templateHtml); |
configure(Map<String, NgRouteCfg> config) => |
_configure(locationService.router.root, config); |
_configure(Route route, Map<String, NgRouteCfg> config) { |
config.forEach((name, cfg) { |
- var moduledCalled = false; |
+ var modulesCalled = false; |
List<Module> newModules; |
route.addRoute( |
name: name, |
path: cfg.path, |
defaultRoute: cfg.defaultRoute, |
enter: (RouteEnterEvent e) { |
- if (cfg.view != null) { |
- _enterHandler(e, cfg.view, newModules); |
+ if (cfg.view != null || cfg.viewHtml != null) { |
+ _enterHandler(e, cfg.view, |
+ modules: newModules, templateHtml: cfg.viewHtml); |
} |
if (cfg.enter != null) { |
cfg.enter(e); |
} |
}, |
preEnter: (RoutePreEnterEvent e) { |
- if (cfg.modules != null && !moduledCalled) { |
- moduledCalled = true; |
+ if (cfg.modules != null && !modulesCalled) { |
+ modulesCalled = true; |
var modules = cfg.modules(); |
if (modules is Future) { |
e.allowEnter(modules.then((List<Module> m) { |
@@ -60,16 +63,18 @@ class ViewFactory { |
} |
} |
-NgRouteCfg ngRoute({String path, String view, Map<String, NgRouteCfg> mount, |
- modules(), bool defaultRoute: false, RoutePreEnterEventHandler preEnter, |
- RouteEnterEventHandler enter, RouteLeaveEventHandler leave}) => |
- new NgRouteCfg(path: path, view: view, mount: mount, modules: modules, |
- defaultRoute: defaultRoute, preEnter: preEnter, enter: enter, |
- leave: leave); |
+NgRouteCfg ngRoute({String path, String view, String viewHtml, |
+ Map<String, NgRouteCfg> mount, modules(), bool defaultRoute: false, |
+ RoutePreEnterEventHandler preEnter, RouteEnterEventHandler enter, |
+ RouteLeaveEventHandler leave}) => |
+ new NgRouteCfg(path: path, view: view, viewHtml: viewHtml, mount: mount, |
+ modules: modules, defaultRoute: defaultRoute, preEnter: preEnter, |
+ enter: enter, leave: leave); |
class NgRouteCfg { |
final String path; |
final String view; |
+ final String viewHtml; |
final Map<String, NgRouteCfg> mount; |
final Function modules; |
final bool defaultRoute; |
@@ -77,8 +82,8 @@ class NgRouteCfg { |
final RoutePreEnterEventHandler preEnter; |
final RouteLeaveEventHandler leave; |
- NgRouteCfg({this.view, this.path, this.mount, this.modules, this.defaultRoute, |
- this.enter, this.preEnter, this.leave}); |
+ NgRouteCfg({this.view, this.viewHtml, this.path, this.mount, this.modules, |
+ this.defaultRoute, this.enter, this.preEnter, this.leave}); |
} |
/** |
@@ -87,12 +92,10 @@ class NgRouteCfg { |
* |
* The [init] method will be called by the framework once the router is |
* instantiated but before [NgBindRouteDirective] and [NgViewDirective]. |
- * |
- * Deprecated: use RouteInitializerFn instead. |
*/ |
-@deprecated |
+@Deprecated("use RouteInitializerFn instead") |
abstract class RouteInitializer { |
- void init(Router router, ViewFactory viewFactory); |
+ void init(Router router, RouteViewFactory viewFactory); |
} |
/** |
@@ -102,20 +105,21 @@ abstract class RouteInitializer { |
* The function will be called by the framework once the router is |
* instantiated but before [NgBindRouteDirective] and [NgViewDirective]. |
*/ |
-typedef void RouteInitializerFn(Router router, ViewFactory viewFactory); |
+typedef void RouteInitializerFn(Router router, RouteViewFactory viewFactory); |
/** |
* A singleton helper service that handles routing initialization, global |
* events and view registries. |
*/ |
-@NgInjectableService() |
+@Injectable() |
class NgRoutingHelper { |
final Router router; |
- final NgApp _ngApp; |
- List<NgViewDirective> portals = <NgViewDirective>[]; |
+ final Application _ngApp; |
+ List<NgView> portals = <NgView>[]; |
Map<String, _View> _templates = new Map<String, _View>(); |
- NgRoutingHelper(RouteInitializer initializer, Injector injector, this.router, this._ngApp) { |
+ NgRoutingHelper(RouteInitializer initializer, Injector injector, this.router, |
+ this._ngApp) { |
// TODO: move this to constructor parameters when di issue is fixed: |
// https://github.com/angular/di.dart/issues/40 |
RouteInitializerFn initializerFn = injector.get(RouteInitializerFn); |
@@ -125,22 +129,22 @@ class NgRoutingHelper { |
}; |
if (initializerFn != null) { |
- initializerFn(router, new ViewFactory(this)); |
+ initializerFn(router, new RouteViewFactory(this)); |
} else { |
- initializer.init(router, new ViewFactory(this)); |
+ initializer.init(router, new RouteViewFactory(this)); |
} |
router.onRouteStart.listen((RouteStartEvent routeEvent) { |
routeEvent.completed.then((success) { |
if (success) { |
- portals.forEach((NgViewDirective p) => p._maybeReloadViews()); |
+ portals.forEach((NgView p) => p._maybeReloadViews()); |
} |
}); |
}); |
- router.listen(appRoot: _ngApp.root); |
+ router.listen(appRoot: _ngApp.element); |
} |
- _reloadViews({Route startingFrom}) { |
+ void _reloadViews({Route startingFrom}) { |
var alreadyActiveViews = []; |
var activePath = router.activePath; |
if (startingFrom != null) { |
@@ -151,36 +155,38 @@ class NgRoutingHelper { |
if (viewDef == null) continue; |
var templateUrl = viewDef.template; |
- NgViewDirective view = portals.lastWhere((NgViewDirective v) { |
+ NgView view = portals.lastWhere((NgView v) { |
return _routePath(route) != _routePath(v._route) && |
_routePath(route).startsWith(_routePath(v._route)); |
}, orElse: () => null); |
if (view != null && !alreadyActiveViews.contains(view)) { |
- view._show(templateUrl, route, viewDef.modules); |
+ view._show(viewDef, route, viewDef.modules); |
alreadyActiveViews.add(view); |
break; |
} |
} |
} |
- _route(Route route, String template, {bool fromEvent, List<Module> modules}) { |
- _templates[_routePath(route)] = new _View(template, modules); |
+ void _route(Route route, String template, {bool fromEvent, List<Module> modules, |
+ String templateHtml}) { |
+ _templates[_routePath(route)] = new _View(template, templateHtml, modules); |
} |
- _registerPortal(NgViewDirective ngView) { |
+ void _registerPortal(NgView ngView) { |
portals.add(ngView); |
} |
- _unregisterPortal(NgViewDirective ngView) { |
+ void _unregisterPortal(NgView ngView) { |
portals.remove(ngView); |
} |
} |
class _View { |
final String template; |
+ final String templateHtml; |
final List<Module> modules; |
- _View(this.template, this.modules); |
+ _View(this.template, this.templateHtml, this.modules); |
} |
String _routePath(Route route) { |