Skip to content

Instantly share code, notes, and snippets.

@hayoung123
hayoung123 / globalObserver.js
Last active July 21, 2021 12:25
옵저버 함수형으로 관리하기
const globalState = {};
const subscribe = (key, className, observer) => globalState[key]._observers.set(className, observer);
const unsubscribe = (key,className,observer) => globalState[key]._observers.remove(className, observer);
const _notify = (key) => globalState[key]._observers.forEach((observer) => observer());
const initState = ({ key, defaultValue }) => {
if (key in globalState) throw Error('이미 존재하는 key값 입니다.');
@hayoung123
hayoung123 / gist:c30fe173fd29db1a8c1c27f0d25a474f
Last active June 12, 2021 10:54
쓰로틀링 & 디바운스
export const debounce = debounceInit();
//될지는 모르겠음
const debounce = (fn,wait) => {
let timer = null;
function debounced(){
if (timer) clearTimeout(timer);
timer = setTimeout(fn, wait);
}
return debounced;