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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | sky/tests/framework/templates.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="TemplateBinding.sky" /> 6 <import src="TemplateBinding.sky" />
7 <script> 7 <script>
8 var templates = new Map(); 8 var templates = new Map();
9 9
10 var kInternal = Symbol("SkyElementInternal");
rafaelw 2014/12/19 23:22:56 nit: let's not use this kind of naming. How about
11
12 class Internal {
13 constructor() {
14 this.appendedTemplate = false;
15 this.isAttached = false;
16 }
17 };
18
10 class SkyElement extends HTMLElement { 19 class SkyElement extends HTMLElement {
11 20
12 static register() { 21 static register() {
13 var wrapper = document.currentScript.parentNode; 22 var wrapper = document.currentScript.parentNode;
14 23
15 if (wrapper.localName !== 'sky-element') 24 if (wrapper.localName !== 'sky-element')
16 throw new Error('No <sky-element>.'); 25 throw new Error('No <sky-element>.');
17 26
18 var tagName = wrapper.getAttribute("name"); 27 var tagName = wrapper.getAttribute("name");
19 if (!tagName) 28 if (!tagName)
20 throw new Error('<sky-element> must have a name.'); 29 throw new Error('<sky-element> must have a name.');
21 30
22 var template = wrapper.querySelector('template'); 31 var template = wrapper.querySelector('template');
23 if (template) 32 if (template)
24 templates.set(tagName, template); 33 templates.set(tagName, template);
25 34
26 return document.registerElement(tagName, { 35 return document.registerElement(tagName, {
27 prototype: this.prototype, 36 prototype: this.prototype,
28 }); 37 });
29 } 38 }
30 39
31 created() { 40 created() {
32 // override 41 // override
33 } 42 }
34 43
35 attached() { 44 attached() {
36 // override 45 // override
37 } 46 }
38 47
39 dettached() { 48 detached() {
40 // override 49 // override
41 } 50 }
42 51
43 attributeChanged(attrName, oldValue, newValue) { 52 attributeChanged(attrName, oldValue, newValue) {
44 // override 53 // override
45 } 54 }
46 55
47 shadowRootReady() { 56 shadowRootReady() {
48 // override 57 // override
49 } 58 }
50 59
51 createdCallback() { 60 createdCallback() {
61 this[kInternal] = new Internal();
52 this.created(); 62 this.created();
53 } 63 }
54 64
65 get isAttached() {
66 return this[kInternal].isAttached;
67 }
68
55 attachedCallback() { 69 attachedCallback() {
56 if (!this.shadowRoot) { 70 var internal = this[kInternal];
71
72 if (!internal.appendedTemplate) {
57 var template = templates.get(this.localName); 73 var template = templates.get(this.localName);
58 if (template) { 74 if (template) {
59 var shadow = this.ensureShadowRoot(); 75 var shadow = this.ensureShadowRoot();
60 shadow.appendChild(template.createInstance(this)); 76 shadow.appendChild(template.createInstance(this));
61 this.shadowRootReady(); 77 this.shadowRootReady();
78 internal.appendedTemplate = true;
62 } 79 }
63 } 80 }
81
64 this.attached(); 82 this.attached();
83 internal.isAttached = true;
65 } 84 }
66 85
67 dettachedCallback() { 86 detachedCallback() {
68 this.dettached(); 87 this.detached();
88 this[kInternal].isAttached = false;
69 } 89 }
70 90
71 attributeChangedCallback(attrName, oldValue, newValue) { 91 attributeChangedCallback(attrName, oldValue, newValue) {
72 // reserved for canonical behavior 92 // reserved for canonical behavior
73 this.attributeChanged(attrName, oldValue, newValue); 93 this.attributeChanged(attrName, oldValue, newValue);
74 } 94 }
75 }; 95 };
76 96
77 module.exports = SkyElement; 97 module.exports = SkyElement;
78 </script> 98 </script>
OLDNEW
« 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