Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf(ngStyleDirective): use $watchCollection #15947

Merged
merged 2 commits into from
Jul 27, 2017

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Apr 28, 2017

This re-commits 4c8d8ad which was reverted (with tests added). This is possible now because of 189461f, although note that change is currently causing #15905 so maybe we should hold off on merging this one for now?

FYI @gdi2290

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

1 similar comment
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@gkalpak
Copy link
Member

gkalpak commented Apr 28, 2017

👍 for waiting until #15905 is resolved.

@Narretz
Copy link
Contributor

Narretz commented May 4, 2017

Interestingly, there's no test for normal literal bindings:

  it('should support binding for object literals', inject(function($rootScope, $compile) {
    element = $compile('<div ng-style="{height: heightStr}"></div>')($rootScope);
    $rootScope.$digest();
    expect(parseInt(element.css('height') + 0, 10)).toEqual(0); // height could be '' or '0px'
    $rootScope.$apply('heightStr = "40px"');
    expect(element.css('height')).toBe('40px');

    $rootScope.$apply('heightStr = "100px"');
    expect(element.css('height')).toBe('100px');
  }));

@jbedard jbedard modified the milestones: 1.7.0, 1.6.x May 5, 2017
@jbedard
Copy link
Collaborator Author

jbedard commented May 5, 2017

@Narretz I've added a commit with that test. Also changed to 1.7 because this depends on 189461f which is going to be reverted in 1.6 (#15958).

@jbedard jbedard force-pushed the style-watch-collection branch 4 times, most recently from 29e6e9a to 4340662 Compare May 27, 2017 20:45
@jbedard
Copy link
Collaborator Author

jbedard commented Jul 17, 2017

I think this can go into 1.7 now @gkalpak?

@jbedard
Copy link
Collaborator Author

jbedard commented Jul 17, 2017

Note: this will break cases where people are relying on a value being an object and automatically invoking .toString() such as {color: obj} where obj.toString() is stateful. This can be fixed by changing the expression to {color: obj.toString()}. Should add a breaking change notice for this.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

As discussed "offline", this is good-to-go for 1.7 (with the breaking change notice) 👍

@jbedard jbedard force-pushed the style-watch-collection branch from 8184f1d to a41cacf Compare July 22, 2017 04:12
jbedard pushed a commit to jbedard/angular.js that referenced this pull request Jul 22, 2017
Since we are simply watching a flat object collection it is more performant
to use $watchCollection than a deepWatch...

BREAKING CHANGE:

Previously the use of deep watch by ng-style would trigger styles to be
re-applied when nested state changed. Now only changes to direct
properties of the watched object will trigger changes.

Closes angular#15947
@jbedard
Copy link
Collaborator Author

jbedard commented Jul 22, 2017

I've updated the commit message with a "BREAKING CHANGE" message and changed the "Closes #" to this PR. Look good?

@jbedard jbedard force-pushed the style-watch-collection branch from a41cacf to b5b798b Compare July 22, 2017 04:54
@Narretz
Copy link
Contributor

Narretz commented Jul 24, 2017

Should there be a test for the case that is described in the BC notice?

@jbedard
Copy link
Collaborator Author

jbedard commented Jul 24, 2017

A test verifying that styles don't get re-applied when an object sub-property changes? Could...

@Narretz
Copy link
Contributor

Narretz commented Jul 24, 2017

Just because we are setting an expectation for this behavior

@jbedard
Copy link
Collaborator Author

jbedard commented Jul 26, 2017

I've added a test. The other option is verifying that ng-style="x" invokes $watchCollection(x)...?

@Narretz
Copy link
Contributor

Narretz commented Jul 26, 2017

LGTM

Since we are simply watching a flat object collection it is more performant
to use $watchCollection than a deepWatch...

BREAKING CHANGE:

Previously the use of deep watch by ng-style would trigger styles to be
re-applied when nested state changed. Now only changes to direct
properties of the watched object will trigger changes.

Closes angular#15947
@jbedard jbedard force-pushed the style-watch-collection branch from c25ee8d to 3acfe2c Compare July 27, 2017 03:10
@jbedard jbedard force-pushed the style-watch-collection branch from 3acfe2c to f736f94 Compare July 27, 2017 03:40
@jbedard jbedard merged commit ac57a25 into angular:master Jul 27, 2017
jbedard pushed a commit that referenced this pull request Jul 27, 2017
Since we are simply watching a flat object collection it is more performant
to use $watchCollection than a deepWatch...

BREAKING CHANGE:

Previously the use of deep watch by ng-style would trigger styles to be
re-applied when nested state changed. Now only changes to direct
properties of the watched object will trigger changes.

Closes #15947
@PatrickJS
Copy link
Contributor

nice

@gkalpak
Copy link
Member

gkalpak commented Jul 28, 2017

A tiny change with potentially big gains 😃
(It also took some serious poking around the $parse service - kudos to @jbedard 💯)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants