|
|
@ -133,17 +133,6 @@ export default function dom(
|
|
|
|
? 'svelte/shared.js'
|
|
|
|
? 'svelte/shared.js'
|
|
|
|
: options.shared || '';
|
|
|
|
: 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}>`;
|
|
|
|
const debugName = `<${generator.customElement ? generator.tag : name}>`;
|
|
|
|
|
|
|
|
|
|
|
|
// generate initial state object
|
|
|
|
// generate initial state object
|
|
|
@ -172,8 +161,6 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
|
|
const constructorBody = deindent`
|
|
|
|
const constructorBody = deindent`
|
|
|
|
${options.dev && `this._debugName = '${debugName}';`}
|
|
|
|
${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();`}
|
|
|
|
${templateProperties.store && `this.store = %store();`}
|
|
|
|
${generator.usesRefs && `this.refs = {};`}
|
|
|
|
${generator.usesRefs && `this.refs = {};`}
|
|
|
|
this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)};
|
|
|
|
this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)};
|
|
|
@ -280,6 +267,8 @@ export default function dom(
|
|
|
|
class ${name} extends HTMLElement {
|
|
|
|
class ${name} extends HTMLElement {
|
|
|
|
constructor(options = {}) {
|
|
|
|
constructor(options = {}) {
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
|
|
|
|
this._handlers = {};
|
|
|
|
|
|
|
|
this._init.call(this, options);
|
|
|
|
${constructorBody}
|
|
|
|
${constructorBody}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -319,8 +308,16 @@ export default function dom(
|
|
|
|
`}
|
|
|
|
`}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
customElements.define("${generator.tag}", ${name});
|
|
|
|
Object.getOwnPropertyNames(${generator.options.dev ? `Object.getPrototypeOf(@Component.prototype)` : `@Component.prototype`}).forEach(name => {
|
|
|
|
@assign(@assign(${prototypeBase}, ${proto}), {
|
|
|
|
${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) {
|
|
|
|
_mount(target, anchor) {
|
|
|
|
target.insertBefore(this, anchor);
|
|
|
|
target.insertBefore(this, anchor);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -329,6 +326,8 @@ export default function dom(
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
customElements.define("${generator.tag}", ${name});
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO put methods in class body
|
|
|
|
// TODO put methods in class body
|
|
|
|