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

Update JSdocs #1029

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
117 changes: 117 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"concurrently": "^7.1.0",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"dts-bundle-generator": "^7.2.0",
"esbuild": "^0.14.39",
"eslint": "^8.16.0",
"eslint-config-airbnb": "^19.0.4",
Expand Down
25 changes: 25 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface APITypes {
plyr: PlyrInstance;
}

/**
* It creates a new PlyrJS instance, and if a source is provided, it sets the source of the PlyrJS
* instance to the source provided
* @param _ - The current instance of the component.
chintan9 marked this conversation as resolved.
Show resolved Hide resolved
* @param params - The props passed to the component
chintan9 marked this conversation as resolved.
Show resolved Hide resolved
* @returns A function that takes two parameters and returns a new instance of PlyrJS.
chintan9 marked this conversation as resolved.
Show resolved Hide resolved
*/
/* REACT-APTOR */
const instantiate: Instantiate<
PlyrJS,
Expand All @@ -40,6 +47,10 @@ const instantiate: Instantiate<
return plyr;
};

/**
* It destroys the PlyrJS instance.
* @param {PlyrJS | null} plyr - PlyrJS | null
*/
const destroy: Destroy<PlyrJS, PlyrConfigurationProps> = (
plyr: PlyrJS | null
) => {
Expand All @@ -49,6 +60,11 @@ const destroy: Destroy<PlyrJS, PlyrConfigurationProps> = (
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

/**
* It returns an object with a `plyr` property that contains the Plyr instance
* @param {PlyrJS | null} plyr - PlyrJS | null
* @returns A function that returns an object with a single property, plyr.
*/
const getAPI: GetAPI<PlyrJS, PlyrConfigurationProps> = (
plyr: PlyrJS | null
) => {
Expand All @@ -72,6 +88,13 @@ const getAPI: GetAPI<PlyrJS, PlyrConfigurationProps> = (
});
};

/**
* It creates a React hook that returns a ref to a video element that is initialized with Plyr
* @param ref - Ref<APITypes>
chintan9 marked this conversation as resolved.
Show resolved Hide resolved
* @param {PlyrConfigurationProps} params - PlyrConfigurationProps,
* @param {DependencyList | null} [deps=null] - DependencyList | null = null
* @returns A function that returns a React component.
*/
export function usePlyr(
ref: Ref<APITypes>,
params: PlyrConfigurationProps,
Expand All @@ -89,6 +112,7 @@ export function usePlyr(
);
}

/* Creating a React component that is initialized with Plyr. */
const Plyr = React.forwardRef<APITypes, PlyrProps>((props, ref) => {
const { source, options = null, ...rest } = props;
const raptorRef = usePlyr(ref, {
Expand All @@ -98,6 +122,7 @@ const Plyr = React.forwardRef<APITypes, PlyrProps>((props, ref) => {
return <video ref={raptorRef} className="plyr-react plyr" {...rest} />;
});

/* Setting the default props and prop types for the component. */
if (__DEV__) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Plyr.displayName = "Plyr";
Expand Down