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

Commit 4933a5e

Browse files
committed
fix(view): change ViewPort to remove the view that got inserted in the same VM turn
See issue #1630
1 parent 9295a92 commit 4933a5e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/core_dom/view.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,25 @@ class ViewPort {
8282
/// The associated scope is destroyed immediately.
8383
View remove(View view) {
8484
view.scope.destroy();
85+
86+
// The view removal is sync, and the corresponding DOM operation is async.
8587
views.remove(view);
8688
scope.rootScope.domWrite(() {
89+
90+
/**
91+
* We have to call `views.remove` one more time to handle the case when a view gets
92+
* inserted and removed in the VM turn.
93+
*
94+
* viewPort.insert(a);
95+
* viewPort.remove(a);
96+
*
97+
* Another option of making the view insertion synchronous does not work because of:
98+
* https://github.com/angular/angular.dart/issues/1630
99+
*
100+
* Remove this once Issue 1630 is fixed.
101+
*/
102+
views.remove(view);
103+
87104
_animate.remove(view.nodes);
88105
_notifyLightDom();
89106
});

test/core_dom/view_spec.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,29 @@ main() {
131131

132132

133133
describe('remove', () {
134-
beforeEach((RootScope scope) {
134+
it("should remove newly added view", (RootScope scope) {
135135
viewPort.insert(a);
136-
viewPort.insert(b, insertAfter: a);
136+
viewPort.remove(a);
137137
scope.flush();
138138

139-
expect(rootElement.text).toEqual('AaBb');
139+
expect(viewPort.views).toEqual([]);
140140
});
141141

142142
it('should remove the last view', (RootScope scope) {
143+
viewPort.insert(a);
144+
viewPort.insert(b, insertAfter: a);
145+
scope.flush();
146+
143147
viewPort.remove(b);
144148
scope.flush();
145149
expect(rootElement).toHaveHtml('<!-- anchor --><span>A</span>a');
146150
});
147151

148152
it('should remove child views from parent pseudo black', (RootScope scope) {
153+
viewPort.insert(a);
154+
viewPort.insert(b, insertAfter: a);
155+
scope.flush();
156+
149157
viewPort.remove(a);
150158
scope.flush();
151159
expect(rootElement).toHaveHtml('<!-- anchor --><span>B</span>b');

0 commit comments

Comments
 (0)