Actualizar sigpro_work.js
This commit is contained in:
@@ -251,19 +251,43 @@ const Use = (key, defaultValue) => {
|
||||
return defaultValue;
|
||||
};
|
||||
|
||||
const If = (cond, a, b = null) => {
|
||||
const If = (cond, a, b = null, options = {}) => {
|
||||
const marker = createText("");
|
||||
const container = Tag("div", { style: "display:contents" }, [marker]);
|
||||
let view = null;
|
||||
let currentView = null;
|
||||
let lastState = null;
|
||||
|
||||
Watch(() => {
|
||||
const state = !!(typeof cond === "function" ? cond() : cond);
|
||||
if (view) view.destroy();
|
||||
if (state === lastState) return;
|
||||
lastState = state;
|
||||
|
||||
const branch = state ? a : b;
|
||||
const oldView = currentView;
|
||||
|
||||
if (oldView) {
|
||||
if (options.off) {
|
||||
options.off(oldView.container, () => oldView.destroy());
|
||||
} else {
|
||||
oldView.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (branch) {
|
||||
view = Render(() => typeof branch === "function" ? branch() : branch);
|
||||
container.insertBefore(view.container, marker);
|
||||
currentView = Render(() => typeof branch === "function" ? branch() : branch);
|
||||
const el = currentView.container;
|
||||
container.insertBefore(el, marker);
|
||||
|
||||
if (options.on) {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => options.on(el));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
currentView = null;
|
||||
}
|
||||
});
|
||||
|
||||
return container;
|
||||
};
|
||||
|
||||
@@ -336,7 +360,7 @@ const Mount = (component, target) => {
|
||||
return instance;
|
||||
};
|
||||
|
||||
const SigPro = { $, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
|
||||
const SigPro = { $, $$, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
Object.assign(window, SigPro);
|
||||
@@ -350,5 +374,5 @@ if (typeof window !== "undefined") {
|
||||
window.SigPro = Object.freeze(SigPro);
|
||||
}
|
||||
|
||||
export { $, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
|
||||
export { $, $$, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
|
||||
export default SigPro;
|
||||
Reference in New Issue
Block a user