diff --git a/test/js/samples/custom-element-basic/expected-bundle.js b/test/js/samples/custom-element-basic/expected-bundle.js index aff7954c60..f234f6dca8 100644 --- a/test/js/samples/custom-element-basic/expected-bundle.js +++ b/test/js/samples/custom-element-basic/expected-bundle.js @@ -162,23 +162,31 @@ var proto = { }; function create_main_fragment ( state, component ) { - var div, text; + var h1, text, text_1, text_2; return { create: function () { - div = createElement( 'div' ); - text = createText( "I am shadow DOM" ); + h1 = createElement( 'h1' ); + text = createText( "Hello " ); + text_1 = createText( state.name ); + text_2 = createText( "!" ); }, mount: function ( target, anchor ) { - insertNode( div, target, anchor ); - appendNode( text, div ); + insertNode( h1, target, anchor ); + appendNode( text, h1 ); + appendNode( text_1, h1 ); + appendNode( text_2, h1 ); }, - update: noop, + update: function ( changed, state ) { + if ( changed.name ) { + text_1.data = state.name; + } + }, unmount: function () { - detachNode( div ); + detachNode( h1 ); }, destroy: noop @@ -209,6 +217,22 @@ class SvelteComponent extends HTMLElement { this._fragment.mount( this.attachShadow({ mode: 'open' }), null ); } } + + static get observedAttributes() { + return ["name"]; + } + + get name() { + return this.get('name'); + } + + set name(value) { + this.set({ name: value }); + } + + attributeChangedCallback ( attr, oldValue, newValue ) { + this.set({ [attr]: newValue }); + } } customElements.define('custom-element', SvelteComponent); diff --git a/test/js/samples/custom-element-basic/expected.js b/test/js/samples/custom-element-basic/expected.js index 50023bb4ec..1e1b8deac0 100644 --- a/test/js/samples/custom-element-basic/expected.js +++ b/test/js/samples/custom-element-basic/expected.js @@ -1,23 +1,31 @@ import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment ( state, component ) { - var div, text; + var h1, text, text_1, text_2; return { create: function () { - div = createElement( 'div' ); - text = createText( "I am shadow DOM" ); + h1 = createElement( 'h1' ); + text = createText( "Hello " ); + text_1 = createText( state.name ); + text_2 = createText( "!" ); }, mount: function ( target, anchor ) { - insertNode( div, target, anchor ); - appendNode( text, div ); + insertNode( h1, target, anchor ); + appendNode( text, h1 ); + appendNode( text_1, h1 ); + appendNode( text_2, h1 ); }, - update: noop, + update: function ( changed, state ) { + if ( changed.name ) { + text_1.data = state.name; + } + }, unmount: function () { - detachNode( div ); + detachNode( h1 ); }, destroy: noop @@ -48,6 +56,22 @@ class SvelteComponent extends HTMLElement { this._fragment.mount( this.attachShadow({ mode: 'open' }), null ); } } + + static get observedAttributes() { + return ["name"]; + } + + get name() { + return this.get('name'); + } + + set name(value) { + this.set({ name: value }); + } + + attributeChangedCallback ( attr, oldValue, newValue ) { + this.set({ [attr]: newValue }); + } } customElements.define('custom-element', SvelteComponent); diff --git a/test/js/samples/custom-element-basic/input.html b/test/js/samples/custom-element-basic/input.html index 3e00e7121f..6cc7a9e7af 100644 --- a/test/js/samples/custom-element-basic/input.html +++ b/test/js/samples/custom-element-basic/input.html @@ -1,4 +1,4 @@ -
I am shadow DOM
+

Hello {{name}}!

\ No newline at end of file