Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for volatile functions #1

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Commits on Aug 18, 2024

  1. Init development environment

    Not intending to merge this. It supports my development environment on
    NixOS where deps like Node from Volta that dynamically link to a glibc
    interpreter are not executable.
    PsychoLlama committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    e8f5a43 View commit details
    Browse the repository at this point in the history
  2. Scaffold the volatile source type

    This introduces a new `Signal.Volatile` function. It follows the initial
    proposal here: tc39/proposal-signals#237
    
    Volatile sources bring outside data into the computation graph.
    PsychoLlama committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    4d054ad View commit details
    Browse the repository at this point in the history
  3. Implement cached lookups on observed volatile sources

    If volatile sources are given a subscriber and the source is being
    watched, now it returns from cache instead of querying `getSnapshot`
    every time `source.get()` is invoked.
    
    This only applies while being observed. When not observed, it fetches
    from the snapshot function every time.
    PsychoLlama committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    90b7711 View commit details
    Browse the repository at this point in the history
  4. Bust consumer caches that depend on volatile sources

    This causes the cache of `Signal.Computed` to be ignored and always
    re-evaluate if it depends on volatile sources. We have to do this
    because we don't know if the underlying sources changed since the last
    time it evaluated.
    
    When a volatile source upgrades to non-volatile (or is removed from the
    dependencies list), the downstream consumers can once again cache their
    evaluations.
    PsychoLlama committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    a1c9377 View commit details
    Browse the repository at this point in the history
  5. Implement volatile change notifications

    When a volatile signal is upgraded to a tracked source through
    `subscribe` it gets an `onChange` handler. Until this commit it was
    a no-op. Now the `onChange` handler causes consumers to mark the current
    value as dirty.
    
    There are currently no restricted contexts for `onChange`. It's
    conceivable we may want to restrict it.
    PsychoLlama committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    9bc421f View commit details
    Browse the repository at this point in the history

Commits on Aug 19, 2024

  1. Add support for sources in volatile signals

    Now volatile signals can depend on other signals inside `getSnapshot`.
    Is this desirable? I'm not sure yet, but without supporting it, there
    are unexpected edge cases. This is where the abstraction begins to leak
    a bit.
    PsychoLlama committed Aug 19, 2024
    Configuration menu
    Copy the full SHA
    75417af View commit details
    Browse the repository at this point in the history