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

Put custom event definitions into externs #1564

Open
joeyparrish opened this issue Aug 28, 2018 · 1 comment · May be fixed by #7640
Open

Put custom event definitions into externs #1564

joeyparrish opened this issue Aug 28, 2018 · 1 comment · May be fixed by #7640
Assignees
Labels
priority: P3 Useful but not urgent type: enhancement New feature or request
Milestone

Comments

@joeyparrish
Copy link
Member

Right now, the events we dispatch are only described at the jsdoc level, not in any actual Closure types. For example:

/**
 * @event shaka.Player.ErrorEvent
 * @description Fired when a playback error occurs.
 * @property {string} type
 *   'error'
 * @property {!shaka.util.Error} detail
 *   An object which contains details on the error.  The error's 'category' and
 *   'code' properties will identify the specific error that occurred.  In an
 *   uncompiled build, you can also use the 'message' and 'stack' properties
 *   to debug.
 * @exportDoc
 */

It would be ideal to make these part of the generated externs, so that projects building with Closure (and some day TypeScript (#1273)) could use these event types.

To do that, I'm not sure of the best approach. Probably, the event types should be promoted to proper types in Closure. Then the existing extern generator could pick them up and describe them.

@joeyparrish joeyparrish added the type: enhancement New feature or request label Aug 28, 2018
@shaka-bot shaka-bot added this to the Backlog milestone Aug 28, 2018
@joeyparrish joeyparrish modified the milestones: Backlog, Backlog 2 Jan 28, 2020
@joeyparrish joeyparrish added the priority: P3 Useful but not urgent label Sep 29, 2021
@joeyparrish
Copy link
Member Author

A pattern that should work is to have an actual class for each event. For example, shaka.Player.ErrorEvent = class { ... }

The constructor takes all the necessary parameters, like the error object (shaka.util.Error), but the constructor would hard-code the type constant (like "error"). These would all inherit from shaka.util.FakeEvent.

So instead of the player calling this very generic utility for constructing FakeEvent instances:

const event = shaka.Player.makeEvent_(
    shaka.util.FakeEvent.EventName.Error,
    (new Map()).set('detail', error));

you would simply call the constructor for that specific event type:

const event = new shaka.Player.ErrorEvent(error);

This is much cleaner, and the types would be automatically documented.

@avelad avelad self-assigned this Nov 20, 2024
@avelad avelad modified the milestones: Backlog, v4.13 Nov 20, 2024
@avelad avelad linked a pull request Nov 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: P3 Useful but not urgent type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants