Skip to content

Instantly share code, notes, and snippets.

@moonformeli
moonformeli / medium_debounce.ts
Created December 28, 2022 15:23
debounce.ts
type Fn = (...args) => any;
function debounce(fn: Fn, delay: number = 200) {
let timer: NodeJS.Timeout = null;
return ((...args) => {
if (timer) {
clearTimeout(timer);
timer = null;
}
app.get('/movie', async (req, res) => {
const { id } = req.query;
const movie: MoviePayload = await getMovieById(id);
res.json(movie);
});
interface Movie {
title: string;
}
interface Director {
name: string;
age: number;
}
interface Actor {
const Like = () => {
const [likes, setLikes] = useState(0);
const [dislikes, setDislikes] = useState(0);
const onClickLikes = () => setLikes(likes + 1);
const onClickDislikes = () => setDislikes(dislikes + 1);
return (
<div className="like">
<Avatar
function MyPage() {
const [myInfo, setMyInfo] = useState(null);
const [billHistory, setBillHistory] = useState([]);
const [friendsList, setFriendsList] = useState([]);
useEffect(() => {
fetchMyInfo().then(async (mInfo) => {
setMyInfo(mInfo);
const bHistory = await fetchBillHistory();
function MyPage() {
const [myInfo, setMyInfo] = useState(null);
const [billHistory, setBillHistory] = useState([]);
const [friendsList, setFriendsList] = useState([]);
useEffect(() => {
(async () => {
const mInfo = await fetchMyInfo();
const bHistory = await fetchBillHistory();
const fList = await fetchFriendsList();
goto(“/”);
login()
.then(() => {
changeUIComponents();
return updateProfile();
})
.then(() => {
reloadPage();
});
goto("/");
await login();
changeUIComponents();
await updateProfile();
reloadPage();
class Queue {
pos = -1;
queue = [];
empty() {
while (this.pos > -1) {
this.pop();
}
}
function add5(x) {
return x + 5;
}
function mul10(x) {
return x * 10;
}
function pipe(...fn) {
return function(v) {