File tree Expand file tree Collapse file tree 5 files changed +77
-8
lines changed
test/runtime/samples/component-binding-onMount Expand file tree Collapse file tree 5 files changed +77
-8
lines changed Original file line number Diff line number Diff line change 1
- import { run_all } from './utils' ;
1
+ import { run_all , Queue } from './utils' ;
2
2
import { set_current_component } from './lifecycle' ;
3
3
4
- export const dirty_components = [ ] ;
4
+ export const dirty_components = new Queue < any > ( ) ;
5
5
export const intros = { enabled : false } ;
6
6
7
7
export const binding_callbacks = [ ] ;
@@ -31,17 +31,14 @@ export function add_flush_callback(fn) {
31
31
flush_callbacks . push ( fn ) ;
32
32
}
33
33
34
- let flushing = false ;
35
34
const seen_callbacks = new Set ( ) ;
36
35
export function flush ( ) {
37
- if ( flushing ) return ;
38
- flushing = true ;
39
36
40
37
do {
41
38
// first, call beforeUpdate functions
42
39
// and update components
43
- for ( let i = 0 ; i < dirty_components . length ; i += 1 ) {
44
- const component = dirty_components [ i ] ;
40
+ while ( dirty_components . length ) {
41
+ const component = dirty_components . shift ( ) ;
45
42
set_current_component ( component ) ;
46
43
update ( component . $$ ) ;
47
44
}
@@ -73,7 +70,6 @@ export function flush() {
73
70
}
74
71
75
72
update_scheduled = false ;
76
- flushing = false ;
77
73
seen_callbacks . clear ( ) ;
78
74
}
79
75
Original file line number Diff line number Diff line change @@ -58,6 +58,40 @@ export function is_empty(obj) {
58
58
return Object . keys ( obj ) . length === 0 ;
59
59
}
60
60
61
+ export class Queue < T > {
62
+ forward : T [ ] ;
63
+ reverse : T [ ] ;
64
+
65
+ constructor ( ) {
66
+ this . forward = [ ] ;
67
+ this . reverse = [ ] ;
68
+ }
69
+ push ( value : T ) {
70
+ return this . forward . push ( value ) ;
71
+ }
72
+ shift ( ) {
73
+ if ( this . reverse . length === 0 ) {
74
+ while ( this . forward . length ) {
75
+ this . reverse . push ( this . forward . pop ( ) ) ;
76
+ }
77
+ }
78
+ return this . reverse . pop ( ) ;
79
+ }
80
+ get length ( ) {
81
+ return this . forward . length + this . reverse . length ;
82
+ }
83
+ set length ( len : number ) {
84
+ if ( len === 0 ) {
85
+ this . forward . length = 0 ;
86
+ this . reverse . length = 0 ;
87
+ } else {
88
+ while ( this . length > len ) {
89
+ this . shift ( ) ;
90
+ }
91
+ }
92
+ }
93
+ }
94
+
61
95
export function validate_store ( store , name ) {
62
96
if ( store != null && typeof store . subscribe !== 'function' ) {
63
97
throw new Error ( `'${ name } ' is not a store with a 'subscribe' method` ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { onMount } from ' svelte' ;
3
+
4
+ let element;
5
+ let bound = false ;
6
+ onMount (() => {
7
+ if (element) bound = true ;
8
+ });
9
+
10
+ </script >
11
+
12
+ <div bind:this ={element }></div >
13
+ <p >
14
+ Bound? {bound }
15
+ </p >
Original file line number Diff line number Diff line change
1
+ export default {
2
+ async test ( { assert, target } ) {
3
+ assert . htmlEqual ( target . innerHTML , `
4
+ <div id="target"><div></div>
5
+ <p>
6
+ Bound? true
7
+ </p>
8
+ </div>
9
+ ` ) ;
10
+ }
11
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Mount from ' ./Mount.svelte' ;
3
+ import { onMount } from ' svelte' ;
4
+
5
+ onMount (() => {
6
+ const component = new Mount ({
7
+ target: document .querySelector (' #target' ),
8
+ props: {},
9
+ });
10
+ });
11
+ </script >
12
+
13
+ <div id =" target" />
You can’t perform that action at this time.
0 commit comments