From 947c592735095855c9abf706f50849155ea9dad1 Mon Sep 17 00:00:00 2001 From: James deBoer Date: Thu, 1 May 2014 15:57:50 -0700 Subject: [PATCH] revert(NgView): Reverts "Make use of the ViewPort" This reverts commit ed40de4d63f48b5b565c2b8be05fe15c0fd5c327. Conflicts: lib/routing/ng_view.dart test/routing/routing_spec.dart --- lib/routing/ng_view.dart | 79 ++++++++++++++-------------------- test/routing/ng_view_spec.dart | 36 ++++++---------- test/routing/routing_spec.dart | 24 ++++++----- 3 files changed, 59 insertions(+), 80 deletions(-) diff --git a/lib/routing/ng_view.dart b/lib/routing/ng_view.dart index 5700b3632..248927ff7 100644 --- a/lib/routing/ng_view.dart +++ b/lib/routing/ng_view.dart @@ -58,49 +58,47 @@ part of angular.routing; @Decorator( selector: 'ng-view', module: NgView.module, - children: Directive.TRANSCLUDE_CHILDREN) + visibility: Directive.CHILDREN_VISIBILITY) class NgView implements DetachAware, RouteProvider { static final Module _module = new Module() ..bind(RouteProvider, toFactory: (i) => i.get(NgView)); - static module() => _module; - final NgRoutingHelper _locationService; - final ViewCache _viewCache; - final Injector _injector; - final Scope _scope; + final NgRoutingHelper locationService; + final ViewCache viewCache; + final Injector injector; + final Element element; + final Scope scope; RouteHandle _route; - final ViewPort _viewPort; - View _view; - Scope _childScope; + Scope _scope; Route _viewRoute; - - NgView(this._viewCache, Injector injector, Router router, - this._scope, this._viewPort) - : _injector = injector, - _locationService = injector.get(NgRoutingHelper) + NgView(this.element, this.viewCache, + Injector injector, Router router, + this.scope) + : injector = injector, + locationService = injector.get(NgRoutingHelper) { - RouteProvider routeProvider = _injector.parent.get(NgView); + RouteProvider routeProvider = injector.parent.get(NgView); _route = routeProvider != null ? routeProvider.route.newHandle() : router.root.newHandle(); - _locationService._registerPortal(this); + locationService._registerPortal(this); _maybeReloadViews(); } void _maybeReloadViews() { - if (_route.isActive) _locationService._reloadViews(startingFrom: _route); + if (_route.isActive) locationService._reloadViews(startingFrom: _route); } - void detach() { + detach() { _route.discard(); - _locationService._unregisterPortal(this); + locationService._unregisterPortal(this); } - void _show(_View viewDef, Route route, List modules) { + _show(_View viewDef, Route route, List modules) { assert(route.isActive); if (_viewRoute != null) return; @@ -115,51 +113,40 @@ class NgView implements DetachAware, RouteProvider { }); var viewInjector = modules == null ? - _injector : - forceNewDirectivesAndFormatters(_injector, modules); + injector : + forceNewDirectivesAndFormatters(injector, modules); var newDirectives = viewInjector.get(DirectiveMap); var viewFuture = viewDef.templateHtml != null ? - new Future.value(_viewCache.fromHtml(viewDef.templateHtml, newDirectives)) : - _viewCache.fromUrl(viewDef.template, newDirectives); - + new Future.value(viewCache.fromHtml(viewDef.templateHtml, newDirectives)) : + viewCache.fromUrl(viewDef.template, newDirectives); viewFuture.then((viewFactory) { _cleanUp(); - _childScope = _scope.createChild(new PrototypeMap(_scope.context)); + _scope = scope.createChild(new PrototypeMap(scope.context)); _view = viewFactory( - viewInjector.createChild([new Module()..bind(Scope, toValue: _childScope)])); - - var view = _view; - _scope.rootScope.domWrite(() { - _viewPort.insert(view); - }); + viewInjector.createChild([new Module()..bind(Scope, toValue: _scope)])); + _view.nodes.forEach((elm) => element.append(elm)); }); } - void _cleanUp() { + _cleanUp() { if (_view == null) return; - var view = _view; - var childScope = _childScope; - _scope.rootScope.domWrite(() { - _viewPort.remove(view); - childScope.destroy(); - }); + _view.nodes.forEach((node) => node.remove()); + _scope.destroy(); _view = null; - _childScope = null; + _scope = null; } Route get route => _viewRoute; - String get routeName => _viewRoute.name; - Map get parameters { var res = {}; - var route = _viewRoute; - while (route != null) { - res.addAll(route.parameters); - route = route.parent; + var p = _viewRoute; + while (p != null) { + res.addAll(p.parameters); + p = p.parent; } return res; } diff --git a/test/routing/ng_view_spec.dart b/test/routing/ng_view_spec.dart index 9a59cd482..e165aea33 100644 --- a/test/routing/ng_view_spec.dart +++ b/test/routing/ng_view_spec.dart @@ -10,8 +10,8 @@ main() { TestBed _; Router router; - beforeEachModule((Module module) { - module + beforeEachModule((Module m) { + m ..install(new AngularMockModule()) ..bind(RouteInitializerFn, toImplementation: FlatRouteInitializer); }); @@ -28,22 +28,19 @@ main() { it('should switch template', async(() { - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('Foo'); router.route('/bar'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('Bar'); router.route('/foo'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('Foo'); })); @@ -59,31 +56,29 @@ main() { it('should switch template when route is already active', async(() { // Force the routing system to initialize. - _.compile('
'); + _.compile(''); router.route('/foo'); microLeap(); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); - microLeap(); _.rootScope.apply(); + microLeap(); expect(root.text).toEqual('Foo'); })); it('should clear template when route is deactivated', async(() { - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('Foo'); router.route('/baz'); // route without a template microLeap(); - _.rootScope.apply(); expect(root.text).toEqual(''); })); @@ -94,8 +89,8 @@ main() { TestBed _; Router router; - beforeEachModule((Module module) { - module + beforeEachModule((Module m) { + m ..install(new AngularMockModule()) ..bind(RouteInitializerFn, toImplementation: NestedRouteInitializer); }); @@ -116,29 +111,25 @@ main() { }); it('should switch nested templates', async(() { - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/library/all'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('LibraryBooks'); router.route('/library/1234'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/overview'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('LibraryBook 1234'); // nothing should change here router.route('/library/1234/read'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('LibraryRead Book 1234'); })); }); @@ -148,8 +139,8 @@ main() { TestBed _; Router router; - beforeEachModule((Module module) { - module + beforeEachModule((Module m) { + m ..install(new AngularMockModule()) ..bind(RouteInitializerFn, toValue: (router, views) { views.configure({ @@ -166,12 +157,11 @@ main() { }); it('should switch inline templates', async(() { - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); expect(root.text).toEqual('Hello'); })); }); diff --git a/test/routing/routing_spec.dart b/test/routing/routing_spec.dart index ad1b7af4f..bbc63cd31 100644 --- a/test/routing/routing_spec.dart +++ b/test/routing/routing_spec.dart @@ -158,12 +158,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

Foo

')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); + expect(enterCount).toBe(1); expect(root.text).toEqual('Foo'); })); @@ -231,18 +231,18 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '

Foo

')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); + expect(root.text).toEqual('Foo'); expect(leaveCount).toBe(0); router.route('/bar'); microLeap(); - _.rootScope.apply(); + expect(root.text).toEqual(''); expect(leaveCount).toBe(1); })); @@ -263,12 +263,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
Old!
')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); + expect(root.text).toEqual('New!'); })); @@ -288,12 +288,12 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
Old!
')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); - _.rootScope.apply(); + expect(root.text).toEqual('New!'); })); @@ -313,12 +313,13 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
{{\'World\' | hello}}
')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); _.rootScope.apply(); + expect(root.text).toEqual('Hello, World!'); })); @@ -338,12 +339,13 @@ main() { _.injector.get(TemplateCache) .put('foo.html', new HttpResponse(200, '
{{\'World\' | hello}}
')); - Element root = _.compile('
'); + Element root = _.compile(''); expect(root.text).toEqual(''); router.route('/foo'); microLeap(); _.rootScope.apply(); + expect(root.text).toEqual('Hello, World!'); }));