Skip to content

Specify best practices for sequence/FrozenArray/ObservableArray #1495

@tabatkins

Description

@tabatkins

What is the issue with the Web IDL Standard?

There's a lot of legacy APIs that were created before ObservableArray was added, so we have a panoply of behaviors across the web. It's very difficult for spec authors to know which of the three types they should use for representing some array value.

I think the basic summary of best practices is:

  1. If you want to expose an array, and the values won't change from author or UA action, use a read-only FrozenArray.
  2. If you want to expose an array, and the values are changeable from author action (and possibly from UA action), use an ObservableArray.
  3. If you want to expose an array, and the values are only changeable from UA action, choose between a read-only FrozenArray (especially if authors will want to poll the values frequently) and a method that returns a sequence. Consider exposing a promise-returning method to let authors wait for updates, if changes are infrequent, so they don't have to poll. (Frequently-changing values are fine to poll for, usually.)

Notably, I think best practice should warn against using a mutable FrozenArray; this was used in the past to allow replacing the value wholesale (there's even an example of that exact behavior in the FrozenArray section), but if you allow replacing all of the items, you should allow replacing individual items as well, and just use an ObservableArray.

Thoughts?

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