use same codepath

pull/13282/head
Dominic Gannaway 2 years ago
parent a51905951b
commit 0eca0ce1a6

@ -10,7 +10,7 @@ function setup() {
let computed4 = $.derived(() => $.get(computed3) + 2);
let computed5 = $.derived(() => $.get(computed4) + 3);
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(computed5);
busy(); // heavy side effect
@ -62,7 +62,7 @@ export async function kairo_avoidable_unowned() {
export async function kairo_avoidable_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -6,7 +6,7 @@ function setup() {
let last = head;
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
for (let i = 0; i < 50; i++) {
let current = $.derived(() => {
return $.get(head) + i;
@ -68,7 +68,7 @@ export async function kairo_broad_unowned() {
export async function kairo_broad_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
}
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -68,7 +68,7 @@ export async function kairo_deep_unowned() {
export async function kairo_deep_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -18,7 +18,7 @@ function setup() {
});
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(sum);
counter++;
@ -72,7 +72,7 @@ export async function kairo_diamond_unowned() {
export async function kairo_diamond_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -10,7 +10,7 @@ function setup() {
.map((_, index) => $.derived(() => $.get(mux)[index]))
.map((x) => $.derived(() => $.get(x) + 1));
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
splited.forEach((x) => {
$.render_effect(() => {
$.get(x);
@ -65,7 +65,7 @@ export async function kairo_mux_unowned() {
export async function kairo_mux_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -69,7 +69,7 @@ export async function kairo_repeated_unowned() {
export async function kairo_repeated_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -27,7 +27,7 @@ function setup() {
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(sum);
counter++;
@ -82,7 +82,7 @@ export async function kairo_triangle_unowned() {
export async function kairo_triangle_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -15,7 +15,7 @@ function setup() {
let counter = 0;
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
$.get(current);
counter++;
@ -68,7 +68,7 @@ export async function kairo_unstable_unowned() {
export async function kairo_unstable_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -32,7 +32,7 @@ function setup() {
const F = $.derived(() => hard($.get(D)[0] && $.get(B)));
const G = $.derived(() => $.get(C) + ($.get(C) || $.get(E) % 2) + $.get(D)[0] + $.get(F));
const destroy = $.user_effect_root(() => {
const destroy = $.effect_root(() => {
$.render_effect(() => {
res.push(hard($.get(G)));
});
@ -67,7 +67,7 @@ function setup() {
export async function mol_bench_owned() {
let run, destroy;
const destroy_owned = $.user_effect_root(() => {
const destroy_owned = $.effect_root(() => {
// Do 10 loops to warm up JIT
for (let i = 0; i < 10; i++) {
const { run, destroy } = setup();

@ -26,7 +26,7 @@ export function CallExpression(node, context) {
case '$effect.root':
return b.call(
'$.user_effect_root',
'$.effect_root',
.../** @type {Expression[]} */ (node.arguments.map((arg) => context.visit(arg)))
);

@ -96,7 +96,7 @@ export {
export { derived, derived_safe_equal } from './reactivity/deriveds.js';
export {
effect_tracking,
user_effect_root,
effect_root,
legacy_pre_effect,
legacy_pre_effect_reset,
render_effect,

@ -39,7 +39,7 @@ import {
import { set } from './sources.js';
import * as e from '../errors.js';
import { DEV } from 'esm-env';
import { define_property } from '../../shared/utils.js';
import { define_property, noop } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
/**
@ -133,6 +133,7 @@ function create_effect(type, fn, sync, push = true) {
// if an effect has no dependencies, no DOM and no teardown function,
// don't bother adding it to the effect tree
debugger;
var inert =
sync &&
effect.deps === null &&
@ -232,27 +233,28 @@ export function inspect_effect(fn) {
}
/**
* Internal representation of `$effect.root(...)`
* @param {() => void | (() => void)} fn
* @returns {() => void}
*/
export function effect_root(fn) {
const effect = create_effect(ROOT_EFFECT, fn, true);
const effect = create_effect(
ROOT_EFFECT,
() => {
branch(() => {
// We return a noop if no function is returned to ensure that the branch
// is attached to the effect tree otherwise it will count as inert
return fn() || noop;
});
},
true
);
return () => {
destroy_effect(effect);
};
}
/**
* Internal representation of `$effect.root(...)`
* @param {() => void | (() => void)} fn
* @returns {() => void}
*/
export function user_effect_root(fn) {
return effect_root(() => {
branch(fn);
});
}
/**
* @param {() => void | (() => void)} fn
* @returns {Effect}

@ -10,7 +10,7 @@ import {
} from './dom/operations.js';
import { HYDRATION_END, HYDRATION_ERROR, HYDRATION_START } from '../../constants.js';
import { push, pop, component_context, active_effect } from './runtime.js';
import { effect_root, branch } from './reactivity/effects.js';
import { effect_root } from './reactivity/effects.js';
import {
hydrate_next,
hydrate_node,
@ -225,35 +225,33 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
var component = undefined;
var unmount = effect_root(() => {
branch(() => {
if (context) {
push({});
var ctx = /** @type {ComponentContext} */ (component_context);
ctx.c = context;
}
if (context) {
push({});
var ctx = /** @type {ComponentContext} */ (component_context);
ctx.c = context;
}
if (events) {
// We can't spread the object or else we'd lose the state proxy stuff, if it is one
/** @type {any} */ (props).$$events = events;
}
if (events) {
// We can't spread the object or else we'd lose the state proxy stuff, if it is one
/** @type {any} */ (props).$$events = events;
}
if (hydrating) {
assign_nodes(/** @type {TemplateNode} */ (anchor), null);
}
if (hydrating) {
assign_nodes(/** @type {TemplateNode} */ (anchor), null);
}
should_intro = intro;
// @ts-expect-error the public typings are not what the actual function looks like
component = Component(anchor, props) || {};
should_intro = true;
should_intro = intro;
// @ts-expect-error the public typings are not what the actual function looks like
component = Component(anchor, props) || {};
should_intro = true;
if (hydrating) {
/** @type {Effect} */ (active_effect).nodes_end = hydrate_node;
}
if (hydrating) {
/** @type {Effect} */ (active_effect).nodes_end = hydrate_node;
}
if (context) {
pop();
}
});
if (context) {
pop();
}
return () => {
for (var event_name of registered_events) {

@ -192,14 +192,14 @@ test('map handling of undefined values', () => {
render_effect(() => {
log.push(map.get(1));
});
});
flushSync(() => {
map.delete(1);
});
flushSync(() => {
map.delete(1);
});
flushSync(() => {
map.set(1, 1);
});
flushSync(() => {
map.set(1, 1);
});
assert.deepEqual(log, [undefined, undefined, 1]);
@ -220,14 +220,14 @@ test('not invoking reactivity when value is not in the map after changes', () =>
render_effect(() => {
log.push(map.get(2));
});
});
flushSync(() => {
map.delete(1);
});
flushSync(() => {
map.delete(1);
});
flushSync(() => {
map.set(1, 1);
});
flushSync(() => {
map.set(1, 1);
});
assert.deepEqual(log, [1, undefined, undefined, undefined, 1, undefined]);

@ -11,7 +11,7 @@ import {
} from 'svelte/store';
import { source, set } from '../../src/internal/client/reactivity/sources';
import * as $ from '../../src/internal/client/runtime';
import { user_effect_root, render_effect } from 'svelte/internal/client';
import { effect_root, render_effect } from 'svelte/internal/client';
describe('writable', () => {
it('creates a writable store', () => {
@ -645,7 +645,7 @@ describe('fromStore', () => {
const log: number[] = [];
const teardown = user_effect_root(() => {
const teardown = effect_root(() => {
render_effect(() => {
log.push(count.current);
});

Loading…
Cancel
Save