blockless
Rich Harris 10 months ago
parent 0545dbf534
commit 34f31986ff

@ -354,7 +354,7 @@ export function each_keyed(anchor_node, collection, flags, key_fn, render_fn, fa
* @param {Element | Comment} anchor_node
* @param {() => V[]} collection
* @param {number} flags
* @param {(anchor: Element | Comment | null, item: V, index: import('../../types.js').MaybeSignal<number>) => void} render_fn
* @param {(anchor: Element | Comment | null, item: V | (() => V), index: import('../../types.js').MaybeSignal<number>) => void} render_fn
* @param {null | ((anchor: Node) => void)} fallback_fn
* @returns {void}
*/

@ -291,7 +291,7 @@ export function pause_effect(effect, done) {
}
/**
* @param {import('../types.js').ComputationSignal} effect
* @param {import('../types.js').BlockEffect} effect
* @param {import('../types.js').TransitionObject[]} transitions
*/
function pause_children(effect, transitions) {
@ -309,7 +309,7 @@ function pause_children(effect, transitions) {
}
/**
* @param {import('../types.js').ComputationSignal} effect
* @param {import('../types.js').BlockEffect} effect
*/
export function destroy_effect(effect) {
// TODO call cleanup functions (but not sure when exactly?)
@ -328,7 +328,7 @@ export function destroy_effect(effect) {
}
/**
* @param {import('../types.js').ComputationSignal} effect
* @param {import('../types.js').BlockEffect} effect
*/
export function resume_effect(effect) {
if (effect.r) {
@ -339,7 +339,9 @@ export function resume_effect(effect) {
effect.f ^= INERT;
for (const transition of effect.in) {
transition.to(1);
if (effect.in) {
for (const transition of effect.in) {
transition.to(1);
}
}
}

@ -268,7 +268,8 @@ export function comment(anchor) {
*/
function close_template(dom, is_fragment, anchor) {
const block = /** @type {import('./types.js').Block} */ (current_block);
const effect = current_effect;
const effect = /** @type {import('./types.js').BlockEffect} */ (current_effect);
/** @type {import('./types.js').TemplateNode | Array<import('./types.js').TemplateNode>} */
const current = is_fragment
@ -1632,16 +1633,17 @@ export function element(anchor_node, tag_fn, is_svg, render_fn) {
}
/**
* @template P
* @template {Record<string, any>} P
* @template {(node: Node, props: P) => void} C
* @param {Comment} anchor_node
* @param {() => (props: P) => void} component_fn
* @param {(component: (props: P) => void) => void} render_fn
* @param {() => C} component_fn
* @param {(component: C) => void} render_fn
* @returns {void}
*/
export function component(anchor_node, component_fn, render_fn) {
hydrate_block_anchor(anchor_node);
/** @type {TODO} */
/** @type {C | null} */
let Component = null;
/** @type {import('./types.js').ComputationSignal | null} */
@ -1658,7 +1660,7 @@ export function component(anchor_node, component_fn, render_fn) {
}
if (Component) {
effect = render_effect(() => render_fn(Component), {}, true);
effect = render_effect(() => render_fn(/** @type {C} */ (Component)), {}, true);
}
});
}
@ -1769,7 +1771,7 @@ export function transition(dom, get_transition_fn, props, global = false) {
* @returns {void}
*/
export function animate(dom, get_transition_fn, props) {
bind_transition(dom, get_transition_fn, props, 'key', false);
throw new Error('TODO animate');
}
/**

@ -509,7 +509,7 @@ function is_transition_block(block) {
* @returns {void}
*/
export function bind_transition(element, get_fn, get_params, direction, global) {
const effect = /** @type {import('./types.js').EffectSignal} */ (current_effect);
const effect = /** @type {import('./types.js').BlockEffect} */ (current_effect);
let p = direction === 'out' ? 1 : 0;

@ -121,6 +121,12 @@ export type ComputationSignal<V = unknown> = {
w: number;
};
export type BlockEffect<V = unknown> = ComputationSignal<V> & {
in?: TransitionObject[];
out?: TransitionObject[];
dom?: TemplateNode | Array<TemplateNode>;
};
export type Signal<V = unknown> = SourceSignal<V> | ComputationSignal<V>;
export type SignalDebug<V = unknown> = SourceSignalDebug & Signal<V>;

@ -34,7 +34,11 @@ class Animation {
#keyframes;
#duration;
#target;
/** @type {() => void} */
#finished;
/** @type {() => void} */
#cancelled;
/**
@ -48,12 +52,17 @@ class Animation {
this.#duration = options.duration || 0;
this.currentTime = 0;
this.#finished = () => {};
this.#cancelled = () => {};
// Promise-like semantics, but call callbacks immediately on raf.tick
this.finished = {
/** @param {() => void} callback */
then: (callback) => {
this.#finished = callback;
return {
/** @param {() => void} callback */
catch: (callback) => {
this.#cancelled = callback;
}

Loading…
Cancel
Save