* Pause multiple effects simultaneously, and coordinate their * subsequent destruction. Used in each blocks * @param {EachState} state * @param {Effect[]} to_destroy * @param {null | Node} controlled_anchor
(state, to_destroy, controlled_anchor)
| 64 | * @param {null | Node} controlled_anchor |
| 65 | */ |
| 66 | function pause_effects(state, to_destroy, controlled_anchor) { |
| 67 | /** @type {TransitionManager[]} */ |
| 68 | var transitions = []; |
| 69 | var length = to_destroy.length; |
| 70 | |
| 71 | /** @type {EachOutroGroup} */ |
| 72 | var group; |
| 73 | var remaining = to_destroy.length; |
| 74 | |
| 75 | for (var i = 0; i < length; i++) { |
| 76 | let effect = to_destroy[i]; |
| 77 | |
| 78 | pause_effect( |
| 79 | effect, |
| 80 | () => { |
| 81 | if (group) { |
| 82 | group.pending.delete(effect); |
| 83 | group.done.add(effect); |
| 84 | |
| 85 | if (group.pending.size === 0) { |
| 86 | var groups = /** @type {Set<EachOutroGroup>} */ (state.outrogroups); |
| 87 | |
| 88 | destroy_effects(state, array_from(group.done)); |
| 89 | groups.delete(group); |
| 90 | |
| 91 | if (groups.size === 0) { |
| 92 | state.outrogroups = null; |
| 93 | } |
| 94 | } |
| 95 | } else { |
| 96 | remaining -= 1; |
| 97 | } |
| 98 | }, |
| 99 | false |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | if (remaining === 0) { |
| 104 | // If we're in a controlled each block (i.e. the block is the only child of an |
| 105 | // element), and we are removing all items, _and_ there are no out transitions, |
| 106 | // we can use the fast path — emptying the element and replacing the anchor |
| 107 | var fast_path = transitions.length === 0 && controlled_anchor !== null; |
| 108 | |
| 109 | if (fast_path) { |
| 110 | var anchor = /** @type {Element} */ (controlled_anchor); |
| 111 | var parent_node = /** @type {Element} */ (anchor.parentNode); |
| 112 | |
| 113 | clear_text_content(parent_node); |
| 114 | parent_node.append(anchor); |
| 115 | |
| 116 | state.items.clear(); |
| 117 | } |
| 118 | |
| 119 | destroy_effects(state, to_destroy, !fast_path); |
| 120 | } else { |
| 121 | group = { |
| 122 | pending: new Set(to_destroy), |
| 123 | done: new Set() |
no test coverage detected