Skip to content

Commit

Permalink
Merge pull request #39 from jaaneh/fix/defaultprops-to-default-params
Browse files Browse the repository at this point in the history
fix/defaultprops to default params
  • Loading branch information
moonstar-x authored Jan 6, 2024
2 parents c198a9f + 389b090 commit 8a3e15c
Show file tree
Hide file tree
Showing 7 changed files with 4,119 additions and 24,011 deletions.
27,951 changes: 4,066 additions & 23,885 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-twitch-embed",
"version": "3.0.1",
"version": "3.0.2",
"description": "A collection of components to embed Twitch.",
"author": "moonstar-x",
"license": "MIT",
Expand Down
17 changes: 4 additions & 13 deletions src/components/TwitchChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@ export interface TwitchChatProps extends React.HTMLAttributes<HTMLIFrameElement>
width?: string | number
}

const defaultProps: Partial<TwitchChatProps> = {
darkMode: DEFAULTS.DARK_MODE,
title: DEFAULTS.TITLE.TWITCH_CHAT,
height: DEFAULTS.CHAT.HEIGHT,
width: DEFAULTS.CHAT.WIDTH
};

const TwitchChat: React.FC<TwitchChatProps> = ({
channel,
parent,
darkMode,
darkMode = DEFAULTS.DARK_MODE,

title,
height,
width,
title = DEFAULTS.TITLE.TWITCH_CHAT,
height = DEFAULTS.CHAT.HEIGHT,
width = DEFAULTS.CHAT.WIDTH,
...props
}) => {
const hostname = useHostname();
Expand All @@ -52,6 +45,4 @@ const TwitchChat: React.FC<TwitchChatProps> = ({
);
};

TwitchChat.defaultProps = defaultProps;

export default TwitchChat;
20 changes: 5 additions & 15 deletions src/components/TwitchClip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@ export interface TwitchClipProps extends React.HTMLAttributes<HTMLIFrameElement>
width?: string | number
}

const defaultProps: Partial<TwitchClipProps> = {
autoplay: DEFAULTS.AUTOPLAY,
muted: DEFAULTS.MUTED,
title: DEFAULTS.TITLE.TWITCH_CLIP,
height: DEFAULTS.MEDIA.HEIGHT,
width: DEFAULTS.MEDIA.WIDTH
};

