Skip to content

Commit

Permalink
Call deliver() from attachedCallback() rather than createdCallback().
Browse files Browse the repository at this point in the history
This is more efficient for programatically created widgets because it avoids
calling computeProperties() and refreshRendering() twice on initialization:
once with the default property values and once after user specified values have
been processed.

Refs #385, works around ibm-js/deliteful#535 and therefore fixes ibm-js/deliteful#532.
  • Loading branch information
wkeese committed Mar 27, 2015
1 parent 4377e7e commit bca1479
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions CustomElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ define([
attributes: true
});
}

if (this.deliver) {
this.deliver();
}
}
}),

Expand All @@ -241,6 +237,11 @@ define([
*/
attachedCallback: dcl.advise({
before: function () {
// Call computeProperties() and refreshRendering() for declaratively set properties.
// Do this in attachedCallback() rather than createdCallback() to avoid calling refreshRendering() etc.
// prematurely in the programmatic case (i.e. calling it before user parameters have been applied).
this.deliver();

this.attached = true;

// Protect against repeated calls.
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,19 +731,19 @@ define([
var cwpc = new ClassConstWidget({
className: "userDefinedClass"
});
assert.strictEqual(cwpc.className, "constClass myBaseClass userDefinedClass",
assert.strictEqual(cwpc.className, "constClass userDefinedClass myBaseClass",
"programmatic const");

// Test programmatic with class={{foo}}
var cwpv = new ClassVarWidget({
className: "userDefinedClass"
});
assert.strictEqual(cwpv.className, "myTemplateClass1 myBaseClass userDefinedClass",
assert.strictEqual(cwpv.className, "userDefinedClass myTemplateClass1 myBaseClass",
"programmatic var, before update");

cwpv.templateClass = "myTemplateClass2";
cwpv.deliver();
assert.strictEqual(cwpv.className, "myBaseClass userDefinedClass myTemplateClass2",
assert.strictEqual(cwpv.className, "userDefinedClass myBaseClass myTemplateClass2",
"programmatic var, after update");
},

Expand Down

0 comments on commit bca1479

Please sign in to comment.