File tree Expand file tree Collapse file tree
svelte/demo/src/bootstrap/samples/progressbar Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { tick } from 'svelte' ;
1+ import { createSubscriber } from 'svelte/reactivity ' ;
22
33export class Brewer {
44 #running = $state ( false ) ;
55 #value = $state ( 0 ) ;
66 #interval?: any ;
7- #subscribers = 0 ;
7+ readonly #subscribe = createSubscriber ( ( ) => {
8+ this . #interval = setInterval ( ( ) => {
9+ if ( this . #running && this . #value < 100 ) {
10+ this . #value = this . #value + 10 ;
11+ }
12+ } , 500 ) ;
13+ return ( ) => {
14+ clearInterval ( this . #interval) ;
15+ this . #interval = undefined ;
16+ } ;
17+ } ) ;
818
919 get value ( ) {
10- if ( $effect . tracking ( ) ) {
11- $effect ( ( ) => {
12- if ( this . #subscribers === 0 ) {
13- this . #interval = setInterval ( ( ) => {
14- if ( this . #running && this . #value < 100 ) {
15- this . #value = this . #value + 10 ;
16- }
17- } , 500 ) ;
18- }
19- this . #subscribers++ ;
20- return ( ) => {
21- void tick ( ) . then ( ( ) => {
22- this . #subscribers-- ;
23- if ( this . #subscribers === 0 ) {
24- clearInterval ( this . #interval) ;
25- this . #interval = undefined ;
26- }
27- } ) ;
28- } ;
29- } ) ;
30- }
20+ this . #subscribe( ) ;
3121 return this . #value;
3222 }
3323
You can’t perform that action at this time.
0 commit comments