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

Commit

Permalink
fix(NgAttachAware): revert to original behavior and define stronger test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Jan 31, 2014
1 parent f0e796d commit 500446d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/core_dom/block_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class BlockFactory {
var removeWatcher;
removeWatcher = scope.$watch(() {
removeWatcher();
scope.$evalAsync(() => controller.attach());
controller.attach();
});
}
if (controller is NgDetachAware) {
Expand Down
22 changes: 15 additions & 7 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,21 +423,25 @@ main() => describe('dte.compiler', () {
it('should fire onTemplate method', async(inject((Logger logger, MockHttpBackend backend) {
backend.whenGET('some/template.url').respond('<div>WORKED</div>');
var scope = $rootScope.$new();
var element = $('<attach-detach value="{{\'ready\'}}"></attach-detach>');
scope['isReady'] = 'ready';
scope['logger'] = logger;
var element = $('<attach-detach attr-value="{{isReady}}" expr-value="isReady">{{logger("inner")}}</attach-detach>');
$compile(element)(injector.createChild([new Module()..value(Scope, scope)]), element);
expect(logger).toEqual(['new']);

expect(logger).toEqual(['new']);

$rootScope.$digest();
expect(logger).toEqual(['new', 'attach:ready']);
expect(logger).toEqual(['new', 'attach:@ready; =>ready', 'inner']);
logger.clear();

backend.flush();
microLeap();
expect(logger).toEqual(['new', 'attach:ready', 'templateLoaded', scope.shadowRoot]);
expect(logger).toEqual(['templateLoaded', scope.shadowRoot]);
logger.clear();

scope.$destroy();
expect(logger).toEqual(['new', 'attach:ready', 'templateLoaded', scope.shadowRoot, 'detach']);
expect(logger).toEqual(['detach']);
expect(element.textWithShadow()).toEqual('WORKED');
})));
});
Expand Down Expand Up @@ -714,19 +718,23 @@ class LogComponent {
@NgComponent(
selector: 'attach-detach',
templateUrl: 'some/template.url',
map: const { 'value': '@value' }
map: const {
'attr-value': '@attrValue',
'expr-value': '<=>exprValue'
}
)
class AttachDetachComponent implements NgAttachAware, NgDetachAware, NgShadowRootAware {
Logger logger;
Scope scope;
String value = 'too early';
String attrValue = 'too early';
String exprValue = 'too early';

AttachDetachComponent(Logger this.logger, TemplateLoader templateLoader, Scope this.scope) {
logger('new');
templateLoader.template.then((_) => logger('templateLoaded'));
}

attach() => logger('attach:$value');
attach() => logger('attach:@$attrValue; =>$exprValue');
detach() => logger('detach');
onShadowRoot(shadowRoot) {
scope.$root.shadowRoot = shadowRoot;
Expand Down

0 comments on commit 500446d

Please sign in to comment.