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
| import React from "react"; | |
| import { Select, MenuItem, FormControl, InputLabel, Box } from "@mui/material"; | |
| interface MovieFilterProps<T extends string | number> { | |
| primaryOptionLabel?: string; | |
| primaryOptionValue?: T; | |
| options: T[]; | |
| selectedFilter: T; | |
| setSelectedFilter: React.Dispatch<React.SetStateAction<T>>; | |
| title: string; |
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
| // Make sure we have a input field with id "inputData" in our DOM. | |
| const inputData = document.getElementById("inputData"); | |
| const getDataFromServer = (name) => { | |
| console.log(`${name} :: getting Data from Server...........`); | |
| }; | |
| const throttle = (callback, delay) => { | |
| delay = delay || 2000; |
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
| // Make sure we have a input field with id "inputData" in our DOM. | |
| const inputData = document.getElementById("inputData"); | |
| const getDataFromServer = (name) => { | |
| console.log(`${name} :: getting Data from Server...........`); | |
| }; | |
| const debounce = (callback, delay) => { | |
| delay = delay || 2000; |
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
| const memoize = (callback, limit = 100, delimiter = "\u00B7") => { | |
| if (typeof callback !== "function") { | |
| throw new TypeError("Memoize expects a function"); | |
| } | |
| const cache = new Map(); | |
| return (...args) => { | |
| const cacheKey = args.join(delimiter); // To get key without collision | |
| if (cache.has(cacheKey)) { | |
| console.log(`Retrieving from cache for ${cacheKey}`); |
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
| class AsyncQueue { | |
| constructor() { | |
| this.values = []; // To hold actual values | |
| this.callbacks = []; // To hold the callbacks | |
| } | |
| /** | |
| * If the callbacks array has something, remove it and execute it. | |
| * Otherwise, add the value to the values array. | |
| */ |
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
| class Observable { | |
| #observers = new Set(); | |
| subscribe(observer) { | |
| // Only support function as callback | |
| if (typeof observer !== "function") { | |
| throw new TypeError("Observer must be a function"); | |
| } | |
| this.#observers.add(observer); | |
| return () => { |
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
| body { | |
| background-color: skyblue; | |
| margin: 20px; | |
| height: 90%; | |
| } | |
| .flex_center { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; |
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
| // Make these changes in the ~/Library/Application Support/Code/User/snippets/html.json | |
| // Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and | |
| // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
| // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
| // same ids are connected. | |
| // Example: | |
| // "Print to console": { | |
| // "prefix": "log", | |
| // "body": [ | |
| // "console.log('$1');", |
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
| /** | |
| * PubSub (Publish-Subscribe) Pattern Implementation | |
| * | |
| * A lightweight event bus that decouples producers (publishers) from | |
| * consumers (subscribers). Publishers emit named events with data; | |
| * subscribers register callbacks that fire when those events are published. | |
| */ | |
| class PubSub { | |
| #events = new Map(); |
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
| import { Provider } from "react-redux"; | |
| import thunk, { ThunkMiddleware } from "redux-thunk"; | |
| import { render, RenderAPI } from "react-test-renderer"; | |
| import configureMockStore from "redux-mock-store"; | |
| import TestComponent from "./TestComponent"; | |
| import { describe } from "node:test"; | |
| const middlewares: Array<ThunkMiddleware> = [thunk]; | |
| const createMockStore = configureMockStore(middlewares); |
NewerOlder