@@ -26,19 +26,37 @@ let uid = 1;
2626export class Batch {
2727 id = uid ++ ;
2828
29- /** @type {Map<Source, any> } */
30- #previous = new Map ( ) ;
31-
32- /** @type {Map<Source, any> } */
29+ /**
30+ * The current values of any sources that are updated in this batch
31+ * They keys of this map are identical to `this.#previous`
32+ * @type {Map<Source, any> }
33+ */
3334 #current = new Map ( ) ;
3435
35- /** @type {Set<() => void> } */
36+ /**
37+ * The values of any sources that are updated in this batch _before_ those updates took place.
38+ * They keys of this map are identical to `this.#current`
39+ * @type {Map<Source, any> }
40+ */
41+ #previous = new Map ( ) ;
42+
43+ /**
44+ * When the batch is committed (and the DOM is updated), we need to remove old branches
45+ * and append new ones by calling the functions added inside (if/each/key/etc) blocks
46+ * @type {Set<() => void> }
47+ */
3648 #callbacks = new Set ( ) ;
3749
50+ /**
51+ * The number of async effects that are currently in flight
52+ */
3853 #pending = 0 ;
3954
40- /** @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null } */
41- // TODO replace with Promise.withResolvers once supported widely enough
55+ /**
56+ * A deferred that resolves when the batch is committed, used with `settled()`
57+ * TODO replace with Promise.withResolvers once supported widely enough
58+ * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null }
59+ */
4260 #deferred = null ;
4361
4462 /** @type {Effect[] } */
@@ -53,7 +71,11 @@ export class Batch {
5371 /** @type {Effect[] } */
5472 effects = [ ] ;
5573
56- /** @type {Set<Effect> } */
74+ /**
75+ * A set of branches that still exist, but will be destroyed when this batch
76+ * is committed — we skip over these during `process`
77+ * @type {Set<Effect> }
78+ */
5779 skipped_effects = new Set ( ) ;
5880
5981 /**
0 commit comments