reduce diff

pull/17038/head
Rich Harris 4 weeks ago
parent a77fab9d17
commit df666c3ce3

@ -23,6 +23,6 @@ export function DebugTag(node, context) {
const call = b.call('console.log', object);
context.state.init.push(
b.stmt(b.call('$.template_effect', b.array([]), b.thunk(b.block([b.stmt(call), b.debugger]))))
b.stmt(b.call('$.template_effect', b.thunk(b.block([b.stmt(call), b.debugger]))))
);
}

@ -476,7 +476,6 @@ function setup_select_synchronization(value_binding, context) {
b.stmt(
b.call(
'$.template_effect',
b.array([]),
b.thunk(
b.block([b.stmt(/** @type {Expression} */ (context.visit(bound))), b.stmt(invalidator)])
)
@ -655,7 +654,7 @@ function build_custom_element_attribute_update_assignment(node_id, attribute, co
// this is different from other updates — it doesn't get grouped,
// because set_custom_element_data may not be idempotent
const update = has_state ? b.call('$.template_effect', b.array([]), b.thunk(call)) : call;
const update = has_state ? b.call('$.template_effect', b.thunk(call)) : call;
context.state.init.push(b.stmt(update));
}

@ -73,7 +73,7 @@ export function RenderTag(node, context) {
const async_values = memoizer.async_values();
const blockers = memoizer.blockers();
if (async_values || blockers.elements.length > 0) {
if (async_values || blockers) {
context.state.init.push(
b.stmt(
b.call(

@ -76,7 +76,7 @@ export function SlotElement(node, context) {
const async_values = memoizer.async_values();
const blockers = memoizer.blockers();
if (async_values || blockers.elements.length > 0) {
if (async_values || blockers) {
context.state.init.push(
b.stmt(
b.call(

@ -502,7 +502,7 @@ export function build_component(node, component_name, context) {
const async_values = memoizer.async_values();
const blockers = memoizer.blockers();
if (async_values || blockers.elements.length > 0) {
if (async_values || blockers) {
return b.stmt(
b.call(
'$.async',

@ -86,10 +86,10 @@ export function build_attribute_effect(
b.call(
'$.attribute_effect',
element_id,
memoizer.blockers(),
b.arrow(ids, b.object(values)),
memoizer.sync_values(),
memoizer.async_values(),
memoizer.blockers(),
element.metadata.scoped &&
context.state.analysis.css.hash !== '' &&
b.literal(context.state.analysis.css.hash),

@ -60,7 +60,7 @@ export class Memoizer {
}
blockers() {
return b.array([...this.#blockers]);
return this.#blockers.size > 0 ? b.array([...this.#blockers]) : undefined;
}
deriveds(runes = true) {
@ -191,7 +191,6 @@ export function build_render_statement(state) {
return b.stmt(
b.call(
'$.template_effect',
memoizer.blockers(),
b.arrow(
ids,
state.update.length === 1 && state.update[0].type === 'ExpressionStatement'
@ -199,7 +198,8 @@ export function build_render_statement(state) {
: b.block(state.update)
),
memoizer.sync_values(),
memoizer.async_values()
memoizer.async_values(),
memoizer.blockers()
)
);
}

@ -18,7 +18,7 @@ import { get_boundary } from './boundary.js';
* @param {Array<() => Promise<any>>} expressions
* @param {(anchor: TemplateNode, ...deriveds: Value[]) => void} fn
*/
export function async(node, blockers, expressions = [], fn) {
export function async(node, blockers = [], expressions = [], fn) {
var boundary = get_boundary();
var batch = /** @type {Batch} */ (current_batch);
var blocking = !boundary.is_pending();

@ -46,7 +46,7 @@ export function html(node, get_value, svg = false, mathml = false, skip_warning
var value = '';
template_effect([], () => {
template_effect(() => {
var effect = /** @type {Effect} */ (active_effect);
if (value === (value = get_value() ?? '')) {

@ -490,10 +490,10 @@ function set_attributes(
*/
export function attribute_effect(
element,
blockers,
fn,
sync = [],
async = [],
blockers = [],
css_hash,
should_remove_defaults = false,
skip_warning = false

@ -362,13 +362,12 @@ export function render_effect(fn, flags = 0) {
}
/**
* @param {Array<Promise<void>>} blockers
* @param {(...expressions: any) => void | (() => void)} fn
* @param {Array<() => any>} sync
* @param {Array<() => Promise<any>>} async
* @param {Promise<void>} [blocker]
* @param {Array<Promise<void>>} blockers
*/
export function template_effect(blockers, fn, sync = [], async = [], blocker) {
export function template_effect(fn, sync = [], async = [], blockers = []) {
flatten(blockers, sync, async, (values) => {
create_effect(RENDER_EFFECT, () => fn(...values.map(get)), true);
});

@ -17,7 +17,7 @@ export default function Async_each_fallback_hoisting($$anchor) {
var text = $.text();
$.template_effect([], ($0) => $.set_text(text, $0), void 0, [() => Promise.reject('This should never be reached')]);
$.template_effect(($0) => $.set_text(text, $0), void 0, [() => Promise.reject('This should never be reached')]);
$.append($$anchor, text);
},
($$anchor) => {
@ -25,7 +25,7 @@ export default function Async_each_fallback_hoisting($$anchor) {
var text_1 = $.text();
$.template_effect([], ($0) => $.set_text(text_1, $0), void 0, [() => Promise.resolve(4)]);
$.template_effect(($0) => $.set_text(text_1, $0), void 0, [() => Promise.resolve(4)]);
$.append($$anchor, text_1);
}
);

@ -15,7 +15,7 @@ export default function Async_each_hoisting($$anchor) {
var text = $.text();
$.template_effect([], ($0) => $.set_text(text, $0), void 0, [() => $.get(item)]);
$.template_effect(($0) => $.set_text(text, $0), void 0, [() => $.get(item)]);
$.append($$anchor, text);
});
});

@ -10,14 +10,14 @@ export default function Async_if_alternate_hoisting($$anchor) {
var consequent = ($$anchor) => {
var text = $.text();
$.template_effect([], ($0) => $.set_text(text, $0), void 0, [() => Promise.reject('no no no')]);
$.template_effect(($0) => $.set_text(text, $0), void 0, [() => Promise.reject('no no no')]);
$.append($$anchor, text);
};
var alternate = ($$anchor) => {
var text_1 = $.text();
$.template_effect([], ($0) => $.set_text(text_1, $0), void 0, [() => Promise.resolve('yes yes yes')]);
$.template_effect(($0) => $.set_text(text_1, $0), void 0, [() => Promise.resolve('yes yes yes')]);
$.append($$anchor, text_1);
};

@ -10,14 +10,14 @@ export default function Async_if_hoisting($$anchor) {
var consequent = ($$anchor) => {
var text = $.text();
$.template_effect([], ($0) => $.set_text(text, $0), void 0, [() => Promise.resolve('yes yes yes')]);
$.template_effect(($0) => $.set_text(text, $0), void 0, [() => Promise.resolve('yes yes yes')]);
$.append($$anchor, text);
};
var alternate = ($$anchor) => {
var text_1 = $.text();
$.template_effect([], ($0) => $.set_text(text_1, $0), void 0, [() => Promise.reject('no no no')]);
$.template_effect(($0) => $.set_text(text_1, $0), void 0, [() => Promise.reject('no no no')]);
$.append($$anchor, text_1);
};

@ -26,7 +26,7 @@ export default function Await_block_scope($$anchor) {
var text_1 = $.sibling(node);
$.template_effect([], () => {
$.template_effect(() => {
$.set_text(text, `clicks: ${counter.count ?? ''}`);
$.set_text(text_1, ` ${counter.count ?? ''}`);
});

@ -30,6 +30,6 @@ export default function Bind_component_snippet($$anchor) {
var text_1 = $.sibling(node);
$.template_effect([], () => $.set_text(text_1, ` value: ${$.get(value) ?? ''}`));
$.template_effect(() => $.set_text(text_1, ` value: ${$.get(value) ?? ''}`));
$.append($$anchor, fragment);
}

@ -25,10 +25,9 @@ export default function Main($$anchor) {
var svg_1 = $.sibling(div_1, 2);
var custom_element_1 = $.sibling(svg_1, 2);
$.template_effect([], () => $.set_custom_element_data(custom_element_1, 'fooBar', y()));
$.template_effect(() => $.set_custom_element_data(custom_element_1, 'fooBar', y()));
$.template_effect(
[],
($0, $1) => {
$.set_attribute(div_1, 'foobar', $0);
$.set_attribute(svg_1, 'viewBox', $1);

@ -11,7 +11,7 @@ export default function Each_string_template($$anchor) {
var text = $.text();
$.template_effect([], () => $.set_text(text, `${thing ?? ''}, `));
$.template_effect(() => $.set_text(text, `${thing ?? ''}, `));
$.append($$anchor, text);
});

@ -20,7 +20,7 @@ export default function Function_prop_no_getter($$anchor) {
var text = $.text();
$.template_effect([], () => $.set_text(text, `clicks: ${$.get(count) ?? ''}`));
$.template_effect(() => $.set_text(text, `clicks: ${$.get(count) ?? ''}`));
$.append($$anchor, text);
},

@ -26,7 +26,7 @@ export default function Nullish_coallescence_omittance($$anchor) {
var h1_1 = $.sibling(button, 2);
h1_1.textContent = 'Hello, world';
$.template_effect([], () => $.set_text(text, `Count is ${$.get(count) ?? ''}`));
$.template_effect(() => $.set_text(text, `Count is ${$.get(count) ?? ''}`));
$.append($$anchor, fragment);
}

@ -44,6 +44,6 @@ export default function Skip_static_subtree($$anchor, $$props) {
var img = $.sibling(select, 2);
$.next(2);
$.template_effect([], () => $.set_text(text, $$props.title));
$.template_effect(() => $.set_text(text, $$props.title));
$.append($$anchor, fragment);
}

@ -19,6 +19,6 @@ export default function Text_nodes_deriveds($$anchor) {
var text = $.child(p);
$.reset(p);
$.template_effect([], ($0, $1) => $.set_text(text, `${$0 ?? ''}${$1 ?? ''}`), [text1, text2]);
$.template_effect(($0, $1) => $.set_text(text, `${$0 ?? ''}${$1 ?? ''}`), [text1, text2]);
$.append($$anchor, p);
}
Loading…
Cancel
Save