If con transicion enter / exit
This commit is contained in:
11
sw.js
11
sw.js
@@ -214,14 +214,19 @@ const append = (parent, child) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Control Flow & Built-in Components ---
|
// --- Control Flow & Built-in Components ---
|
||||||
export const If = (condition, renderFn, fallback = null) => {
|
export const If = (condition, renderFn, fallback = null, trans = {}) => {
|
||||||
let cachedNode, currentCondition;
|
let cachedNode, currentCondition;
|
||||||
return () => {
|
return () => {
|
||||||
const show = !!condition();
|
const show = !!get(condition);
|
||||||
if (show !== currentCondition) {
|
if (show !== currentCondition) {
|
||||||
|
currentCondition = show;
|
||||||
if (cachedNode) remove(cachedNode);
|
if (cachedNode) remove(cachedNode);
|
||||||
cachedNode = show ? render(renderFn) : (isFunction(fallback) ? render(fallback) : fallback);
|
cachedNode = show ? render(renderFn) : (isFunction(fallback) ? render(fallback) : fallback);
|
||||||
currentCondition = show;
|
if (isNode(cachedNode)) {
|
||||||
|
if (trans.enter) cachedNode.$enterTransition = trans.enter;
|
||||||
|
if (trans.exit) cachedNode.$leaveTransition = (done) => trans.exit(cachedNode, done);
|
||||||
|
cachedNode.$enterTransition?.(cachedNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cachedNode;
|
return cachedNode;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user