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