Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

refactor(NgView): Make use of the ViewPort #1069

Closed
wants to merge 1 commit into from

Conversation

vicb
Copy link
Contributor

@vicb vicb commented May 26, 2014

Closes 704

This was first introduced by #910 and later reverted in #991.

Some info about the change:

  • NgView now makes use of the ViewPort instead of appending / removing elements manually,
  • This means that <ng-view> is removed from the DOM in favor of an anchor (HTML comment),
  • To exist the anchor must have a parent, which is which <ng-view>s are wrapped in div in the tests,
  • The added _.rootScope.apply() is required to run the flush phase when the view are inserto to /removed from the DOM.

@pavelgj @jbdeboer you have both commented the original PR, could you please review this one and let me know if you seen issues with it. Thanks.

@vicb vicb added cla: yes and removed cla: no labels May 26, 2014
@@ -28,24 +28,27 @@ main() {


it('should switch template', async(() {
Element root = _.compile('<ng-view></ng-view>');
Element root = _.compile('<div><ng-view></ng-view></div>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you wrap these in div?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ngview need to have a parent for transclude to work as explained in the PR comment. Let me know of anything is unclear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually let me try to put this in a clearer way:

Without the wrapping <div>, compile() would return the <ng-view> node.

It was perfectly fine before this PR because the nodes were added as children of <ng-view>.

Now that we use transclusion, the <ng-view> node is removed from the DOM and replaced by an anchor (<!--ANCHOR: ng-view-->). The view nodes are appended as siblings of this anchor the <ng-view> node is removed from the DOM at compile time and <ng-view>.text will always ever contain its content at compile time: "".

@vicb
Copy link
Contributor Author

vicb commented May 27, 2014

I have updated the PR to use flush() instead of apply() which better reflects why this call is needed.

var childScope = _scope;
_scope.rootScope.domWrite(() {
_viewPort.remove(view);
childScope.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destroying scope in domWrite feels odd to me... but I can't say if that will cause issues... just pointing it out... no action required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destroying scope in domWrite is wrong. It should be destroyed immediately, and DOM operation delayed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

@pavelgj
Copy link
Contributor

pavelgj commented May 27, 2014

I don't know why it was reverted, don't think the bug was isolated... but this generally lgtm.

@vicb
Copy link
Contributor Author

vicb commented May 27, 2014

@pavelgj thanks for the review. I think @jbdeboer had an issue with the former version of this PR, let's make he can review & try this before it gets merged.

@vicb vicb added this to the 0.14.0 milestone Jun 25, 2014
@@ -54,7 +54,7 @@ part of angular.routing;
@Decorator(
selector: 'ng-view',
module: NgView.module,
visibility: Directive.CHILDREN_VISIBILITY)
children: Directive.TRANSCLUDE_CHILDREN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will not work. :-( The issue is that ng-view's are nestable and so they need ChildrenVisibility, otherwise nested routes do not work. The new DirectiveInjector makes it not possible to inject Transcluded controllers. We can change the behavior, but that is the current status. Can we talk about it.

I feel like ngView should be transcluding so that it can properly handle animation, and it is what we do in AngularJS. (https://github.com/angular/angular.js/blob/master/src/ngRoute/directive/ngView.js#L188)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PING, can you address this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this on my todo list, will look at it tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The visibility has been removed because children visibility is the default value (Visibility.CHILDREN).

What kind of tests need to be added ? (We already have tests for nested ng-view.)

@rkirov rkirov modified the milestones: 0.14.0, 0.15.0 Aug 22, 2014
@jbdeboer
Copy link
Contributor

@vicb "tomorrow" was a long time ago! Status?

@vicb
Copy link
Contributor Author

vicb commented Aug 25, 2014

needs work. delayed by higher priority tasks

@chirayuk chirayuk force-pushed the master branch 2 times, most recently from 8fd235c to 50e2645 Compare September 5, 2014 23:10
@vicb
Copy link
Contributor Author

vicb commented Sep 17, 2014

@mhevery I want to tackle this long running PR. Could you please answer the question about the tests, I'll push an updated version after that (with the scope removal issue fixed)

@vicb vicb removed this from the 0.15.0 milestone Sep 22, 2014
@vicb vicb mentioned this pull request Sep 23, 2014
@vicb vicb closed this Sep 23, 2014
mhevery referenced this pull request in vicb/angular.dart Sep 24, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

5 participants