Skip to content

It should be possible to perform incremental updates to large/complex variable values without blowing the entire variable value away #196

Description

@jswalden

youtube-live has all sorts of variables named broadcast_${broadcastID}_{datum} and similar, for datum=health/state and for all broadcasts that have been fetched. It also has unfinished_${i}_{datum}, for datum=state/id/name/shortName/health/etc. (The numbers of broadcast IDs, and of unfinished broadcasts to expose, depend on configuration options.)

The module presently, therefore, exposes a huge mess of flat variables. Conveniently, in some cases where it needs a refresh of the state of a single broadcast, it can therefore update only the few variables that pertain to that broadcast.

When variable values can be JSONValue, it'd be saner to have type YouTubeVariables = { broadcasts: Record<BroadcastID, { health, state }>; unfinishedBroadcasts: { state; id; name; shortName; health }[] };. But then you lose ability to do narrow updating of only the data pertinent to one broadcast -- you'd have to update all of broadcasts (and possibly unfinishedBroadcasts) if you had fresh info for one broadcast in both.

(It is difficult to stick with the existing mess of flat variables, as TypeScript doesn't have good understanding of template string-keyed fields of varying type within the same object -- ultimately degrading key type to string and value type to a union of all property value types.)

I could imagine a registry-style API where you can specify paths into a config store (initial leaf being the name of a variable) and only update those specific paths, without throwing out the rest of the system. But I haven't thought at too much length about all this, and there might well be a better/cleaner way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions