fix(query): clean-up queryref during dehydration

The QueryRef objects persists during dehydration but needs to be
cleaned-up by removing callbacks and previous elements.

Closes #3944

Closes #3948
This commit is contained in:
Rado Kirov
2015-09-01 16:18:45 -07:00
committed by Rado Kirov
parent 44a991e245
commit 01cdd31339
5 changed files with 75 additions and 13 deletions

View File

@ -212,6 +212,34 @@ export function main() {
view.detectChanges();
});
}));
it('should correctly clean-up when destroyed together with the directives it is querying',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
var template =
'<needs-query #q *ng-if="shouldShow"><div text="foo"></div></needs-query>';
tcb.overrideTemplate(MyComp, template)
.createAsync(MyComp)
.then((view) => {
view.componentInstance.shouldShow = true;
view.detectChanges();
var q: NeedsQuery = view.componentViewChildren[1].getLocal('q');
expect(q.query.length).toEqual(1);
view.componentInstance.shouldShow = false;
view.detectChanges();
view.componentInstance.shouldShow = true;
view.detectChanges();
var q2: NeedsQuery = view.componentViewChildren[1].getLocal('q');
expect(q2.query.length).toEqual(1);
async.done();
});
}));
});
describe("querying by var binding", () => {

View File

@ -92,6 +92,19 @@ export function main() {
queryList.fireCallbacks();
expect(fires).toEqual(1);
});
it('should support removing all callbacks', () => {
var fires = 0;
var callback = () => fires += 1;
queryList.onChange(callback);
queryList.add('one');
queryList.removeAllCallbacks();
queryList.fireCallbacks();
expect(fires).toEqual(0);
});
});
});
}