@@ -304,44 +304,50 @@ export default function dom ( parsed, source, options, names ) {
304
304
` ) ;
305
305
}
306
306
307
- const stateBlock = new CodeBuilder ( ) ;
307
+ const constructorBlock = new CodeBuilder ( ) ;
308
308
309
- stateBlock . addLine (
309
+ constructorBlock . addLine ( `options = options || {};` ) ;
310
+ if ( generator . usesRefs ) constructorBlock . addLine ( `this.refs = {};` ) ;
311
+
312
+ constructorBlock . addLine (
310
313
`this._state = ${ templateProperties . data ? `Object.assign( template.data(), options.data )` : `options.data || {}` } ;`
311
314
) ;
312
315
313
316
if ( templateProperties . computed ) {
314
- stateBlock . addLine (
317
+ constructorBlock . addLine (
315
318
`applyComputations( this._state, this._state, {}, true );`
316
319
) ;
317
320
}
318
321
319
322
if ( options . dev ) {
320
323
Object . keys ( generator . expectedProperties ) . forEach ( prop => {
321
- stateBlock . addLine (
324
+ constructorBlock . addLine (
322
325
`if ( !( '${ prop } ' in this._state ) ) throw new Error( "Component was created without expected data property '${ prop } '" );`
323
326
) ;
324
327
} ) ;
325
- }
326
328
327
- builders . main . addBlock ( deindent `
328
- function ${ name } ( options ) {
329
- options = options || {} ;
330
- ${ generator . usesRefs ? `\nthis.refs = {}` : `` }
329
+ constructorBlock . addBlock (
330
+ `if ( ! options.target && !options._root ) throw new Error( "'target' is a required option" );`
331
+ ) ;
332
+ }
331
333
332
- ${ stateBlock }
334
+ constructorBlock . addBlock ( deindent `
335
+ this._observers = {
336
+ pre: Object.create( null ),
337
+ post: Object.create( null )
338
+ };
333
339
334
- this._observers = {
335
- pre: Object.create( null ),
336
- post: Object.create( null )
337
- };
340
+ this._handlers = Object.create( null );
338
341
339
- this._handlers = Object.create( null );
342
+ this._root = options._root;
343
+ this._yield = options._yield;
340
344
341
- this._root = options._root;
342
- this._yield = options._yield ;
345
+ ${ builders . init }
346
+ ` ) ;
343
347
344
- ${ builders . init }
348
+ builders . main . addBlock ( deindent `
349
+ function ${ name } ( options ) {
350
+ ${ constructorBlock }
345
351
}
346
352
` ) ;
347
353
0 commit comments