get custom elements working etc

pull/1359/head
Rich Harris 8 years ago
parent f4e327ea52
commit b606dd62bb

@ -133,17 +133,6 @@ export default function dom(
? 'svelte/shared.js'
: options.shared || '';
let prototypeBase = `${name}.prototype`;
const proto = sharedPath
? `@Component.prototype`
: deindent`
{
${['destroy', 'get', 'fire', 'on', 'set', '_set', '_mount', '_unmount', '_differs']
.map(n => `${n}: @${n}`)
.join(',\n')}
}`;
const debugName = `<${generator.customElement ? generator.tag : name}>`;
// generate initial state object
@ -172,8 +161,6 @@ export default function dom(
const constructorBody = deindent`
${options.dev && `this._debugName = '${debugName}';`}
${options.dev && !generator.customElement &&
`if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`}
${templateProperties.store && `this.store = %store();`}
${generator.usesRefs && `this.refs = {};`}
this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)};
@ -280,6 +267,8 @@ export default function dom(
class ${name} extends HTMLElement {
constructor(options = {}) {
super();
this._handlers = {};
this._init.call(this, options);
${constructorBody}
}
@ -319,8 +308,16 @@ export default function dom(
`}
}
customElements.define("${generator.tag}", ${name});
@assign(@assign(${prototypeBase}, ${proto}), {
Object.getOwnPropertyNames(${generator.options.dev ? `Object.getPrototypeOf(@Component.prototype)` : `@Component.prototype`}).forEach(name => {
${name}.prototype[name] = @Component.prototype[name];
});
@assign(${name}.prototype, {
fire: @Base.prototype.fire,
get: @Base.prototype.get,
on: @Base.prototype.on,
_differs: @Base.prototype._differs,
_mount(target, anchor) {
target.insertBefore(this, anchor);
},
@ -329,6 +326,8 @@ export default function dom(
this.parentNode.removeChild(this);
}
});
customElements.define("${generator.tag}", ${name});
`);
} else {
// TODO put methods in class body

@ -54,11 +54,7 @@ export class Base {
export class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -81,6 +77,14 @@ export class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};
@ -115,6 +119,14 @@ export class Component extends Base {
}
export class ComponentDev extends Component {
constructor(options) {
if (!options || (!options.target && !options.root)) {
throw new Error(`'target' is a required option`);
}
super(options);
}
destroy(detach) {
super.destroy(detach);
this.destroy = () => {

@ -23,6 +23,10 @@ describe('custom-elements', function() {
console[type](...args);
});
nightmare.on('page', (type, message, stack) => {
console.error(stack);
});
let svelte;
let server;
let bundle;

@ -65,11 +65,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -92,6 +88,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -65,11 +65,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -92,6 +88,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};
@ -162,6 +166,8 @@ function create_main_fragment(component, state) {
class SvelteComponent extends HTMLElement {
constructor(options = {}) {
super();
this._handlers = {};
this._init.call(this, options);
this._state = assign({}, options.data);
this.attachShadow({ mode: 'open' });
@ -184,8 +190,16 @@ class SvelteComponent extends HTMLElement {
}
}
customElements.define("custom-element", SvelteComponent);
assign(assign(SvelteComponent.prototype, Component.prototype), {
Object.getOwnPropertyNames(Component.prototype).forEach(name => {
SvelteComponent.prototype[name] = Component.prototype[name];
});
assign(SvelteComponent.prototype, {
fire: Base.prototype.fire,
get: Base.prototype.get,
on: Base.prototype.on,
_differs: Base.prototype._differs,
_mount(target, anchor) {
target.insertBefore(this, anchor);
},
@ -195,4 +209,6 @@ assign(assign(SvelteComponent.prototype, Component.prototype), {
}
});
customElements.define("custom-element", SvelteComponent);
export default SvelteComponent;

@ -1,5 +1,5 @@
/* generated by Svelte vX.Y.Z */
import { Component, assign, createElement, detachNode, insertNode, noop } from "svelte/shared.js";
import { Base, Component, assign, createElement, detachNode, insertNode, noop } from "svelte/shared.js";
function create_main_fragment(component, state) {
var div;
@ -28,6 +28,8 @@ function create_main_fragment(component, state) {
class SvelteComponent extends HTMLElement {
constructor(options = {}) {
super();
this._handlers = {};
this._init.call(this, options);
this._state = assign({}, options.data);
this.attachShadow({ mode: 'open' });
@ -50,8 +52,16 @@ class SvelteComponent extends HTMLElement {
}
}
customElements.define("custom-element", SvelteComponent);
assign(assign(SvelteComponent.prototype, Component.prototype), {
Object.getOwnPropertyNames(Component.prototype).forEach(name => {
SvelteComponent.prototype[name] = Component.prototype[name];
});
assign(SvelteComponent.prototype, {
fire: Base.prototype.fire,
get: Base.prototype.get,
on: Base.prototype.on,
_differs: Base.prototype._differs,
_mount(target, anchor) {
target.insertBefore(this, anchor);
},
@ -60,4 +70,6 @@ assign(assign(SvelteComponent.prototype, Component.prototype), {
this.parentNode.removeChild(this);
}
});
customElements.define("custom-element", SvelteComponent);
export default SvelteComponent;

@ -83,11 +83,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -110,6 +106,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};
@ -134,6 +138,14 @@ class Component extends Base {
}
class ComponentDev extends Component {
constructor(options) {
if (!options || (!options.target && !options.root)) {
throw new Error(`'target' is a required option`);
}
super(options);
}
destroy(detach) {
super.destroy(detach);
this.destroy = () => {
@ -205,7 +217,6 @@ class SvelteComponent extends ComponentDev {
constructor(options) {
super(options);
this._debugName = '<SvelteComponent>';
if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
this._state = assign({ Math : Math }, options.data);
this._recompute({ foo: 1 }, this._state);
if (!('foo' in this._state)) console.warn("<SvelteComponent> was created without expected data property 'foo'");

@ -45,7 +45,6 @@ class SvelteComponent extends ComponentDev {
constructor(options) {
super(options);
this._debugName = '<SvelteComponent>';
if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");
this._state = assign({ Math : Math }, options.data);
this._recompute({ foo: 1 }, this._state);
if (!('foo' in this._state)) console.warn("<SvelteComponent> was created without expected data property 'foo'");

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -85,11 +85,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -112,6 +108,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -65,11 +65,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -92,6 +88,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -65,11 +65,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -92,6 +88,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -69,11 +69,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -96,6 +92,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -77,11 +77,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -104,6 +100,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -71,11 +71,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -98,6 +94,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -81,11 +81,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -108,6 +104,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -67,11 +67,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -94,6 +90,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -53,11 +53,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -80,6 +76,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -77,11 +77,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -104,6 +100,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

@ -73,11 +73,7 @@ class Base {
class Component extends Base {
constructor(options) {
super();
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
this._init(options);
}
destroy(detach) {
@ -100,6 +96,14 @@ class Component extends Base {
this.root._lock = false;
}
_init(options) {
this._bind = options._bind;
this.options = options;
this.root = options.root || this;
this.store = this.root.store || options.store;
}
_set(newState) {
const previous = this._state;
const changed = {};

Loading…
Cancel
Save