Skip to content

Truly independent web browser

3.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    input:checked { color: rgb(0, 128, 0) }
    button:disabled { color: rgb(0, 0, 255) }
    .row :checked + .label { color: rgb(255, 0, 0) }
    /* A compound whose only feature is the state, so the state is the subject's own dispatch key. */
    :checked { outline-color: rgb(0, 128, 0) }
    :disabled { outline-color: rgb(0, 0, 255) }
    .guard :checked { border-top-color: rgb(0, 128, 0) }
</style>
<div id="fixture">
    <div class="row">
        <input id="box" type="checkbox">
        <span id="label" class="label"></span>
        <button id="control"></button>
    </div>
</div>
<script>
    // A pseudo-class state is journaled as its own input rather than as a local feature, so the
    // set of features a transaction has in flux never names one. Narrowing reads a state straight
    // off the element's fact row, which describes the state the element ended up in, so an element
    // leaving a state has to be planned by the route the state change itself takes.
    let forced = 0;

    function snapshot() {
        return Array.from(document.querySelectorAll("#fixture *"))
            .map(element => {
                const style = getComputedStyle(element);
                return `${element.id}=${style.color}/${style.outlineColor}/${style.borderTopColor}`;
            })
            .join(" ");
    }

    function settlesExactly(name, mutate) {
        internals.updateStyle();
        mutate();
        internals.updateStyle();
        const incremental = snapshot();
        CSS.registerProperty({ name: `--force-${forced++}`, syntax: "*", inherits: false, initialValue: "1px" });
        internals.updateStyle();
        const complete = snapshot();
        if (incremental === complete) {
            println(`${name}: settles exactly`);
            return;
        }
        println(`${name}: STALE`);
        println(`  incremental: ${incremental}`);
        println(`  complete:    ${complete}`);
    }

    test(() => {
        const box = document.getElementById("box");
        const control = document.getElementById("control");

        settlesExactly("the box becomes checked", () => (box.checked = true));
        settlesExactly("and is unchecked again", () => (box.checked = false));
        settlesExactly("the control becomes disabled", () => (control.disabled = true));
        settlesExactly("and is enabled again", () => (control.disabled = false));

        // The state leaves in the same transaction as an unrelated feature arrives, so the route
        // from that feature streams a region while the state the subject names is still moving.
        const row = document.querySelector(".row");
        settlesExactly("a guard arrives as the box becomes checked", () => {
            row.classList.add("guard");
            box.checked = true;
        });
        settlesExactly("the box is unchecked while the guard leaves", () => {
            row.classList.remove("guard");
            box.checked = false;
        });
    });
</script>