@@ -31,6 +31,24 @@ export function add_flush_callback(fn) {
31
31
flush_callbacks . push ( fn ) ;
32
32
}
33
33
34
+ // flush() calls callbacks in this order:
35
+ // 1. All beforeUpdate callbacks, in order: parents before children
36
+ // 2. All bind:this callbacks, in reverse order: children before parents.
37
+ // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
38
+ // for afterUpdates called during the initial onMount, which are called in
39
+ // reverse order: children before parents.
40
+ // Since callbacks might update component values, which could trigger another
41
+ // call to flush(), the following steps guard against this:
42
+ // 1. During beforeUpdate, any updated components will be added to the
43
+ // dirty_components array and will cause a reentrant call to flush(). Because
44
+ // the flush index is kept outside the function, the reentrant call will pick
45
+ // up where the earlier call left off and go through all dirty components. The
46
+ // current_component value is saved and restored so that the reentrant call will
47
+ // not interfere with the "parent" flush() call.
48
+ // 2. bind:this callbacks cannot trigger new flush() calls.
49
+ // 3. During afterUpdate, any updated components will NOT have their afterUpdate
50
+ // callback called a second time; the seen_callbacks set, outside the flush()
51
+ // function, guarantees this behavior.
34
52
const seen_callbacks = new Set ( ) ;
35
53
let flushidx = 0 ; // Do *not* move this inside the flush() function
36
54
export function flush ( ) {
0 commit comments