Actualizar sigworkPro.js
This commit is contained in:
@@ -128,16 +128,16 @@ const trigger = (subs) => {
|
|||||||
|
|
||||||
export const $ = (initialValue) => {
|
export const $ = (initialValue) => {
|
||||||
const subs = new Set();
|
const subs = new Set();
|
||||||
return {
|
return (newVal) => {
|
||||||
get value() {
|
if (newVal === undefined) {
|
||||||
track(subs);
|
track(subs);
|
||||||
return initialValue;
|
return initialValue;
|
||||||
},
|
}
|
||||||
set value(newVal) {
|
if (!Object.is(newVal, initialValue)) {
|
||||||
if (Object.is(newVal, initialValue)) return;
|
|
||||||
initialValue = newVal;
|
initialValue = newVal;
|
||||||
trigger(subs);
|
trigger(subs);
|
||||||
},
|
}
|
||||||
|
return initialValue;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ export const persistent = (initialValue, storageKey) => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
const sig = $(stored);
|
const sig = $(stored);
|
||||||
Watch(() => {
|
Watch(() => {
|
||||||
localStorage.setItem(storageKey, JSON.stringify(sig.value));
|
localStorage.setItem(storageKey, JSON.stringify(sig()));
|
||||||
});
|
});
|
||||||
return sig;
|
return sig;
|
||||||
};
|
};
|
||||||
@@ -163,28 +163,27 @@ export const computed = (fn) => {
|
|||||||
if (!Object.is(newValue, cachedValue)) {
|
if (!Object.is(newValue, cachedValue)) {
|
||||||
cachedValue = newValue;
|
cachedValue = newValue;
|
||||||
dirty = false;
|
dirty = false;
|
||||||
s.value = newValue;
|
s(newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (currentComponentContext) {
|
if (currentComponentContext) {
|
||||||
currentComponentContext.unmount.push(stop);
|
currentComponentContext.unmount.push(stop);
|
||||||
}
|
}
|
||||||
return {
|
const signal = () => {
|
||||||
get value() {
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
cachedValue = fn();
|
cachedValue = fn();
|
||||||
dirty = false;
|
dirty = false;
|
||||||
s.value = cachedValue;
|
s(cachedValue);
|
||||||
}
|
|
||||||
return s.value;
|
|
||||||
}
|
}
|
||||||
|
return s();
|
||||||
};
|
};
|
||||||
|
return signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const watch = (source, callback) => {
|
export const watch = (source, callback) => {
|
||||||
let first = true, oldVal;
|
let first = true, oldVal;
|
||||||
return Watch(() => {
|
return Watch(() => {
|
||||||
const newVal = isFunction(source) ? source() : source.value;
|
const newVal = isFunction(source) ? source() : source;
|
||||||
if (!first) untrack(() => callback(newVal, oldVal));
|
if (!first) untrack(() => callback(newVal, oldVal));
|
||||||
else first = false;
|
else first = false;
|
||||||
oldVal = newVal;
|
oldVal = newVal;
|
||||||
@@ -401,11 +400,11 @@ export const Router = ({ routes }) => {
|
|||||||
const outlet = Tag('div', { class: 'router-outlet' });
|
const outlet = Tag('div', { class: 'router-outlet' });
|
||||||
const getHash = () => window.location.hash.slice(1) || '/';
|
const getHash = () => window.location.hash.slice(1) || '/';
|
||||||
const path = $(getHash());
|
const path = $(getHash());
|
||||||
const handler = () => { path.value = getHash(); };
|
const handler = () => { path(getHash()); };
|
||||||
window.addEventListener('hashchange', handler);
|
window.addEventListener('hashchange', handler);
|
||||||
onUnmount(() => window.removeEventListener('hashchange', handler));
|
onUnmount(() => window.removeEventListener('hashchange', handler));
|
||||||
Watch(() => {
|
Watch(() => {
|
||||||
const current = path.value;
|
const current = path();
|
||||||
const matched = routes.find(r => {
|
const matched = routes.find(r => {
|
||||||
const rSeg = r.path.split('/').filter(Boolean);
|
const rSeg = r.path.split('/').filter(Boolean);
|
||||||
const pSeg = current.split('/').filter(Boolean);
|
const pSeg = current.split('/').filter(Boolean);
|
||||||
|
|||||||
Reference in New Issue
Block a user