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 load template or call onShadowRoot whe…
Browse files Browse the repository at this point in the history
…n scope is destroyed
  • Loading branch information
pavelgj authored and mhevery committed Feb 21, 2014
1 parent 72708e3 commit 2e40350
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/core_dom/block_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,19 @@ class _ComponentFactory {
shadowDom.setInnerHtml('<style>${filteredCssList.join('')}</style>', treeSanitizer: treeSanitizer);
}
if (blockFuture != null) {
return blockFuture.then((BlockFactory blockFactory) => attachBlockToShadowDom(blockFactory));
return blockFuture.then((BlockFactory blockFactory) {
if (!shadowScope.isAttached) return shadowDom;
return attachBlockToShadowDom(blockFactory);
});
}
return shadowDom;
}));
controller = createShadowInjector(injector, templateLoader).get(type);
if (controller is NgShadowRootAware) {
templateLoader.template.then((controller as NgShadowRootAware).onShadowRoot);
templateLoader.template.then((_) {
if (!shadowScope.isAttached) return;
(controller as NgShadowRootAware).onShadowRoot(shadowDom);
});
}
return controller;
}
Expand Down
11 changes: 8 additions & 3 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,16 @@ main() => describe('dte.compiler', () {
expect(element.textWithShadow()).toEqual('WORKED');
})));

it('should should not call attach after scope is destroyed', async(inject((Logger logger) {
it('should should not call attach after scope is destroyed', async(inject((Logger logger, MockHttpBackend backend) {
backend.whenGET('foo.html').respond('<div>WORKED</div>');
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();
microLeap();

expect(logger).toEqual(['SimpleAttachComponent']);
})));
Expand Down Expand Up @@ -857,11 +859,14 @@ class ExprAttrComponent {
}
}

@NgComponent(selector: 'simple-attach')
class SimpleAttachComponent implements NgAttachAware {
@NgComponent(
selector: 'simple-attach',
templateUrl: 'foo.html')
class SimpleAttachComponent implements NgAttachAware, NgShadowRootAware {
Logger logger;
SimpleAttachComponent(this.logger) {
logger('SimpleAttachComponent');
}
attach() => logger('attach');
onShadowRoot(_) => logger('onShadowRoot');
}

0 comments on commit 2e40350

Please sign in to comment.