| 20 | * @template Key |
| 21 | */ |
| 22 | export class BranchManager { |
| 23 | /** @type {TemplateNode} */ |
| 24 | anchor; |
| 25 | |
| 26 | /** @type {Map<Batch, Key>} */ |
| 27 | #batches = new Map(); |
| 28 | |
| 29 | /** |
| 30 | * Map of keys to effects that are currently rendered in the DOM. |
| 31 | * These effects are visible and actively part of the document tree. |
| 32 | * Example: |
| 33 | * ``` |
| 34 | * {#if condition} |
| 35 | * foo |
| 36 | * {:else} |
| 37 | * bar |
| 38 | * {/if} |
| 39 | * ``` |
| 40 | * Can result in the entries `true->Effect` and `false->Effect` |
| 41 | * @type {Map<Key, Effect>} |
| 42 | */ |
| 43 | #onscreen = new Map(); |
| 44 | |
| 45 | /** |
| 46 | * Similar to #onscreen with respect to the keys, but contains branches that are not yet |
| 47 | * in the DOM, because their insertion is deferred. |
| 48 | * @type {Map<Key, Branch>} |
| 49 | */ |
| 50 | #offscreen = new Map(); |
| 51 | |
| 52 | /** |
| 53 | * Keys of effects that are currently outroing |
| 54 | * @type {Set<Key>} |
| 55 | */ |
| 56 | #outroing = new Set(); |
| 57 | |
| 58 | /** |
| 59 | * Whether to pause (i.e. outro) on change, or destroy immediately. |
| 60 | * This is necessary for `<svelte:element>` |
| 61 | */ |
| 62 | #transition = true; |
| 63 | |
| 64 | /** |
| 65 | * @param {TemplateNode} anchor |
| 66 | * @param {boolean} transition |
| 67 | */ |
| 68 | constructor(anchor, transition = true) { |
| 69 | this.anchor = anchor; |
| 70 | this.#transition = transition; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param {Batch} batch |
| 75 | */ |
| 76 | #commit = (batch) => { |
| 77 | // if this batch was made obsolete, bail |
| 78 | if (!this.#batches.has(batch)) return; |
| 79 |
nothing calls this directly
no test coverage detected