-
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController/AbortController const controller = new AbortController const signal = controller.signal // https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch // https://developer.mozilla.org/en-US/docs/Web/API/RequestInit fetch('/', { signal }).then(res => res.text()).catch(reason => reason).then(console.log) // https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort // https://developer.mozilla.org/zh-CN/docs/Web/API/DOMException controller.abort('test')
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener // addEventListener document.addEventListener('click', () => console.log('doc.click'), { once: true }) // twice. const controller = new AbortController let times = 0 document.addEventListener('click', () => { console.log('doc.click.twice') if (++times === 2) controller.abort() }, { signal: controller.signal }) // aborted // auto removeEventListener? 在组件 unmounted 时,直接 controller.abort() // https://x.com/thesegunadebayo/status/1817946177440018677 document.addEventListener('click', e => console.log('nothing'), { signal: AbortSignal.abort() })
// https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static // https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static // https://github.com/shaseley/abort-signal-any const controller = new AbortController const userMayCancelSignal = controller.signal document.addEventListener('click', () => { controller.abort() }) try { const res = await fetch('/', { signal: AbortSignal.any([ AbortSignal.timeout(2000), userMayCancelSignal ]) }) console.log(res.text()) } catch(e) { console.log(e.name) } // action. const click = new Event('click') document.dispatchEvent(click)
// https://nodejs.org/docs/latest/api/timers.html#timerspromisessettimeoutdelay-value-options const controller = new AbortController function setTimeoutEx(fn, timeout) { const timer = setTimeout(() => fn, timeout) controller.addEventListener('abort', () => { clearTimeout(timer) }) return timer }
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget const controller = new AbortController const signal = controller.signal signal.addEventListener('abort', () => console.log('abort')) controller.abort()
-
if…else 有优雅的写法吗? 可以参考condition的设计
function onSortChange({ order, prop }) { const rules = [ { value: 1, condition: ['descending', 'thisYearIncome'] }, { value: 2, condition: ['ascending', 'thisYearIncome'] }, { value: 3, condition: ['descending', 'lastYearIncome'] }, { value: 4, condition: ['ascending', 'lastYearIncome'] }, { value: 5, condition: ['descending', 'rate'] }, { value: 6, condition: ['ascending', 'rate'] }, ] const find = rules.find(({ condition }) => condition[0] === order && condition[1] === prop) const sortType = find ? find.value : 0 // console.log(sortType) this.fetchData(sortType) }
-
推荐试用 iPhone 内置输入法的语音转文字功能
-
定将捷足随途骥,那有闲情逐水鸥
-
上传,解压到 static 目录下子目录[唯一], nginx 特定 location 下 root 指向到 static[autoindex on] - Ref
-
图片浏览效果:public.work
-
期待是一种隐形的暴力 Ref
-
I tried to
brew install ffmpeg
on my wife’s older MBP, so of course it needed to fetch, checks notes: rust, ruby, and vim (?!) Ref, unraveling-homebrew-dependencies-a-handy-guide -
需要花一学期时间才能学完的知识,不要期望周/月内学完 - ps: 尊重下别人
-
最近对自己的一个反思:做的基本都是逆人性的东西,所以很难 scale, 应该多做点顺人性的。Ref
2024 第 31 周
更新:
欢迎读者通过邮件(redky#qq.com)或 Telegram 与我交流