@@ -296,31 +296,32 @@ Worker.prototype.save = function save(filename) {
296
296
/* ----- SET / GET ----- */
297
297
298
298
Worker . prototype . set = function set ( opt ) {
299
- // Set properties within the promise chain.
300
299
// TODO: Test null/undefined input to this function.
301
300
// TODO: Implement ordered pairs?
302
- return this . then ( async function set_main ( ) {
303
- for ( var key in opt ) {
301
+
302
+ // Build an array of setter functions to queue.
303
+ var fns = Object . keys ( opt || { } ) . map ( function ( key ) {
304
304
if ( key in Worker . template . prop ) {
305
305
// Set pre-defined properties.
306
- this . prop [ key ] = opt [ key ] ;
306
+ return function set_prop ( ) { this . prop [ key ] = opt [ key ] ; }
307
307
} else {
308
308
switch ( key ) {
309
309
case 'margin' :
310
- await this . setMargin ( opt . margin ) ;
311
- break ;
310
+ return this . setMargin . bind ( this , opt . margin ) ;
312
311
case 'jsPDF' :
313
- // Include jsPDF here because it must also update pageSize.
314
- this . opt . jsPDF = opt . jsPDF ;
312
+ return function set_jsPDF ( ) { this . opt . jsPDF = opt . jsPDF ; return this . setPageSize ( ) ; }
315
313
case 'pageSize' :
316
- await this . setPageSize ( opt . pageSize ) ;
317
- break ;
314
+ return this . setPageSize . bind ( this , opt . pageSize ) ;
318
315
default :
319
316
// Set any other properties in opt.
320
- this . opt [ key ] = opt [ key ] ;
317
+ return function set_opt ( ) { this . opt [ key ] = opt [ key ] } ;
321
318
}
322
319
}
323
- }
320
+ } , this ) ;
321
+
322
+ // Set properties within the promise chain.
323
+ return this . then ( function set_main ( ) {
324
+ return this . thenList ( fns ) ;
324
325
} ) ;
325
326
} ;
326
327
0 commit comments