Merge pull request #1151 from sveltejs/gh-1117

in custom elements, call oncreate in connectedCallback
pull/1170/head
Rich Harris 7 years ago committed by GitHub
commit 173792fd90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -327,6 +327,16 @@ export default function dom(
attributeChangedCallback(attr, oldValue, newValue) {
this.set({ [attr]: newValue });
}
${(generator.hasComponents || generator.hasComplexBindings || templateProperties.oncreate || generator.hasIntroTransitions) && deindent`
connectedCallback() {
${generator.hasComponents && `this._lock = true;`}
${(generator.hasComponents || generator.hasComplexBindings) && `@callAll(this._beforecreate);`}
${(generator.hasComponents || templateProperties.oncreate) && `@callAll(this._oncreate);`}
${(generator.hasComponents || generator.hasIntroTransitions) && `@callAll(this._aftercreate);`}
${generator.hasComponents && `this._lock = false;`}
}
`}
}
customElements.define("${generator.tag}", ${name});

@ -1,3 +1,7 @@
export function equal(a, b, message) {
if (a != b) throw new Error(message || `Expected ${a} to equal ${b}`);
}
export function ok(condition, message) {
if (!condition) throw new Error(message || `Expected ${condition} to be truthy`);
}

@ -3,7 +3,7 @@ import * as http from 'http';
import { rollup } from 'rollup';
import virtual from 'rollup-plugin-virtual';
import Nightmare from 'nightmare';
import { loadSvelte, loadConfig } from "../helpers.js";
import { addLineNumbers, loadConfig, loadSvelte } from "../helpers.js";
const page = `
<body>
@ -96,6 +96,7 @@ describe('custom-elements', function() {
if (result) console.log(result);
})
.catch(message => {
console.log(addLineNumbers(bundle));
throw new Error(message);
});
});

@ -0,0 +1,9 @@
<script>
export default {
tag: 'my-app',
oncreate() {
this.wasCreated = true;
}
};
</script>

@ -0,0 +1,8 @@
import * as assert from 'assert';
import './main.html';
export default function (target) {
target.innerHTML = '<my-app/>';
const el = target.querySelector('my-app');
assert.ok(el.wasCreated);
}
Loading…
Cancel
Save