Skip to content

Commit

Permalink
change otherprops to rest
Browse files Browse the repository at this point in the history
  • Loading branch information
nainghtetlinn committed Nov 25, 2023
1 parent f94b5c6 commit c262dc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/library.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Color from "color"
import { OtherPropsType, OptionsType, AppOptionsType } from "./types"

import {
OtherProps,
OptionsType,
AppOptionsType,
defaultOptions,
} from "./types"
const defaultOptions = {
fontSize: 30,
color: "rgba(255, 255, 255, 1)",
bgColor: "rgba(0, 0, 0, 1)",
}

export function animateMatrixEffect(id: string, ...otherProps: OtherProps) {
export function animateMatrixEffect(id: string, ...rest: OtherPropsType) {
const parentElement = document.getElementById(id)
if (!parentElement) throw new Error(`Cannot find element with id: "${id}"`)

Expand All @@ -19,14 +19,14 @@ export function animateMatrixEffect(id: string, ...otherProps: OtherProps) {

// getting options base on user parameter
let options: OptionsType = {}
if (otherProps.length > 0) {
if (typeof otherProps[0] === "function") {
otherProps[0]()
if (rest.length > 0) {
if (typeof rest[0] === "function") {
rest[0]()
} else {
options = { ...otherProps[0] }
options = { ...rest[0] }
}

otherProps[1] && typeof otherProps[1] === "function" && otherProps[1]()
rest[1] && typeof rest[1] === "function" && rest[1]()
}

const appOptions: AppOptionsType = {
Expand Down
10 changes: 2 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type OtherProps =
export type OtherPropsType =
| [OptionsType]
| [OptionsType, () => void]
| [() => void]
Expand All @@ -14,13 +14,7 @@ export type OptionsType = {
export type AppOptionsType = {
fontSize: number
color: string
firstWordColor: string
bgColor: string
bgFade: string
firstWordColor: string
}

export const defaultOptions = {
fontSize: 30,
color: "rgba(255, 255, 255, 1)",
bgColor: "rgba(0, 0, 0, 1)",
}

0 comments on commit c262dc7

Please sign in to comment.