simplify render_effect signature (#10925)

* simplify render_effect signature

* lint
pull/10927/head
Rich Harris 1 year ago committed by GitHub
parent 59ff650ccb
commit b7a0d80bfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -36,8 +36,7 @@ export function key_block(anchor, get_key, render_fn) {
}); });
} }
effect = render_effect( effect = render_effect(() => {
() => {
const dom = render_fn(anchor); const dom = render_fn(anchor);
return () => { return () => {
@ -45,10 +44,7 @@ export function key_block(anchor, get_key, render_fn) {
remove(dom); remove(dom);
} }
}; };
}, }, true);
true,
true
);
effects.add(effect); effects.add(effect);
} }

@ -1,5 +1,5 @@
import { hydrating } from '../hydration.js'; import { hydrating } from '../hydration.js';
import { render_effect } from '../../reactivity/effects.js'; import { user_effect } from '../../reactivity/effects.js';
/** /**
* @param {HTMLElement} dom * @param {HTMLElement} dom
@ -10,15 +10,12 @@ export function autofocus(dom, value) {
if (value) { if (value) {
const body = document.body; const body = document.body;
dom.autofocus = true; dom.autofocus = true;
render_effect(
() => { user_effect(() => {
if (document.activeElement === body) { if (document.activeElement === body) {
dom.focus(); dom.focus();
} }
}, });
true,
false
);
} }
} }

@ -216,14 +216,13 @@ export function invalidate_effect(fn) {
/** /**
* @param {(() => void)} fn * @param {(() => void)} fn
* @param {boolean} managed * @param {boolean} managed
* @param {boolean} sync
* @returns {import('#client').Effect} * @returns {import('#client').Effect}
*/ */
export function render_effect(fn, managed = false, sync = true) { export function render_effect(fn, managed = false) {
let flags = RENDER_EFFECT; let flags = RENDER_EFFECT;
if (managed) flags |= MANAGED; if (managed) flags |= MANAGED;
return create_effect(flags, /** @type {any} */ (fn), sync); return create_effect(flags, /** @type {any} */ (fn), true);
} }
/** /**

@ -22,13 +22,9 @@ function run_test(runes: boolean, fn: (runes: boolean) => () => void) {
$.push({}, runes); $.push({}, runes);
// Create a render context so that effect validations etc don't fail // Create a render context so that effect validations etc don't fail
let execute: any; let execute: any;
const signal = render_effect( const signal = render_effect(() => {
() => {
execute = fn(runes); execute = fn(runes);
}, }, true);
true,
true
);
$.pop(); $.pop();
execute(); execute();
destroy_effect(signal); destroy_effect(signal);

Loading…
Cancel
Save