a few naming tweaks

pull/10798/head
Rich Harris 2 years ago
parent 230a33dca5
commit bdcd25ed87

@ -28,19 +28,19 @@ export function create_await_block() {
/** /**
* @template V * @template V
* @param {Comment} anchor_node * @param {Comment} anchor
* @param {(() => Promise<V>)} get_input * @param {(() => Promise<V>)} get_input
* @param {null | ((anchor: Node) => void)} pending_fn * @param {null | ((anchor: Node) => void)} pending_fn
* @param {null | ((anchor: Node, value: V) => void)} then_fn * @param {null | ((anchor: Node, value: V) => void)} then_fn
* @param {null | ((anchor: Node, error: unknown) => void)} catch_fn * @param {null | ((anchor: Node, error: unknown) => void)} catch_fn
* @returns {void} * @returns {void}
*/ */
export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_fn) { export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
const block = create_await_block(); const block = create_await_block();
const component_context = current_component_context; const component_context = current_component_context;
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor);
/** @type {any} */ /** @type {any} */
let input; let input;
@ -62,7 +62,7 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
set_current_effect(branch); set_current_effect(branch);
set_current_reaction(branch); // TODO do we need both? set_current_reaction(branch); // TODO do we need both?
set_current_component_context(component_context); set_current_component_context(component_context);
var effect = render_effect(() => fn(anchor_node, value), {}, true); var effect = render_effect(() => fn(anchor, value), {}, true);
set_current_component_context(null); set_current_component_context(null);
set_current_reaction(null); set_current_reaction(null);
set_current_effect(null); set_current_effect(null);
@ -98,7 +98,7 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
destroy_effect(pending_effect); destroy_effect(pending_effect);
} }
pending_effect = render_effect(() => pending_fn(anchor_node), {}, true); pending_effect = render_effect(() => pending_fn(anchor), {}, true);
} }
if (then_effect) pause(then_effect); if (then_effect) pause(then_effect);
@ -132,7 +132,7 @@ export function await_block(anchor_node, get_input, pending_fn, then_fn, catch_f
destroy_effect(then_effect); destroy_effect(then_effect);
} }
then_effect = render_effect(() => then_fn(anchor_node, input), {}, true); then_effect = render_effect(() => then_fn(anchor, input), {}, true);
} }
} }
}, block); }, block);

