bind_select_value() — svelte Function Reference
Architecture documentation for the bind_select_value() function in select.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD c085d4db_2942_3c89_a472_21c20593b124["bind_select_value()"] dbe1ea86_6e94_eeeb_a2d1_1db78ca967bc["select.js"] c085d4db_2942_3c89_a472_21c20593b124 -->|defined in| dbe1ea86_6e94_eeeb_a2d1_1db78ca967bc 140e2114_da40_4679_bc9f_599a89c67e4e["listen_to_event_and_reset_event()"] c085d4db_2942_3c89_a472_21c20593b124 -->|calls| 140e2114_da40_4679_bc9f_599a89c67e4e 92afbc52_412a_6f4e_4097_d55790325b3e["get_option_value()"] c085d4db_2942_3c89_a472_21c20593b124 -->|calls| 92afbc52_412a_6f4e_4097_d55790325b3e a985ae40_8ef8_7ef2_adad_116fbf97e70c["effect()"] c085d4db_2942_3c89_a472_21c20593b124 -->|calls| a985ae40_8ef8_7ef2_adad_116fbf97e70c 35049132_3e86_afd7_a475_924b092a0c2b["select_option()"] c085d4db_2942_3c89_a472_21c20593b124 -->|calls| 35049132_3e86_afd7_a475_924b092a0c2b 69a43253_5c15_5f06_b28b_0c8b251c8edd["init_select()"] c085d4db_2942_3c89_a472_21c20593b124 -->|calls| 69a43253_5c15_5f06_b28b_0c8b251c8edd style c085d4db_2942_3c89_a472_21c20593b124 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/internal/client/dom/elements/bindings/select.js lines 86–149
export function bind_select_value(select, get, set = get) {
var batches = new WeakSet();
var mounting = true;
listen_to_event_and_reset_event(select, 'change', (is_reset) => {
var query = is_reset ? '[selected]' : ':checked';
/** @type {unknown} */
var value;
if (select.multiple) {
value = [].map.call(select.querySelectorAll(query), get_option_value);
} else {
/** @type {HTMLOptionElement | null} */
var selected_option =
select.querySelector(query) ??
// will fall back to first non-disabled option if no option is selected
select.querySelector('option:not([disabled])');
value = selected_option && get_option_value(selected_option);
}
set(value);
if (current_batch !== null) {
batches.add(current_batch);
}
});
// Needs to be an effect, not a render_effect, so that in case of each loops the logic runs after the each block has updated
effect(() => {
var value = get();
if (select === document.activeElement) {
// we need both, because in non-async mode, render effects run before previous_batch is set
var batch = /** @type {Batch} */ (previous_batch ?? current_batch);
// Don't update the <select> if it is focused. We can get here if, for example,
// an update is deferred because of async work depending on the select:
//
// <select bind:value={selected}>...</select>
// <p>{await find(selected)}</p>
if (batches.has(batch)) {
return;
}
}
select_option(select, value, mounting);
// Mounting and value undefined -> take selection from dom
if (mounting && value === undefined) {
/** @type {HTMLOptionElement | null} */
var selected_option = select.querySelector(':checked');
if (selected_option !== null) {
value = get_option_value(selected_option);
set(value);
}
}
// @ts-ignore
select.__value = value;
mounting = false;
});
init_select(select);
}
Domain
Subdomains
Source
Frequently Asked Questions
What does bind_select_value() do?
bind_select_value() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/elements/bindings/select.js.
Where is bind_select_value() defined?
bind_select_value() is defined in packages/svelte/src/internal/client/dom/elements/bindings/select.js at line 86.
What does bind_select_value() call?
bind_select_value() calls 5 function(s): effect, get_option_value, init_select, listen_to_event_and_reset_event, select_option.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free