Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: sky/framework/sky-element/sky-element.sky

Issue 806133003: Fix detached callback and add isAttached to SkyElements. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: don't change shadow root test yet. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/tests/framework/templates.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/sky-element.sky
diff --git a/sky/framework/sky-element/sky-element.sky b/sky/framework/sky-element/sky-element.sky
index 19eb2535f905aa53982923d5f77c242638ccd5eb..63ed363a4d55b9a3d38383e9d4255d5281c3392b 100644
--- a/sky/framework/sky-element/sky-element.sky
+++ b/sky/framework/sky-element/sky-element.sky
@@ -7,6 +7,15 @@
<script>
var templates = new Map();
+var kInternal = Symbol("SkyElementInternal");
rafaelw 2014/12/19 23:22:56 nit: let's not use this kind of naming. How about
+
+class Internal {
+ constructor() {
+ this.appendedTemplate = false;
+ this.isAttached = false;
+ }
+};
+
class SkyElement extends HTMLElement {
static register() {
@@ -36,7 +45,7 @@ class SkyElement extends HTMLElement {
// override
}
- dettached() {
+ detached() {
// override
}
@@ -49,23 +58,34 @@ class SkyElement extends HTMLElement {
}
createdCallback() {
+ this[kInternal] = new Internal();
this.created();
}
+ get isAttached() {
+ return this[kInternal].isAttached;
+ }
+
attachedCallback() {
- if (!this.shadowRoot) {
+ var internal = this[kInternal];
+
+ if (!internal.appendedTemplate) {
var template = templates.get(this.localName);
if (template) {
var shadow = this.ensureShadowRoot();
shadow.appendChild(template.createInstance(this));
this.shadowRootReady();
+ internal.appendedTemplate = true;
}
}
+
this.attached();
+ internal.isAttached = true;
}
- dettachedCallback() {
- this.dettached();
+ detachedCallback() {
+ this.detached();
+ this[kInternal].isAttached = false;
}
attributeChangedCallback(attrName, oldValue, newValue) {
« no previous file with comments | « no previous file | sky/tests/framework/templates.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698