This commit is contained in:
Seth Trowbridge 2025-02-03 17:11:51 -05:00
parent ac9fa7ecea
commit d4aa91fe70

View File

@ -135,12 +135,7 @@ let update = (dom, newDom) => newDom ? newDom !== dom && dom.replaceWith(newDom)
/*********************************************** */
// Map to track state-to-DOM relationships
const stateDomMap = new Map();
function pathHash(/** @type {HTMLElement} */element) {
console.log(element);
const path = [];
let currentElement = element;
@ -162,13 +157,11 @@ function pathHash(/** @type {HTMLElement} */element) {
* @param {any} state - The state object being tracked.
* @param {Element} dom - The DOM element affected by the state.
*/
const trackStateDomRelationship = (state, dom, thing) => {
console.log(state, thing);
const hash = pathHash(dom);
if (!stateDomMap.has(hash)) {
stateDomMap.set(hash, new Set());
}
stateDomMap.get(hash).add(state);
const trackStateDomRelationship = (state, doms) => {
doms.forEach(dom => {
const hash = pathHash(dom);
stateDomMap.set(hash, state);
});
};
// Enhanced updateDoms function
@ -183,10 +176,6 @@ let updateDoms = () => {
// Process listeners for derived states
for (let l of new Set(derivedStatesArray.flatMap(s => s._listeners = keepConnected(s._listeners)))) {
derive(l.f, l.s, l._dom);
// Track which DOM element is being touched by this listener's state
if (l._dom) trackStateDomRelationship(l.s, l._dom);
l._dom = _undefined;
}
} while (++iter < 100 && (derivedStatesArray = [...derivedStates]).length);
@ -195,14 +184,13 @@ let updateDoms = () => {
let changedStatesArray = [...changedStates].filter(s => s.rawVal !== s._oldVal);
changedStates = _undefined;
for (let b of new Set(changedStatesArray.flatMap(s => s._bindings = keepConnected(s._bindings)))) {
// Track which DOM element is being touched by this binding's state
if (b._dom) trackStateDomRelationship(b.f, b._dom);
const _block = new Set(changedStatesArray.flatMap(s =>{
trackStateDomRelationship(s.rawVal, s._bindings.map(b=>b._dom))
return s._bindings = keepConnected(s._bindings);
}));
for (let b of _block) {
update(b._dom, bind(b.f, b._dom));
b._dom = _undefined;
}
@ -213,12 +201,7 @@ let updateDoms = () => {
};
// Debugging helper to log the state-DOM relationships
globalThis.Divulge = () => {
console.log("State-DOM Relationships:");
for (const [state, domSet] of stateDomMap.entries()) {
console.log(state, [...domSet]);
}
};
globalThis.Divulge = () => console.log(stateDomMap.entries());
globalThis.path = pathHash;
/*********************************************** */