@@ -195,13 +195,19 @@ export default function addBindings(
195
195
196
196
const usesContext = group . bindings . some ( binding => binding . handler . usesContext ) ;
197
197
const usesState = group . bindings . some ( binding => binding . handler . usesState ) ;
198
+ const usesStore = group . bindings . some ( binding => binding . handler . usesStore ) ;
198
199
const mutations = group . bindings . map ( binding => binding . handler . mutation ) . filter ( Boolean ) . join ( '\n' ) ;
199
200
200
201
const props = new Set ( ) ;
202
+ const storeProps = new Set ( ) ;
201
203
group . bindings . forEach ( binding => {
202
204
binding . handler . props . forEach ( prop => {
203
205
props . add ( prop ) ;
204
206
} ) ;
207
+
208
+ binding . handler . storeProps . forEach ( prop => {
209
+ storeProps . add ( prop ) ;
210
+ } ) ;
205
211
} ) ; // TODO use stringifyProps here, once indenting is fixed
206
212
207
213
// media bindings — awkward special case. The native timeupdate events
@@ -222,9 +228,11 @@ export default function addBindings(
222
228
}
223
229
${ usesContext && `var context = ${ node . var } ._svelte;` }
224
230
${ usesState && `var state = #component.get();` }
231
+ ${ usesStore && `var $ = #component.store.get();` }
225
232
${ needsLock && `${ lock } = true;` }
226
233
${ mutations . length > 0 && mutations }
227
- #component.set({ ${ Array . from ( props ) . join ( ', ' ) } });
234
+ ${ props . size > 0 && `#component.set({ ${ Array . from ( props ) . join ( ', ' ) } });` }
235
+ ${ storeProps . size > 0 && `#component.store.set({ ${ Array . from ( storeProps ) . join ( ', ' ) } });` }
228
236
${ needsLock && `${ lock } = false;` }
229
237
}
230
238
` ) ;
@@ -307,6 +315,13 @@ function getEventHandler(
307
315
dependencies : string [ ] ,
308
316
value : string ,
309
317
) {
318
+ let storeDependencies = [ ] ;
319
+
320
+ if ( generator . options . store ) {
321
+ storeDependencies = dependencies . filter ( prop => prop [ 0 ] === '$' ) . map ( prop => prop . slice ( 1 ) ) ;
322
+ dependencies = dependencies . filter ( prop => prop [ 0 ] !== '$' ) ;
323
+ }
324
+
310
325
if ( block . contexts . has ( name ) ) {
311
326
const tail = attribute . value . type === 'MemberExpression'
312
327
? getTailSnippet ( attribute . value )
@@ -318,8 +333,10 @@ function getEventHandler(
318
333
return {
319
334
usesContext : true ,
320
335
usesState : true ,
336
+ usesStore : storeDependencies . length > 0 ,
321
337
mutation : `${ list } [${ index } ]${ tail } = ${ value } ;` ,
322
- props : dependencies . map ( prop => `${ prop } : state.${ prop } ` )
338
+ props : dependencies . map ( prop => `${ prop } : state.${ prop } ` ) ,
339
+ storeProps : storeDependencies . map ( prop => `${ prop } : $.${ prop } ` )
323
340
} ;
324
341
}
325
342
@@ -336,16 +353,31 @@ function getEventHandler(
336
353
return {
337
354
usesContext : false ,
338
355
usesState : true ,
356
+ usesStore : storeDependencies . length > 0 ,
339
357
mutation : `${ snippet } = ${ value } ` ,
340
- props : dependencies . map ( ( prop : string ) => `${ prop } : state.${ prop } ` )
358
+ props : dependencies . map ( ( prop : string ) => `${ prop } : state.${ prop } ` ) ,
359
+ storeProps : storeDependencies . map ( prop => `${ prop } : $.${ prop } ` )
341
360
} ;
342
361
}
343
362
363
+ let props ;
364
+ let storeProps ;
365
+
366
+ if ( generator . options . store && name [ 0 ] === '$' ) {
367
+ props = [ ] ;
368
+ storeProps = [ `${ name . slice ( 1 ) } : ${ value } ` ] ;
369
+ } else {
370
+ props = [ `${ name } : ${ value } ` ] ;
371
+ storeProps = [ ] ;
372
+ }
373
+
344
374
return {
345
375
usesContext : false ,
346
376
usesState : false ,
377
+ usesStore : false ,
347
378
mutation : null ,
348
- props : [ `${ name } : ${ value } ` ]
379
+ props,
380
+ storeProps
349
381
} ;
350
382
}
351
383
@@ -393,4 +425,4 @@ function isComputed(node: Node) {
393
425
}
394
426
395
427
return false ;
396
- }
428
+ }
0 commit comments