Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 157x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 145x 157x 157x 151x 151x 151x 151x 157x 157x 238x 238x 238x 208x 208x 208x 34x 34x 208x 208x 208x 208x 208x 208x 208x 116x 116x 112x 112x 116x 106x 106x 208x 208x 39x 39x 39x 39x 39x 39x 39x 39x 208x 208x 208x 208x 208x 99x 208x 47x 1x 1x 47x 47x 47x 99x 196x 196x 208x 238x 30x 30x 30x 30x 16x 2x 2x 16x 16x 16x 30x 238x 238x 238x 238x 157x 157x | import { is_promise, noop } from '../../../shared/utils.js'; import { current_component_context, flush_sync, set_current_component_context, set_current_effect, set_current_reaction, set_dev_current_component_function } from '../../runtime.js'; import { block, branch, destroy_effect, pause_effect } from '../../reactivity/effects.js'; import { INERT } from '../../constants.js'; import { DEV } from 'esm-env'; import { hydrating } from '../hydration.js'; /** * @template V * @param {Comment} anchor * @param {(() => Promise<V>)} get_input * @param {null | ((anchor: Node) => void)} pending_fn * @param {null | ((anchor: Node, value: V) => void)} then_fn * @param {null | ((anchor: Node, error: unknown) => void)} catch_fn * @returns {void} */ export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) { const component_context = current_component_context; /** @type {any} */ let component_function; if (DEV) { component_function = component_context?.function ?? null; } /** @type {any} */ let input; /** @type {import('#client').Effect | null} */ let pending_effect; /** @type {import('#client').Effect | null} */ let then_effect; /** @type {import('#client').Effect | null} */ let catch_effect; /** * @param {(anchor: Comment, value: any) => void} fn * @param {any} value */ function create_effect(fn, value) { set_current_effect(effect); set_current_reaction(effect); // TODO do we need both? set_current_component_context(component_context); if (DEV) { set_dev_current_component_function(component_function); } var e = branch(() => fn(anchor, value)); if (DEV) { set_dev_current_component_function(null); } set_current_component_context(null); set_current_reaction(null); set_current_effect(null); // without this, the DOM does not update until two ticks after the promise, // resolves which is unexpected behaviour (and somewhat irksome to test) flush_sync(); return e; } function pause() { if (pending_effect) pause_effect(pending_effect); if (then_effect) pause_effect(then_effect); if (catch_effect) pause_effect(catch_effect); } const effect = block(() => { if (input === (input = get_input())) return; if (is_promise(input)) { let was_hydrating = hydrating; if (hydrating && pending_fn) { pending_effect = branch(() => pending_fn(anchor)); } var promise = /** @type {Promise<any>} */ (input); var settled = false; promise.then( (value) => { settled = true; if (promise !== input) return; pause(); if (then_fn) { then_effect = create_effect(then_fn, value); } }, (error) => { settled = true; if (promise !== input) return; pause(); if (catch_fn) { catch_effect = create_effect(catch_fn, error); } } ); Promise.resolve().then(() => { // if the promise was already resolved, avoid thrash if (settled) return; if (pending_fn && !was_hydrating) { if (pending_effect && (pending_effect.f & INERT) === 0) { destroy_effect(pending_effect); } pending_effect = branch(() => pending_fn(anchor)); } if (then_effect) pause_effect(then_effect); if (catch_effect) pause_effect(catch_effect); }); } else { if (pending_effect) pause_effect(pending_effect); if (catch_effect) pause_effect(catch_effect); if (then_fn) { if (then_effect) { destroy_effect(then_effect); } then_effect = branch(() => then_fn(anchor, input)); } } // Inert effects are proactively detached from the effect tree. Returning a noop // teardown function is an easy way to ensure that this is not discarded return noop; }); } |