前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >不换的周刊 第38期

不换的周刊 第38期

作者头像
不换
发布2024-04-30 14:09:29
550
发布2024-04-30 14:09:29
举报

Scholar's Weekly 第38期

(封面图片来源于:基于 CC0 协议的 shopify[1])

!!! tip hint important "温馨提示"

代码语言:javascript
复制
周刊中所有高亮的内容都可以点击到指定内容的链接~

?如果您正处在微信公众号,请直接滚动至底部?阅读原文? ?

「关键词:」 Promise.raceJS DocsSSRBrowser Extension

FE News

1.`Promise.race` 中优雅的处理方案[2]

?相关地址:https://dbushell.com/2024/02/27/a-fun-line-of-code/ ?

代码语言:javascript
复制
export const m4aDuration = async (path: string): Promise<number> => {
  const controller = new AbortController();
  const duration = await Promise.race([
    search(path, controller.signal),
    search(path, controller.signal, true)
  ]);
  controller.abort();
  return duration;
};

乍一看没啥特别的地方,但是其实细品发现很精髓的,Promise.race 虽然只决议最快的一个,但是另外一个 Promise 也会在后台继续,要么孤独的被决议,要么被拒绝。

await 决议成功后,controller.abort 就很好的解决了后台很 孤独 的那个 Promise

2.为什么 `is-number` 有这么多的下载量[3]

?相关地址:https://shubhamjain.co/2024/02/29/why-is-number-package-have-59m-downloads/ ?

tailwindcss -> chokidar -> braces -> fill-range -> to-regex-range -> is-number 比如 tailwind 中,内部链条已经包含了 is-number,一个项目中其他包也依赖了,重复依赖导致了下载量的递增。

我们简单看一下代码:

代码语言:javascript
复制
module.exports = function(num) {
  if (typeof num === 'number') {
    return num - num === 0;
  }
  if (typeof num === 'string' && num.trim() !== '') {
    return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
  }
  return false;
};

代码量其实很少,像这类代码可以手写的,不用在项目内部特意的安装。

3.用 JavaScript 重写 17 个改变世界的方程式[4]

?相关地址:https://runjs.app/blog/equations-that-changed-the-world-rewritten-in-javascript ?

不明觉厉。

4.Js Docs 作为替代 TypeScript 的全集指南[5]

?相关地址:https://alexharri.com/blog/jsdoc-as-an-alternative-typescript-syntax ?

我个人看法:不太感兴趣,我比较倾向于手写 TypeScript

5.Waku[6]

?相关地址:https://waku.gg/ ?

一个小型的 SSR 框架,某些功能缺失,不太建议在生产使用,但是它的一些卖点很好:

代码语言:javascript
复制
// ./src/entries.tsx
import { createPages } from 'waku';

import { RootLayout } from './templates/root-layout.js';
import { HomePage } from './templates/home-page.js';

export default createPages(async ({ createPage, createLayout }) => {
  // Create root layout
  createLayout({
    render: 'static',
    path: '/',
    component: RootLayout,
  });

  // Create home page
  createPage({
    render: 'dynamic',
    path: '/',
    component: HomePage,
  });
});

比如路由的管理,比 Next.js 强大太多了。

6.Wxt 下一代浏览器插件编写框架[7]

?相关地址:https://github.com/wxt-dev/wxt ?

用于创建跨浏览器扩展的框架。您可以针对 ChromeFirefoxEdgeSafari 进行定位。Plasmo 是此领域中的另一个选择。

End

!!! pied-piper "交个朋友吧~"

我是不换(书生),"浪子回头金不换"的「不换」,"百无一用是书生"的「书生」,热爱工作,同时在工作之余也热爱开源。

本期周刊到这里就结束了,我们下期再见?~

Reference

[1]

shopify: https://www.shopify.com/stock-photos/photos/thin-plant-stems-in-sun?c=background

[2]

Promise.race 中优雅的处理方案: https://dbushell.com/2024/02/27/a-fun-line-of-code/

[3]

为什么 is-number 有这么多的下载量: https://shubhamjain.co/2024/02/29/why-is-number-package-have-59m-downloads/

[4]

用 JavaScript 重写 17 个改变世界的方程式: https://runjs.app/blog/equations-that-changed-the-world-rewritten-in-javascript

[5]

Js Docs 作为替代 TypeScript 的全集指南: https://alexharri.com/blog/jsdoc-as-an-alternative-typescript-syntax

[6]

Waku: https://waku.gg/

[7]

Wxt 下一代浏览器插件编写框架: https://github.com/wxt-dev/wxt

本文参与?腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-03-04,如有侵权请联系?cloudcommunity@tencent.com 删除

本文分享自 不换的随想乐园 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Scholar's Weekly 第38期
  • FE News
    • 1.`Promise.race` 中优雅的处理方案[2]
      • 2.为什么 `is-number` 有这么多的下载量[3]
        • 3.用 JavaScript 重写 17 个改变世界的方程式[4]
          • 4.Js Docs 作为替代 TypeScript 的全集指南[5]
            • 5.Waku[6]
              • 6.Wxt 下一代浏览器插件编写框架[7]
              • End
                • Reference
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
                http://www.vxiaotou.com