摘要:
观察者模式(Observer pattern),和发布订阅模式(Publish–subscribe pattern),到底有什么不同? 观察者模式 所谓观察者模式,其实就是为了实现松耦合(loosely coupled)。 用《Head First设计模式》里的气象站为例子,每当气象测量数据有更新, 阅读全文
摘要:
// 安装依赖 npm install @babel/plugin-proposal-optional-chaining -S // @babel/plugin-proposal-nullish-coalescing-operator -S // 在babel.config.js中 的 plugin 阅读全文
摘要:
/** 发布者 */ class Publish { name: string id: number messageMap: { [key: string]: {id: number; name: string; [x: string]: any}[] } /** name等同于给当前发布者一个名称 阅读全文
摘要:
在上一篇我重点讲述了 ts 的交叉类型,本期将结合实例重点讲述 ts 中的一些高级操作符。本篇文章略长,笔者之前的文章都略短,作为男人还是要好好学习,文章还是长点好。 本期涉及的操作符如下: keyof in infer 关键字 Parameters ReturnType InstanceType 阅读全文
摘要:
ThingJS https://www.thingjs.com/guide/speedcityshow/ 阅读全文
摘要:
https://www.jianshu.com/p/b07efb7a76a6 https://www.cnblogs.com/vvjiang/p/9327903.html https://v4.webpack.docschina.org/plugins/split-chunks-plugin/ 干货 阅读全文
摘要:
正文 在 TS 中,类似数组、字符串、数组、接口这些常见的类型都非常常见,但是如果要定义一个对象的 key 和 value 类型该怎么做呢?这时候就需要用到 TS 的 Record 了。 上代码: interface PageInfo { title: string; } type Page = " 阅读全文
摘要:
React Hooks 详解 【近 1W 字】+ 项目实战 https://juejin.cn/post/6844903985338400782 https://juejin.cn/post/6847902217261809671 详解 React useCallback & useMemo 前言 阅读全文
摘要:
初探memo 首先让我们用一个例子走进React.memo的世界 呆呆的函数组件 - 没有使用memo 对于一个函数组件来说,如果没有使用React.memo就好比是一个人没有脑子,就笨笨的呆呆的 不信我们就来看下面的Demo 点击访问演示Demo GIF打开UC浏览器 查看更多精彩图片 让我们来分 阅读全文
摘要:
<script> function debounce (fn, delay) {//防抖 let timer = null; let firstTime = false; return function (...args) { let context = this; if (firstTime) { 阅读全文
摘要:
2.1.深度优先遍历深度优先查找(depth first search),采用栈结构,后进先出,JS用递归实现和没有用递归实现 // 不用递归实现深度遍历优先 const depthFirstSearchWithoutRecursive = source => { const result = [] 阅读全文
摘要:
我们都知道React 16实现了新的调度策略(Fiber), 新的调度策略提到的异步、可中断,其实就是基于浏览器的 requestIdleCallback和requestAnimationFrame两个API。所以这里我们有必要了解一下这两个API,关于Fiber部分后面会单开几篇讲。 什么是req 阅读全文
摘要:
前言 webpack加载css背景图片、img元素指向的网络图片、使用es6的import引入的图片时,需要使用url-loader或者file-loader。url-loader和file-loader可以加载任何文件。 区别url-loader可以将图片转为base64字符串,能更快的加载图片, 阅读全文
摘要:
一、区别前面两节我们有提到Loader与Plugin对应的概念,先来回顾下 loader 是文件加载器,能够加载资源文件,并对这些文件进行一些处理,诸如编译、压缩等,最终一起打包到指定的文件中 plugin 赋予了 webpack 各种灵活的功能,例如打包优化、资源管理、环境变量注入等,目的是解决 阅读全文
摘要:
import axios from 'axios' // 从localStorage中获取token function getLocalToken () { const token = window.localStorage.getItem('token') return token } // 给实 阅读全文