-
Notifications
You must be signed in to change notification settings - Fork 66
refactor(react): replace prototype-walking and inferred class props #1376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
613dc1c
refactor(react)!: replace dynamic media prop spreading with explicit …
mihar-22 056d71e
refactor(packages): add shared media props interfaces, defaults, and …
mihar-22 762fcdc
fix(packages): use isUndefined check in useSyncProps and clone config…
mihar-22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,28 @@ | ||
| import { CastableMediaMixin } from '../castable'; | ||
| import { HlsMedia } from '../hls'; | ||
| import { MuxDataMediaMixin } from './mux-data'; | ||
| import { type CastableMediaProps, castableMediaDefaultProps } from '../castable/types'; | ||
| import { HlsMedia, type HlsMediaProps, hlsMediaDefaultProps } from '../hls'; | ||
| import { MuxDataMediaMixin, type MuxDataMediaProps, muxDataMediaDefaultProps } from './mux-data'; | ||
|
|
||
| export class MuxVideoMedia extends MuxDataMediaMixin(CastableMediaMixin(HlsMedia)) { | ||
| export type { CastableMediaProps, HlsMediaProps, MuxDataMediaProps }; | ||
|
|
||
| export interface MuxMediaProps extends HlsMediaProps, CastableMediaProps, MuxDataMediaProps { | ||
| castSrc: string | undefined; | ||
| } | ||
|
|
||
| export const muxMediaDefaultProps: MuxMediaProps = { | ||
| ...hlsMediaDefaultProps, | ||
| ...castableMediaDefaultProps, | ||
| ...muxDataMediaDefaultProps, | ||
| castSrc: undefined, | ||
| }; | ||
|
|
||
| export class MuxVideoMedia extends MuxDataMediaMixin(CastableMediaMixin(HlsMedia)) implements MuxMediaProps { | ||
| static PLAYER_SOFTWARE_NAME = 'mux-video'; | ||
| } | ||
|
|
||
| // TODO: HlsMedia extends HTMLVideoElementHost, we should extend | ||
| // HTMLAudioElementHost instead but this would require a HlsMediaMixin, | ||
| // keep it simple for now. | ||
| export class MuxAudioMedia extends MuxDataMediaMixin(CastableMediaMixin(HlsMedia)) { | ||
| export class MuxAudioMedia extends MuxDataMediaMixin(CastableMediaMixin(HlsMedia)) implements MuxMediaProps { | ||
| static PLAYER_SOFTWARE_NAME = 'mux-audio'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,33 @@ | ||
| import { MuxAudioMedia } from '@videojs/core/dom/media/mux'; | ||
| import type { InferClassProps } from '@videojs/utils/types'; | ||
| import type { AudioHTMLAttributes, PropsWithChildren } from 'react'; | ||
| 'use client'; | ||
|
|
||
| import type { MuxMediaProps } from '@videojs/core/dom/media/mux'; | ||
| import { MuxAudioMedia, muxMediaDefaultProps } from '@videojs/core/dom/media/mux'; | ||
| import type { AudioHTMLAttributes, ReactNode } from 'react'; | ||
| import { forwardRef } from 'react'; | ||
| import { attachMediaElement } from '../../utils/attach-media-element'; | ||
| import { mediaProps } from '../../utils/media-props'; | ||
| import { useAttachMedia } from '../../utils/use-attach-media'; | ||
| import { useComposedRefs } from '../../utils/use-composed-refs'; | ||
| import { useMediaInstance } from '../../utils/use-media-instance'; | ||
| import { useSyncProps } from '../../utils/use-sync-props'; | ||
|
|
||
| export type MuxAudioProps = PropsWithChildren<AudioHTMLAttributes<HTMLAudioElement>> & | ||
| InferClassProps<typeof MuxAudioMedia>; | ||
|
|
||
| export const MuxAudio = forwardRef<HTMLAudioElement, MuxAudioProps>(({ children, ...props }, ref) => { | ||
| const mediaApi = useMediaInstance(MuxAudioMedia); | ||
| export interface MuxAudioProps | ||
| extends Omit<AudioHTMLAttributes<HTMLAudioElement>, keyof MuxMediaProps>, | ||
| Partial<MuxMediaProps> { | ||
| children?: ReactNode; | ||
| } | ||
|
|
||
| const composedRef = useComposedRefs(attachMediaElement(mediaApi), ref); | ||
| export const MuxAudio = forwardRef<HTMLAudioElement, MuxAudioProps>(function MuxAudio({ children, ...props }, ref) { | ||
| const media = useMediaInstance(MuxAudioMedia); | ||
| const attachRef = useAttachMedia(media); | ||
| const composedRef = useComposedRefs(attachRef, ref); | ||
| const htmlProps = useSyncProps(media, props, muxMediaDefaultProps); | ||
|
|
||
| return ( | ||
| <audio ref={composedRef} {...mediaProps(mediaApi, MuxAudioMedia, props)}> | ||
| <audio ref={composedRef} {...htmlProps}> | ||
| {children} | ||
| </audio> | ||
| ); | ||
| }); | ||
|
|
||
| export default MuxAudio; | ||
| export namespace MuxAudio { | ||
| export type Props = MuxAudioProps; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.