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

Commit 72708e3

Browse files
pavelgjmhevery
authored andcommitted
fix(block_factory): should not call attach when scope is destroyed
1 parent 484f03d commit 72708e3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/core_dom/block_factory.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class BlockFactory {
204204
checkAttachReady() {
205205
if (attachDelayStatus.reduce((a, b) => a && b)) {
206206
attachDelayStatus = null;
207-
controller.attach();
207+
if (scope.isAttached) {
208+
controller.attach();
209+
}
208210
}
209211
}
210212
for(var map in ref.mappings) {

test/core_dom/compiler_spec.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ main() => describe('dte.compiler', () {
176176
module.type(PublishMeDirective);
177177
module.type(LogComponent);
178178
module.type(AttachDetachComponent);
179+
module.type(SimpleAttachComponent);
179180
module.type(SimpleComponent);
180181
module.type(ExprAttrComponent);
181182
module.type(SayHelloFilter);
@@ -482,6 +483,18 @@ main() => describe('dte.compiler', () {
482483
expect(logger).toEqual(['detach']);
483484
expect(element.textWithShadow()).toEqual('WORKED');
484485
})));
486+
487+
it('should should not call attach after scope is destroyed', async(inject((Logger logger) {
488+
var element = $('<simple-attach></simple-attach>');
489+
var scope = rootScope.createChild({});
490+
$compile(element, directives)(injector.createChild([new Module()..value(Scope, scope)]), element);
491+
expect(logger).toEqual(['SimpleAttachComponent']);
492+
scope.destroy();
493+
494+
rootScope.apply();
495+
496+
expect(logger).toEqual(['SimpleAttachComponent']);
497+
})));
485498
});
486499

487500
describe('invalid components', () {
@@ -844,3 +857,11 @@ class ExprAttrComponent {
844857
}
845858
}
846859

860+
@NgComponent(selector: 'simple-attach')
861+
class SimpleAttachComponent implements NgAttachAware {
862+
Logger logger;
863+
SimpleAttachComponent(this.logger) {
864+
logger('SimpleAttachComponent');
865+
}
866+
attach() => logger('attach');
867+
}

0 commit comments

Comments
 (0)