const TwitchClip: React.FC<TwitchClipProps> = ({
clip,
parent,
autoplay,
muted,
autoplay = DEFAULTS.AUTOPLAY,
muted = DEFAULTS.MUTED,

title,
height,
width,
title = DEFAULTS.TITLE.TWITCH_CLIP,
height = DEFAULTS.MEDIA.HEIGHT,
width = DEFAULTS.MEDIA.WIDTH,
...props
}) => {
const hostname = useHostname();
Expand All @@ -56,6 +48,4 @@ const TwitchClip: React.FC<TwitchClipProps> = ({
);
};

TwitchClip.defaultProps = defaultProps;

export default TwitchClip;
51 changes: 16 additions & 35 deletions src/components/TwitchEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@ export interface TwitchEmbedProps extends React.HTMLAttributes<HTMLDivElement> {
width?: string | number
}

const defaultProps: Partial<TwitchEmbedProps> = {
allowFullscreen: DEFAULTS.ALLOW_FULLSCREEN,
autoplay: DEFAULTS.AUTOPLAY,
withChat: DEFAULTS.WITH_CHAT,
muted: DEFAULTS.MUTED,
darkMode: DEFAULTS.DARK_MODE,
time: DEFAULTS.TIME,
hideControls: DEFAULTS.HIDE_CONTROLS,
onAuthenticate: typedNoop2<TwitchEmbedInstance, OnAuthenticateData>(),
onVideoPlay: typedNoop2<TwitchEmbedInstance, OnPlayData>(),
onVideoPause: typedNoop<TwitchEmbedInstance>(),
onVideoReady: typedNoop<TwitchEmbedInstance>(),
id: DEFAULTS.ID.TWITCH_EMBED,
height: DEFAULTS.MEDIA.HEIGHT,
width: DEFAULTS.MEDIA.WIDTH
};

const nonReconstructTriggeringProps: (keyof TwitchEmbedProps)[] = ['channel', 'video', 'collection', 'height', 'width'];
const shouldReconstructEmbed = (previousProps: TwitchEmbedProps | undefined, props: TwitchEmbedProps): boolean => {
return objectCompareWithIgnoredKeys(
Expand All @@ -58,26 +41,26 @@ const shouldReconstructEmbed = (previousProps: TwitchEmbedProps | undefined, pro

const TwitchEmbed: React.FC<TwitchEmbedProps> = (props) => {
const {
allowFullscreen,
autoplay,
allowFullscreen = DEFAULTS.ALLOW_FULLSCREEN,
autoplay = DEFAULTS.AUTOPLAY,
channel,
video,
collection,
withChat,
muted,
withChat = DEFAULTS.WITH_CHAT,
muted = DEFAULTS.MUTED,
parent,
darkMode,
time,
hideControls,

onAuthenticate,
onVideoPlay,
onVideoPause,
onVideoReady,

id,
height,
width,
darkMode = DEFAULTS.DARK_MODE,
time = DEFAULTS.TIME,
hideControls = DEFAULTS.HIDE_CONTROLS,

onAuthenticate = typedNoop2<TwitchEmbedInstance, OnAuthenticateData>(),
onVideoPlay = typedNoop2<TwitchEmbedInstance, OnPlayData>(),
onVideoPause = typedNoop<TwitchEmbedInstance>(),
onVideoReady = typedNoop<TwitchEmbedInstance>(),

id = DEFAULTS.ID.TWITCH_EMBED,
height = DEFAULTS.MEDIA.HEIGHT,
width = DEFAULTS.MEDIA.WIDTH,
...restOfProps
} = props;

Expand Down Expand Up @@ -173,6 +156,4 @@ const TwitchEmbed: React.FC<TwitchEmbedProps> = (props) => {
);
};

TwitchEmbed.defaultProps = defaultProps;

export default TwitchEmbed;
66 changes: 21 additions & 45 deletions src/components/TwitchPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@ export interface TwitchPlayerProps extends Omit<React.HTMLAttributes<HTMLDivElem
width?: string | number
}

const defaultProps: Partial<TwitchPlayerProps> = {
autoplay: DEFAULTS.AUTOPLAY,
muted: DEFAULTS.MUTED,
time: DEFAULTS.TIME,
allowFullscreen: DEFAULTS.ALLOW_FULLSCREEN,
playsInline: DEFAULTS.INLINE,
hideControls: DEFAULTS.HIDE_CONTROLS,
onCaptions: typedNoop2<TwitchPlayerInstance, string>(),
onEnded: typedNoop<TwitchPlayerInstance>(),
onPause: typedNoop<TwitchPlayerInstance>(),
onPlay: typedNoop2<TwitchPlayerInstance, OnPlayData>(),
onPlaybackBlocked: typedNoop<TwitchPlayerInstance>(),
onPlaying: typedNoop<TwitchPlayerInstance>(),
onOffline: typedNoop<TwitchPlayerInstance>(),
onOnline: typedNoop<TwitchPlayerInstance>(),
onReady: typedNoop<TwitchPlayerInstance>(),
onSeek: typedNoop2<TwitchPlayerInstance, OnSeekData>(),
id: DEFAULTS.ID.TWITCH_PLAYER,
height: DEFAULTS.MEDIA.HEIGHT,
width: DEFAULTS.MEDIA.WIDTH
};

const nonReconstructTriggeringProps: (keyof TwitchPlayerProps)[] = ['channel', 'video', 'collection', 'height', 'width'];
const shouldReconstructPlayer = (previousProps: TwitchPlayerProps | undefined, props: TwitchPlayerProps): boolean => {
return objectCompareWithIgnoredKeys(
Expand All @@ -72,27 +50,27 @@ const TwitchPlayer: React.FC<TwitchPlayerProps> = (props) => {
video,
collection,
parent,
autoplay,
muted,
time,
allowFullscreen,
playsInline,
hideControls,

onCaptions,
onEnded,
onPause,
onPlay,
onPlaybackBlocked,
onPlaying,
onOffline,
onOnline,
onReady,
onSeek,

id,
height,
width,
autoplay = DEFAULTS.AUTOPLAY,
muted = DEFAULTS.MUTED,
time = DEFAULTS.TIME,
allowFullscreen = DEFAULTS.ALLOW_FULLSCREEN,
playsInline = DEFAULTS.INLINE,
hideControls = DEFAULTS.HIDE_CONTROLS,

onCaptions = typedNoop2<TwitchPlayerInstance, string>(),
onEnded = typedNoop<TwitchPlayerInstance>(),
onPause = typedNoop<TwitchPlayerInstance>(),
onPlay = typedNoop2<TwitchPlayerInstance, OnPlayData>(),
onPlaybackBlocked = typedNoop<TwitchPlayerInstance>(),
onPlaying = typedNoop<TwitchPlayerInstance>(),
onOffline = typedNoop<TwitchPlayerInstance>(),
onOnline = typedNoop<TwitchPlayerInstance>(),
onReady = typedNoop<TwitchPlayerInstance>(),
onSeek = typedNoop2<TwitchPlayerInstance, OnSeekData>(),

id = DEFAULTS.ID.TWITCH_PLAYER,
height = DEFAULTS.MEDIA.HEIGHT,
width = DEFAULTS.MEDIA.WIDTH,
...restOfProps
} = props;

Expand Down Expand Up @@ -198,6 +176,4 @@ const TwitchPlayer: React.FC<TwitchPlayerProps> = (props) => {
);
};

TwitchPlayer.defaultProps = defaultProps;

export default TwitchPlayer;
23 changes: 6 additions & 17 deletions src/components/TwitchPlayerNonInteractive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,18 @@ export interface TwitchPlayerNonInteractiveProps extends React.HTMLAttributes<HT
width?: string | number
}

const defaultProps: Partial<TwitchPlayerNonInteractiveProps> = {
autoplay: DEFAULTS.AUTOPLAY,
muted: DEFAULTS.MUTED,
time: DEFAULTS.TIME,
title: DEFAULTS.TITLE.TWITCH_PLAYER_NON_INTERACTIVE,
height: DEFAULTS.MEDIA.HEIGHT,
width: DEFAULTS.MEDIA.WIDTH
};

const TwitchPlayerNonInteractive: React.FC<TwitchPlayerNonInteractiveProps> = ({
parent,
channel,
video,
collection,
autoplay,
muted,
time,
autoplay = DEFAULTS.AUTOPLAY,
muted = DEFAULTS.MUTED,
time = DEFAULTS.TIME,

title,
height,
width,
title = DEFAULTS.TITLE.TWITCH_PLAYER_NON_INTERACTIVE,
height = DEFAULTS.MEDIA.HEIGHT,
width = DEFAULTS.MEDIA.WIDTH,
...props
}) => {
const hostname = useHostname();
Expand Down Expand Up @@ -68,6 +59,4 @@ const TwitchPlayerNonInteractive: React.FC<TwitchPlayerNonInteractiveProps> = ({
);
};

TwitchPlayerNonInteractive.defaultProps = defaultProps;

export default TwitchPlayerNonInteractive;

0 comments on commit 8a3e15c

Please sign in to comment.