simplify init_select

pull/16251/head
Rich Harris 3 months ago
parent 334adc0897
commit d89f3184eb

@ -666,7 +666,7 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
);
if (is_select_with_value) {
state.init.push(b.stmt(b.call('$.init_select', node_id, b.thunk(value))));
state.init.push(b.stmt(b.call('$.init_select', node_id)));
}
if (has_state) {

@ -6,7 +6,7 @@ import { create_event, delegate } from './events.js';
import { add_form_reset_listener, autofocus } from './misc.js';
import * as w from '../../warnings.js';
import { LOADING_ATTR_SYMBOL } from '#client/constants';
import { queue_idle_task } from '../task.js';
import { queue_idle_task, queue_micro_task } from '../task.js';
import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js';
import {
active_effect,
@ -20,7 +20,7 @@ import { clsx } from '../../../shared/attributes.js';
import { set_class } from './class.js';
import { set_style } from './style.js';
import { ATTACHMENT_KEY, NAMESPACE_HTML } from '../../../../constants.js';
import { block, branch, destroy_effect } from '../../reactivity/effects.js';
import { block, branch, destroy_effect, effect } from '../../reactivity/effects.js';
import { derived } from '../../reactivity/deriveds.js';
import { init_select, select_option } from './bindings/select.js';
@ -513,10 +513,15 @@ export function attribute_effect(
});
if (is_select) {
init_select(
/** @type {HTMLSelectElement} */ (element),
() => /** @type {Record<string | symbol, any>} */ (prev).value
);
var select = /** @type {HTMLSelectElement} */ (element);
if (!inited) {
effect(() => {
select_option(select, /** @type {Record<string | symbol, any>} */ (prev).value);
});
}
init_select(select);
}
inited = true;

@ -53,16 +53,9 @@ export function select_option(select, value, mounting) {
* inside an `#each` block.
* @template V
* @param {HTMLSelectElement} select
* @param {() => V} [get_value]
*/
export function init_select(select, get_value) {
let mounting = true;
export function init_select(select) {
effect(() => {
if (get_value) {
select_option(select, untrack(get_value), mounting);
}
mounting = false;
var observer = new MutationObserver(() => {
// @ts-ignore
var value = select.__value;

Loading…
Cancel
Save