Skip to content

Commit

Permalink
fix(element binder): Ensure mappings are evaluated before attach() is
Browse files Browse the repository at this point in the history
called.

Closes dart-archive#1059
  • Loading branch information
jbdeboer authored and Diana Salsbury committed Jul 16, 2014
1 parent a805f9b commit 873d286
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ class _TaskList {
Function onDone;
final List _tasks = [];
bool isDone = false;
int firstTask;

_TaskList(this.onDone) {
if (onDone == null) isDone = true;
firstTask = registerTask();
}

int registerTask() {
Expand All @@ -374,7 +376,7 @@ class _TaskList {
}

void doneRegistering() {
completeTask(registerTask());
completeTask(firstTask);
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void main() {
describe('components', () {
beforeEachModule((Module module) {
module
..bind(AttachWithAttr)
..bind(CamelCaseMapComponent)
..bind(IoComponent)
..bind(IoControllerComponent)
Expand Down Expand Up @@ -654,6 +655,15 @@ void main() {
expect(logger).toEqual(['SimpleAttachComponent']);
}));

it('should call attach after mappings have been set', async((Logger logger) {
_.compile('<attach-with-attr attr="a" oneway="1+1"></attach-with-attr>');

_.rootScope.apply();
microLeap();

expect(logger).toEqual(['attr', 'oneway', 'attach']);
}));

it('should inject compenent element as the dom.Element', async((Logger log, TestBed _, MockHttpBackend backend) {
backend.whenGET('base/test/core_dom/foo.html').respond('<div>WORKED</div>');
_.compile('<log-element></log-element>');
Expand Down Expand Up @@ -1205,6 +1215,19 @@ class SimpleAttachComponent implements AttachAware, ShadowRootAware {
onShadowRoot(_) => logger('onShadowRoot');
}

@Decorator(
selector: 'attach-with-attr'
)
class AttachWithAttr implements AttachAware {
Logger logger;
AttachWithAttr(this.logger);
attach() => logger('attach');
@NgAttr('attr')
set attr(v) => logger('attr');
@NgOneWay('oneway')
set oneway(v) => logger('oneway');
}

@Component(
selector: 'log-element',
templateUrl: 'foo.html')
Expand Down

0 comments on commit 873d286

Please sign in to comment.