chore: remove managed_effect (#10926)

* chore: remove managed_effect

* remove managed_pre_effect
pull/10927/head
Rich Harris 9 months ago committed by GitHub
parent bbd44e9e47
commit 7a17e21f8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,5 +1,5 @@
import { hydrating } from '../../hydration.js'; import { hydrating } from '../../hydration.js';
import { destroy_effect, managed_effect, render_effect } from '../../../reactivity/effects.js'; import { render_effect, user_effect } from '../../../reactivity/effects.js';
import { listen } from './shared.js'; import { listen } from './shared.js';
/** @param {TimeRanges} ranges */ /** @param {TimeRanges} ranges */
@ -115,32 +115,9 @@ export function bind_ready_state(media, update) {
export function bind_playback_rate(media, get_value, update) { export function bind_playback_rate(media, get_value, update) {
var updating = false; var updating = false;
var callback = () => {
if (!updating) {
update(media.playbackRate);
}
updating = false;
};
// Needs to happen after the element is inserted into the dom, else playback will be set back to 1 by the browser. // Needs to happen after the element is inserted into the dom, else playback will be set back to 1 by the browser.
// For hydration we could do it immediately but the additional code is not worth the lost microtask. // For hydration we could do it immediately but the additional code is not worth the lost microtask.
user_effect(() => {
/** @type {import('#client').Effect | undefined} */
var render;
var destroyed = false;
var effect = managed_effect(() => {
destroy_effect(effect);
if (destroyed) return;
if (get_value() == null) {
callback();
}
listen(media, ['ratechange'], callback, false);
render = render_effect(() => {
var value = get_value(); var value = get_value();
// through isNaN we also allow number strings, which is more robust // through isNaN we also allow number strings, which is more robust
@ -148,14 +125,11 @@ export function bind_playback_rate(media, get_value, update) {
updating = true; updating = true;
media.playbackRate = /** @type {number} */ (value); media.playbackRate = /** @type {number} */ (value);
} }
});
});
render_effect(() => () => { listen(media, ['ratechange'], () => {
destroyed = true; if (!updating) update(media.playbackRate);
if (render) { updating = false;
destroy_effect(render); });
}
}); });
} }

@ -128,22 +128,6 @@ export function effect(fn) {
return create_effect(EFFECT, fn, false); return create_effect(EFFECT, fn, false);
} }
/**
* @param {() => void | (() => void)} fn
* @returns {import('#client').Effect}
*/
export function managed_effect(fn) {
return create_effect(EFFECT | MANAGED, fn, false);
}
/**
* @param {() => void | (() => void)} fn
* @returns {import('#client').Effect}
*/
export function managed_pre_effect(fn) {
return create_effect(PRE_EFFECT | MANAGED, fn, false);
}
/** /**
* Internal representation of `$effect.pre(...)` * Internal representation of `$effect.pre(...)`
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn

@ -1,8 +1,8 @@
// @ts-ignore // @ts-ignore
import { hydrate, unmount } from 'svelte'; import { mount, unmount } from 'svelte';
// @ts-ignore you need to create this file // @ts-ignore you need to create this file
import App from './App.svelte'; import App from './App.svelte';
const component = hydrate(App, { const component = mount(App, {
target: document.getElementById('root')! target: document.getElementById('root')!
}); });
// @ts-ignore // @ts-ignore

Loading…
Cancel
Save