Rescan when a fragment changes, to keep property monitor event handlers installed

This commit is contained in:
Tony Garnock-Jones 2022-01-12 15:44:06 +01:00
parent 419adba79b
commit cc3fac620c
1 changed files with 23 additions and 9 deletions

View File

@ -423,18 +423,32 @@ function spawnUIChangeablePropertyFactory(ds: Ref) {
\Q.lit($property: string),
\_)
}) => spawn named ['UIChangeableProperty', selector, property] {
selectorMatch(document.body, selector).forEach(node => {
field needRescan: boolean = false;
on asserted P.UIFragmentVersion($_i, $_v) => needRescan.value = true;
// TODO: don't be so crude about this ^. On the one hand, this
// lets us ignore UIFragmentVersion records coming and going; on
// the other hand, we do potentially a lot of redundant work.
function installOrReplaceHandlers() {
react {
field propValue: any = (node as any)[property];
assert P.UIChangeableProperty(selector, property, propValue.value);
const facet = Turn.activeFacet;
const handlerClosure = (_e: Event) => facet.turn(() => {
propValue.value = (node as any)[property];
selectorMatch(document.body, selector).forEach(node => {
field propValue: any = (node as any)[property];
assert P.UIChangeableProperty(selector, property, propValue.value);
const facet = Turn.activeFacet;
const handlerClosure = (_e: Event) => facet.turn(() => {
propValue.value = (node as any)[property];
});
eventUpdater('change', handlerClosure, true)(node);
on stop eventUpdater('change', handlerClosure, false)(node);
});
eventUpdater('change', handlerClosure, true)(node);
on stop eventUpdater('change', handlerClosure, false)(node);
stop on (needRescan.value) {
needRescan.value = false;
installOrReplaceHandlers();
}
}
});
}
installOrReplaceHandlers();
}
}
}