From ceb4dbc927111d146903ef5b5dcf77a5db808485 Mon Sep 17 00:00:00 2001 From: Elliott Sprehn Date: Mon, 5 Jan 2015 12:54:43 -0800 Subject: [PATCH] Fix detached callback and add isAttached to SkyElements. There was a typo in the name of the detached callback which is now fixed, and also allow querying if an element is attached. R=rafaelw@chromium.org Review URL: https://codereview.chromium.org/806133003 --- framework/sky-element/sky-element.sky | 9 ++++++--- tests/framework/templates-expected.txt | 13 +++++++------ tests/framework/templates.sky | 8 ++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/framework/sky-element/sky-element.sky b/framework/sky-element/sky-element.sky index d34ce56b9a8..a6202df2763 100644 --- a/framework/sky-element/sky-element.sky +++ b/framework/sky-element/sky-element.sky @@ -36,7 +36,7 @@ class SkyElement extends HTMLElement { // override } - dettached() { + detached() { // override } @@ -49,6 +49,7 @@ class SkyElement extends HTMLElement { } createdCallback() { + this.isAttached = false; this.created(); } @@ -63,10 +64,12 @@ class SkyElement extends HTMLElement { } } this.attached(); + this.isAttached = true; } - dettachedCallback() { - this.dettached(); + detachedCallback() { + this.detached(); + this.isAttached = false; } attributeChangedCallback(attrName, oldValue, newValue) { diff --git a/tests/framework/templates-expected.txt b/tests/framework/templates-expected.txt index efc7b2a4b14..60617912a02 100644 --- a/tests/framework/templates-expected.txt +++ b/tests/framework/templates-expected.txt @@ -1,8 +1,9 @@ -Running 4 tests +Running 5 tests ok 1 SkyElement templates should stamp when the element is inserted -ok 2 SkyElement templates should connect data binding -ok 3 SkyElement templates should connect event handlers -ok 4 SkyElement templates should call shadowRootReady after creating the template instance -4 tests -4 pass +ok 2 SkyElement templates should update isAttached when inserting +ok 3 SkyElement templates should connect data binding +ok 4 SkyElement templates should connect event handlers +ok 5 SkyElement templates should call shadowRootReady after creating the template instance +5 tests +5 pass 0 fail diff --git a/tests/framework/templates.sky b/tests/framework/templates.sky index 30e119fc412..040a9e41ab1 100644 --- a/tests/framework/templates.sky +++ b/tests/framework/templates.sky @@ -24,6 +24,14 @@ describe("SkyElement templates", function() { assert.ok(element.shadowRoot.getElementById("inside")); }); + it("should update isAttached when inserting", function() { + assert.isFalse(element.isAttached); + sandbox.appendChild(element); + assert.isTrue(element.isAttached); + element.remove(); + assert.isFalse(element.isAttached); + }); + it("should connect data binding", function(done) { sandbox.appendChild(element); var inside = element.shadowRoot.getElementById("inside");