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

Commit fef0da0

Browse files
committed
fix(element binder): Ensure mappings are evaluated before attach() is
called. Closes #1059
1 parent 3ef9d8e commit fef0da0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: lib/core_dom/element_binder.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,11 @@ class _TaskList {
353353
Function onDone;
354354
final List _tasks = [];
355355
bool isDone = false;
356+
int firstTask;
356357

357358
_TaskList(this.onDone) {
358359
if (onDone == null) isDone = true;
360+
firstTask = registerTask();
359361
}
360362

361363
int registerTask() {
@@ -374,7 +376,7 @@ class _TaskList {
374376
}
375377

376378
void doneRegistering() {
377-
completeTask(registerTask());
379+
completeTask(firstTask);
378380
}
379381
}
380382

Diff for: test/core_dom/compiler_spec.dart

+23
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ void main() {
280280
describe('components', () {
281281
beforeEachModule((Module module) {
282282
module
283+
..bind(AttachWithAttr)
283284
..bind(CamelCaseMapComponent)
284285
..bind(IoComponent)
285286
..bind(IoControllerComponent)
@@ -654,6 +655,15 @@ void main() {
654655
expect(logger).toEqual(['SimpleAttachComponent']);
655656
}));
656657

658+
it('should call attach after mappings have been set', async((Logger logger) {
659+
_.compile('<attach-with-attr attr="a" oneway="1+1"></attach-with-attr>');
660+
661+
_.rootScope.apply();
662+
microLeap();
663+
664+
expect(logger).toEqual(['attr', 'oneway', 'attach']);
665+
}));
666+
657667
it('should inject compenent element as the dom.Element', async((Logger log, TestBed _, MockHttpBackend backend) {
658668
backend.whenGET('foo.html').respond('<div>WORKED</div>');
659669
_.compile('<log-element></log-element>');
@@ -1205,6 +1215,19 @@ class SimpleAttachComponent implements AttachAware, ShadowRootAware {
12051215
onShadowRoot(_) => logger('onShadowRoot');
12061216
}
12071217

1218+
@Decorator(
1219+
selector: 'attach-with-attr'
1220+
)
1221+
class AttachWithAttr implements AttachAware {
1222+
Logger logger;
1223+
AttachWithAttr(this.logger);
1224+
attach() => logger('attach');
1225+
@NgAttr('attr')
1226+
set attr(v) => logger('attr');
1227+
@NgOneWay('oneway')
1228+
set oneway(v) => logger('oneway');
1229+
}
1230+
12081231
@Component(
12091232
selector: 'log-element',
12101233
templateUrl: 'foo.html')

0 commit comments

Comments
 (0)