@ -29,17 +29,17 @@ function create_if_block() {
} }
/** /**
* @param {Comment} anchor_node * @param {Comment} anchor
* @param {() => boolean} condition_fn * @param {() => boolean} get_condition
* @param {(anchor: Node) => void} consequent_fn * @param {(anchor: Node) => void} consequent_fn
* @param {null | ((anchor: Node) => void)} alternate_fn * @param {null | ((anchor: Node) => void)} alternate_fn
* @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local' * @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local'
* @returns {void} * @returns {void}
*/ */
export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn, elseif = false) { export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) {
const block = create_if_block(); const block = create_if_block();
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor);
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */ /** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
let consequent_dom = null; let consequent_dom = null;
@ -57,7 +57,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
let condition = null; let condition = null;
const if_effect = render_effect(() => { const if_effect = render_effect(() => {
if (condition === (condition = !!condition_fn())) return; if (condition === (condition = !!get_condition())) return;
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */ /** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false; let mismatch = false;
@ -87,7 +87,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
} else { } else {
consequent_effect = render_effect( consequent_effect = render_effect(
() => { () => {
consequent_fn(anchor_node); consequent_fn(anchor);
consequent_dom = block.d; consequent_dom = block.d;
if (mismatch) { if (mismatch) {
@ -121,7 +121,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
} else if (alternate_fn) { } else if (alternate_fn) {
alternate_effect = render_effect( alternate_effect = render_effect(
() => { () => {
alternate_fn(anchor_node); alternate_fn(anchor);
alternate_dom = block.d; alternate_dom = block.d;
if (mismatch) { if (mismatch) {

@ -7,15 +7,15 @@ import { remove } from '../reconciler.js';
/** /**
* @template P * @template P
* @template {(props: P) => void} C * @template {(props: P) => void} C
* @param {Comment} anchor_node * @param {Comment} anchor
* @param {() => C} get_component * @param {() => C} get_component
* @param {(component: C) => void} render_fn * @param {(component: C) => void} render_fn
* @returns {void} * @returns {void}
*/ */
export function component(anchor_node, get_component, render_fn) { export function component(anchor, get_component, render_fn) {
const block = {}; const block = {};
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor);
/** @type {C} */ /** @type {C} */
let component; let component;

@ -34,13 +34,13 @@ function swap_block_dom(block, from, to) {
} }
/** /**
* @param {Comment} anchor_node * @param {Comment} anchor
* @param {() => string} tag_fn * @param {() => string} get_tag
* @param {boolean | null} is_svg `null` == not statically known * @param {boolean | null} is_svg `null` == not statically known
* @param {undefined | ((element: Element, anchor: Node) => void)} render_fn * @param {undefined | ((element: Element, anchor: Node) => void)} render_fn
* @returns {void} * @returns {void}
*/ */
export function element(anchor_node, tag_fn, is_svg, render_fn) { export function element(anchor, get_tag, is_svg, render_fn) {
/** @type {import('#client').DynamicElementBlock} */ /** @type {import('#client').DynamicElementBlock} */
const block = { const block = {
// dom // dom
@ -51,7 +51,7 @@ export function element(anchor_node, tag_fn, is_svg, render_fn) {
p: /** @type {import('#client').Block} */ (current_block) p: /** @type {import('#client').Block} */ (current_block)
}; };
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor);
/** @type {string | null} */ /** @type {string | null} */
let tag; let tag;
@ -68,7 +68,7 @@ export function element(anchor_node, tag_fn, is_svg, render_fn) {
let each_item_block = current_each_item_block; let each_item_block = current_each_item_block;
const wrapper = render_effect(() => { const wrapper = render_effect(() => {
const next_tag = tag_fn() || null; const next_tag = get_tag() || null;
if (next_tag === tag) return; if (next_tag === tag) return;
var previous_each_item_block = current_each_item_block; var previous_each_item_block = current_each_item_block;
@ -80,9 +80,9 @@ export function element(anchor_node, tag_fn, is_svg, render_fn) {
const ns = const ns =
is_svg || next_tag === 'svg' is_svg || next_tag === 'svg'
? namespace_svg ? namespace_svg
: is_svg === false || anchor_node.parentElement?.tagName === 'foreignObject' : is_svg === false || anchor.parentElement?.tagName === 'foreignObject'
? null ? null
: anchor_node.parentElement?.namespaceURI ?? null; : anchor.parentElement?.namespaceURI ?? null;
if (effect) { if (effect) {
if (next_tag === null) { if (next_tag === null) {
@ -125,7 +125,7 @@ export function element(anchor_node, tag_fn, is_svg, render_fn) {
render_fn(element, anchor); render_fn(element, anchor);
} }
anchor_node.before(element); anchor.before(element);
if (prev_element) { if (prev_element) {
swap_block_dom(block.p, prev_element, element); swap_block_dom(block.p, prev_element, element);

@ -57,19 +57,19 @@ export function text(dom, value) {
} }
/** /**
* @param {Comment} anchor_node * @param {Comment} anchor
* @param {void | ((anchor: Comment, slot_props: Record<string, unknown>) => void)} slot_fn * @param {void | ((anchor: Comment, slot_props: Record<string, unknown>) => void)} slot_fn
* @param {Record<string, unknown>} slot_props * @param {Record<string, unknown>} slot_props
* @param {null | ((anchor: Comment) => void)} fallback_fn * @param {null | ((anchor: Comment) => void)} fallback_fn
*/ */
export function slot(anchor_node, slot_fn, slot_props, fallback_fn) { export function slot(anchor, slot_fn, slot_props, fallback_fn) {
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor);
if (slot_fn === undefined) { if (slot_fn === undefined) {
if (fallback_fn !== null) { if (fallback_fn !== null) {
fallback_fn(anchor_node); fallback_fn(anchor);
} }
} else { } else {
slot_fn(anchor_node, slot_props); slot_fn(anchor, slot_props);
} }
} }

Loading…
Cancel
Save