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

fix(types): fix and improve component ready callback definition #8766

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import {merge} from './utils/obj.js';

/** @import Player from './player' */

/**
* A callback to be called if and when the component is ready.
* `this` will be the Component instance.
*
* @callback ReadyCallback
* @returns {void}
*/

/**
* Base class for all UI Components.
* Components are UI objects which represent both a javascript object and an element
Expand All @@ -25,14 +33,6 @@ import {merge} from './utils/obj.js';
*/
class Component {

/**
* A callback that is called when a component is ready. Does not have any
* parameters and any callback value will be ignored.
*
* @callback ReadyCallback
* @this Component
*/

/**
* Creates an instance of this class.
*
Expand Down Expand Up @@ -837,9 +837,6 @@ class Component {
*
* @param {ReadyCallback} fn
* Function that gets called when the `Component` is ready.
*
* @return {Component}
* Returns itself; method can be chained.
*/
ready(fn, sync = false) {
if (!fn) {
Expand Down
8 changes: 7 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ import './tech/html5.js';
/** @import { TimeRange } from './utils/time' */
/** @import HtmlTrackElement from './tracks/html-track-element' */

/**
* @callback PlayerReadyCallback
* @this {Player}
* @returns {void}
*/

// The following tech events are simply re-triggered
// on the player when they happen
const TECH_EVENTS_RETRIGGER = [
Expand Down Expand Up @@ -306,7 +312,7 @@ class Player extends Component {
* @param {Object} [options]
* Object of option names and values.
*
* @param {Function} [ready]
* @param {PlayerReadyCallback} [ready]
* Ready callback function.
*/
constructor(tag, options, ready) {
Expand Down
11 changes: 3 additions & 8 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import xhr from '@videojs/xhr';
import Tech from './tech/tech.js';
import { use as middlewareUse, TERMINATOR } from './tech/middleware.js';

/** @import { PlayerReadyCallback } from './player' */

/**
* Normalize an `id` value by trimming off a leading `#`
*
Expand All @@ -53,13 +55,6 @@ import { use as middlewareUse, TERMINATOR } from './tech/middleware.js';
*/
const normalizeId = (id) => id.indexOf('#') === 0 ? id.slice(1) : id;

/**
* A callback that is called when a component is ready. Does not have any
* parameters and any callback value will be ignored. See: {@link Component~ReadyCallback}
*
* @callback ReadyCallback
*/

/**
* The `videojs()` function doubles as the main function for users to create a
* {@link Player} instance as well as the main library namespace.
Expand Down Expand Up @@ -121,7 +116,7 @@ const normalizeId = (id) => id.indexOf('#') === 0 ? id.slice(1) : id;
* Options object for providing settings.
* See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
*
* @param {ReadyCallback} [ready]
* @param {PlayerReadyCallback} [ready]
* A function to be called when the {@link Player} and {@link Tech} are
* ready.
*
Expand Down