From 29fc3e51692e0a5043d7cd4a14b4350700121f59 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 2 Sep 2017 17:22:28 -0400 Subject: [PATCH] update tests --- .../custom-element-basic/expected-bundle.js | 38 ++- .../samples/custom-element-basic/expected.js | 38 ++- .../samples/custom-element-basic/input.html | 2 +- .../js/samples/custom-element-slot/_config.js | 5 + .../custom-element-slot/expected-bundle.js | 249 ++++++++++++++++++ .../samples/custom-element-slot/expected.js | 84 ++++++ .../js/samples/custom-element-slot/input.html | 15 ++ 7 files changed, 416 insertions(+), 15 deletions(-) create mode 100644 test/js/samples/custom-element-slot/_config.js create mode 100644 test/js/samples/custom-element-slot/expected-bundle.js create mode 100644 test/js/samples/custom-element-slot/expected.js create mode 100644 test/js/samples/custom-element-slot/input.html 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