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

Commit 2f18bb4

Browse files
kseamonjelbourn
authored andcommitted
fix(showHide): Don't set up $md-resize $broadcasting $watcher until recieving $md-resize-enable Fixes #5760
Closes #6170
1 parent 2ab3075 commit 2f18bb4

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

src/components/showHide/showHide.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ function createDirective(name, targetValue) {
1919
restrict: 'A',
2020
multiElement: true,
2121
link: function($scope, $element, $attr) {
22-
$scope.$watch($attr[name], function(value) {
23-
if (!!value === targetValue) {
24-
$mdUtil.nextTick(function() {
25-
$scope.$broadcast('$md-resize');
26-
});
27-
$mdUtil.dom.animator.waitTransitionEnd($element).then(function() {
28-
$scope.$broadcast('$md-resize');
29-
});
30-
}
22+
var unregister = $scope.$on('$md-resize-enable', function() {
23+
unregister();
24+
25+
$scope.$watch($attr[name], function(value) {
26+
if (!!value === targetValue) {
27+
$mdUtil.nextTick(function() {
28+
$scope.$broadcast('$md-resize');
29+
});
30+
$mdUtil.dom.animator.waitTransitionEnd($element).then(function() {
31+
$scope.$broadcast('$md-resize');
32+
});
33+
}
34+
});
3135
});
3236
}
3337
};

src/components/showHide/showHide.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('showHide', function() {
2222
it('should notify when the node unhides', function() {
2323
scope.hide = true;
2424
var element = $compile('<div ng-hide="hide"></div>')(scope);
25+
scope.$broadcast('$md-resize-enable');
2526
scope.$apply();
2627
expect(spy).not.toHaveBeenCalled();
2728

@@ -41,6 +42,7 @@ describe('showHide', function() {
4142
it('should not notify on hide', function() {
4243
scope.hide = true;
4344
var element = $compile('<div ng-hide="hide"></div>')(scope);
45+
scope.$broadcast('$md-resize-enable');
4446
scope.$apply();
4547

4648
// Expect no $broadcasts when hiding.
@@ -49,12 +51,30 @@ describe('showHide', function() {
4951
scope.$apply();
5052
expect(spy).not.toHaveBeenCalled();
5153
});
54+
55+
it('should not notify when not activated', function() {
56+
scope.hide = true;
57+
var element = $compile('<div ng-hide="hide"></div>')(scope);
58+
scope.$apply();
59+
expect(spy).not.toHaveBeenCalled();
60+
61+
scope.hide = false;
62+
scope.$apply();
63+
$timeout.flush();
64+
expect(spy).not.toHaveBeenCalled();
65+
66+
spy.calls.reset();
67+
defered.resolve();
68+
scope.$apply();
69+
expect(spy).not.toHaveBeenCalled();
70+
});
5271
});
5372

5473
describe('ng-show', function() {
5574
it('should notify when the node unhides', function() {
5675
scope.show = false;
5776
var element = $compile('<div ng-show="show"></div>')(scope);
77+
scope.$broadcast('$md-resize-enable');
5878
scope.$apply();
5979
expect(spy).not.toHaveBeenCalled();
6080

@@ -74,6 +94,7 @@ describe('showHide', function() {
7494
it('should not notify on hide', function() {
7595
scope.show = false;
7696
var element = $compile('<div ng-show="show"></div>')(scope);
97+
scope.$broadcast('$md-resize-enable');
7798
scope.$apply();
7899

79100
// Expect no $broadcasts when hiding.
@@ -82,5 +103,22 @@ describe('showHide', function() {
82103
scope.$apply();
83104
expect(spy).not.toHaveBeenCalled();
84105
});
106+
107+
it('should not notify when not activated', function() {
108+
scope.show = false;
109+
var element = $compile('<div ng-show="show"></div>')(scope);
110+
scope.$apply();
111+
expect(spy).not.toHaveBeenCalled();
112+
113+
scope.show = true;
114+
scope.$apply();
115+
$timeout.flush();
116+
expect(spy).not.toHaveBeenCalled();
117+
118+
spy.calls.reset();
119+
defered.resolve();
120+
scope.$apply();
121+
expect(spy).not.toHaveBeenCalled();
122+
});
85123
});
86124
});

src/components/virtualRepeat/virtual-repeater.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function VirtualRepeatContainerController(
150150
jWindow.off('resize', debouncedUpdateSize);
151151
});
152152

153+
$scope.$emit('$md-resize-enable');
153154
$scope.$on('$md-resize', boundUpdateSize);
154155
}));
155156
}

src/components/virtualRepeat/virtual-repeater.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ describe('<md-virtual-repeat>', function() {
7373
return component[0].querySelectorAll('[md-virtual-repeat]');
7474
}
7575

76+
it('should $emit $md-resize-enable at startup', function() {
77+
var emitted = false;
78+
scope.$on('$md-resize-enable', function() {
79+
emitted = true;
80+
});
81+
82+
createRepeater();
83+
84+
expect(emitted).toBe(true);
85+
});
86+
7687
it('should render only enough items to fill the viewport + 3 (vertical)', function() {
7788
createRepeater();
7889
scope.items = createItems(NUM_ITEMS);

0 commit comments

Comments
 (0)