@@ -41,7 +41,7 @@ describe('writable', () => {
41
41
42
42
const store = writable ( 0 , ( ) => {
43
43
called += 1 ;
44
- return ( ) => ( called -= 1 ) ;
44
+ return ( ) => { called -= 1 } ;
45
45
} ) ;
46
46
47
47
const unsubscribe1 = store . subscribe ( ( ) => { } ) ;
@@ -81,10 +81,10 @@ describe('writable', () => {
81
81
let count1 = 0 ;
82
82
let count2 = 0 ;
83
83
84
- store . subscribe ( ( ) => ( count1 += 1 ) ) ( ) ;
84
+ store . subscribe ( ( ) => { count1 += 1 } ) ( ) ;
85
85
assert . equal ( count1 , 1 ) ;
86
86
87
- const unsubscribe = store . subscribe ( ( ) => ( count2 += 1 ) ) ;
87
+ const unsubscribe = store . subscribe ( ( ) => { count2 += 1 } ) ;
88
88
assert . equal ( count2 , 1 ) ;
89
89
90
90
unsubscribe ( ) ;
@@ -270,7 +270,44 @@ describe('derived', () => {
270
270
assert . deepEqual ( values , [ 6 , 12 , 20 ] ) ;
271
271
} ) ;
272
272
273
- it ( 'passes optional set function' , ( ) => {
273
+ it ( 'allows derived with different types' , ( ) => {
274
+ const a = writable ( 'one' ) ;
275
+ const b = writable ( 1 ) ;
276
+
277
+ // @ts -expect-error TODO feels like inference should work here
278
+ const c = derived ( [ a , b ] , ( [ a , b ] ) => `${ a } ${ b } ` ) ;
279
+
280
+ assert . deepEqual ( get ( c ) , 'one 1' ) ;
281
+
282
+ a . set ( 'two' ) ;
283
+ b . set ( 2 ) ;
284
+ assert . deepEqual ( get ( c ) , 'two 2' ) ;
285
+ } ) ;
286
+
287
+ it ( 'errors on undefined stores #1' , ( ) => {
288
+ assert . throws ( ( ) => {
289
+ // @ts -expect-error TODO feels like inference should work here
290
+ derived ( null , ( n ) => n ) ;
291
+ } ) ;
292
+ } ) ;
293
+
294
+ it ( 'errors on undefined stores #2' , ( ) => {
295
+ assert . throws ( ( ) => {
296
+ const a = writable ( 1 ) ;
297
+ // @ts -expect-error TODO feels like inference should work here
298
+ derived ( [ a , null , undefined ] , ( [ n ] ) => {
299
+ return n * 2 ;
300
+ } ) ;
301
+ } ) ;
302
+ } ) ;
303
+
304
+ it ( 'works with RxJS-style observables' , ( ) => {
305
+ // @ts -expect-error TODO feels like inference should work here
306
+ const d = derived ( fake_observable , ( _ ) => _ ) ;
307
+ assert . equal ( get ( d ) , 42 ) ;
308
+ } ) ;
309
+
310
+ it ( 'passes optional `set` function' , ( ) => {
274
311
const number = writable ( 1 ) ;
275
312
const evens = derived (
276
313
number ,
@@ -301,9 +338,9 @@ describe('derived', () => {
301
338
assert . deepEqual ( values , [ 0 , 2 , 4 ] ) ;
302
339
} ) ;
303
340
304
- it ( 'passes optional set and update functions' , ( ) => {
341
+ it ( 'passes optional ` set` and ` update` functions' , ( ) => {
305
342
const number = writable ( 1 ) ;
306
- const evensAndSquaresOf4 = derived (
343
+ const evens_and_squares_of_4 = derived (
307
344
number ,
308
345
// @ts -expect-error TODO feels like inference should work here
309
346
( n , set , update ) => {
@@ -316,7 +353,7 @@ describe('derived', () => {
316
353
317
354
const values : number [ ] = [ ] ;
318
355
319
- const unsubscribe = evensAndSquaresOf4 . subscribe ( ( value ) => {
356
+ const unsubscribe = evens_and_squares_of_4 . subscribe ( ( value ) => {
320
357
values . push ( value ) ;
321
358
} ) ;
322
359
@@ -341,21 +378,20 @@ describe('derived', () => {
341
378
} ) ;
342
379
343
380
it ( 'prevents glitches' , ( ) => {
344
- const lastname = writable ( 'Jekyll' ) ;
345
-
381
+ const last_name = writable ( 'Jekyll' ) ;
346
382
// @ts -expect-error TODO feels like inference should work here
347
- const firstname = derived ( lastname , ( n ) => ( n === 'Jekyll' ? 'Henry' : 'Edward' ) ) ;
383
+ const first_name = derived ( last_name , ( n ) => ( n === 'Jekyll' ? 'Henry' : 'Edward' ) ) ;
348
384
349
385
// @ts -expect-error TODO feels like inference should work here
350
- const fullname = derived ( [ firstname , lastname ] , ( names ) => names . join ( ' ' ) ) ;
386
+ const full_name = derived ( [ first_name , last_name ] , ( names ) => names . join ( ' ' ) ) ;
351
387
352
388
const values : string [ ] = [ ] ;
353
389
354
- const unsubscribe = fullname . subscribe ( ( value ) => {
390
+ const unsubscribe = full_name . subscribe ( ( value ) => {
355
391
values . push ( value as string ) ;
356
392
} ) ;
357
393
358
- lastname . set ( 'Hyde' ) ;
394
+ last_name . set ( 'Hyde' ) ;
359
395
360
396
assert . deepEqual ( values , [ 'Henry Jekyll' , 'Edward Hyde' ] ) ;
361
397
@@ -421,7 +457,7 @@ describe('derived', () => {
421
457
unsubscribe ( ) ;
422
458
} ) ;
423
459
424
- it ( 'is updated with safe_not_equal logic' , ( ) => {
460
+ it ( 'is updated with ` safe_not_equal` logic' , ( ) => {
425
461
const arr = [ 0 ] ;
426
462
427
463
const number = writable ( 1 ) ;
@@ -446,7 +482,7 @@ describe('derived', () => {
446
482
unsubscribe ( ) ;
447
483
} ) ;
448
484
449
- it ( 'calls a cleanup function' , ( ) => {
485
+ it ( 'calls a ` cleanup` function' , ( ) => {
450
486
const num = writable ( 1 ) ;
451
487
452
488
const values : number [ ] = [ ] ;
@@ -503,26 +539,6 @@ describe('derived', () => {
503
539
unsubscribe ( ) ;
504
540
} ) ;
505
541
506
- it ( 'allows derived with different types' , ( ) => {
507
- const a = writable ( 'one' ) ;
508
- const b = writable ( 1 ) ;
509
-
510
- // @ts -expect-error TODO feels like inference should work here
511
- const c = derived ( [ a , b ] , ( [ a , b ] ) => `${ a } ${ b } ` ) ;
512
-
513
- assert . deepEqual ( get ( c ) , 'one 1' ) ;
514
-
515
- a . set ( 'two' ) ;
516
- b . set ( 2 ) ;
517
- assert . deepEqual ( get ( c ) , 'two 2' ) ;
518
- } ) ;
519
-
520
- it ( 'works with RxJS-style observables' , ( ) => {
521
- // @ts -expect-error TODO feels like inference should work here
522
- const d = derived ( fake_observable , ( _ ) => _ ) ;
523
- assert . equal ( get ( d ) , 42 ) ;
524
- } ) ;
525
-
526
542
it ( "doesn't restart when unsubscribed from another store with a shared ancestor" , ( ) => {
527
543
const a = writable ( true ) ;
528
544
let b_started = false ;
@@ -545,23 +561,6 @@ describe('derived', () => {
545
561
a . set ( false ) ;
546
562
assert . equal ( b_started , false ) ;
547
563
} ) ;
548
-
549
- it ( 'errors on undefined stores #1' , ( ) => {
550
- assert . throws ( ( ) => {
551
- // @ts -expect-error TODO feels like inference should work here
552
- derived ( null , ( n ) => n ) ;
553
- } ) ;
554
- } ) ;
555
-
556
- it ( 'errors on undefined stores #2' , ( ) => {
557
- assert . throws ( ( ) => {
558
- const a = writable ( 1 ) ;
559
- // @ts -expect-error TODO feels like inference should work here
560
- derived ( [ a , null , undefined ] , ( [ n ] ) => {
561
- return n * 2 ;
562
- } ) ;
563
- } ) ;
564
- } ) ;
565
564
} ) ;
566
565
567
566
describe ( 'get' , ( ) => {
@@ -577,17 +576,17 @@ describe('get', () => {
577
576
578
577
describe ( 'readonly' , ( ) => {
579
578
it ( 'makes a store readonly' , ( ) => {
580
- const writableStore = writable ( 1 ) ;
581
- const readableStore = readonly ( writableStore ) ;
579
+ const writable_store = writable ( 1 ) ;
580
+ const readable_store = readonly ( writable_store ) ;
582
581
583
- assert . equal ( get ( readableStore ) , get ( writableStore ) ) ;
582
+ assert . equal ( get ( readable_store ) , get ( writable_store ) ) ;
584
583
585
- writableStore . set ( 2 ) ;
584
+ writable_store . set ( 2 ) ;
586
585
587
- assert . equal ( get ( readableStore ) , 2 ) ;
588
- assert . equal ( get ( readableStore ) , get ( writableStore ) ) ;
586
+ assert . equal ( get ( readable_store ) , 2 ) ;
587
+ assert . equal ( get ( readable_store ) , get ( writable_store ) ) ;
589
588
590
589
// @ts -ignore
591
- assert . throws ( ( ) => readableStore . set ( 3 ) ) ;
590
+ assert . throws ( ( ) => readable_store . set ( 3 ) ) ;
592
591
} ) ;
593
592
} ) ;
0 commit comments