Skip to content

Guidance for readyState fields #605

@LeaVerou

Description

@LeaVerou

These are all over the place.

Types:

  • FileReader, EventSource, HTMLMediaElement, IDBRequest, XMLHttpRequest, WebSocket use numbers (as static constants on the class)
  • Document, MediaSource, RTCDataChannel use strings

There is the existing guidance to use strings for enums, though number constants do have the nice property that comparisons are possible (e.g. this.readyState >= Foo.LOADING), and seem much more prevalent.

The states themselves are also all over the place:

  • Document: loading, interactive, complete
  • MediaSource: closed, open, ended
  • FileReader: empty, loading, done
  • EventSource: connecting, open, closed
  • HTMLMediaElement: have nothing, have metadata, have current data, have future data, have enough data
  • HTMLTrackElement: none, loading, loaded, error
  • IDBRequest: pending, done
  • XMLHttpRequest: unsent, opened, headers received, loading, done
  • WebSocket: connecting, open, closing, closed

Of course these cannot be completely harmonized since the use cases are different, but I suspect there is some guidance that can be extracted to apply to future classes…

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