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

Commit

Permalink
fix(block_factory): should not call attach when scope is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj authored and mhevery committed Feb 21, 2014
1 parent 484f03d commit 72708e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/core_dom/block_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ class BlockFactory {
checkAttachReady() {
if (attachDelayStatus.reduce((a, b) => a && b)) {
attachDelayStatus = null;
controller.attach();
if (scope.isAttached) {
controller.attach();
}
}
}
for(var map in ref.mappings) {
Expand Down
21 changes: 21 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ main() => describe('dte.compiler', () {
module.type(PublishMeDirective);
module.type(LogComponent);
module.type(AttachDetachComponent);
module.type(SimpleAttachComponent);
module.type(SimpleComponent);
module.type(ExprAttrComponent);
module.type(SayHelloFilter);
Expand Down Expand Up @@ -482,6 +483,18 @@ main() => describe('dte.compiler', () {
expect(logger).toEqual(['detach']);
expect(element.textWithShadow()).toEqual('WORKED');
})));

it('should should not call attach after scope is destroyed', async(inject((Logger logger) {
var element = $('<simple-attach></simple-attach>');
var scope = rootScope.createChild({});
$compile(element, directives)(injector.createChild([new Module()..value(Scope, scope)]), element);
expect(logger).toEqual(['SimpleAttachComponent']);
scope.destroy();

rootScope.apply();

expect(logger).toEqual(['SimpleAttachComponent']);
})));
});

describe('invalid components', () {
Expand Down Expand Up @@ -844,3 +857,11 @@ class ExprAttrComponent {
}
}

@NgComponent(selector: 'simple-attach')
class SimpleAttachComponent implements NgAttachAware {
Logger logger;
SimpleAttachComponent(this.logger) {
logger('SimpleAttachComponent');
}
attach() => logger('attach');
}

0 comments on commit 72708e3

Please sign in to comment.