0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Make passing options to component optional

This commit is contained in:
Fabrice Weinberg 2016-12-07 13:45:33 +01:00
parent ecf05ad36e
commit 65b10f6d5e
4 changed files with 13 additions and 0 deletions

View File

@ -433,6 +433,8 @@ export default function generate ( parsed, source, options, names ) {
topLevelStatements.push( deindent`
function ${constructorName} ( options ) {
options = options || {};
var component = this;${generator.usesRefs ? `\nthis.refs = {}` : ``}
var state = ${initialState};${templateProperties.computed ? `\napplyComputations( state, state, {} );` : ``}

View File

@ -0,0 +1,7 @@
export default {
html: '<h1>Just some static HTML</h1>',
test: function ( assert, component, target, window ) {
const newComp = new window.SvelteComponent();
assert.equal(newComp instanceof window.SvelteComponent, true);
}
};

View File

@ -0,0 +1 @@
<h1>Just some static HTML</h1>

View File

@ -279,6 +279,9 @@ describe( 'svelte', () => {
return env()
.then( window => {
// Put the constructor on window for testing
window.SvelteComponent = SvelteComponent;
const target = window.document.querySelector( 'main' );
const component = new SvelteComponent({