摘要: any 我们把对象设置为 any,编译时正常,运行时才会抛出异常 let v: any = 22 v = new Array() v = "33" v.push(33) console.log(v); 为了避免写 any 运行时异常,unknown出场 unknown let v: unknown 阅读全文
posted @ 2022-01-21 15:20 远方的少年🐬 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 先上一张经典图为敬 redux-saga 是一个用于管理redux应用异步操作代替 redux-thunk 的中间件 集中处理 redux 副作用问题。reducer负责处理action的更新,saga负责协调那些复杂或者异步的操作 使用 generator 函数执行异步,generator不是线程 阅读全文
posted @ 2022-01-19 17:30 远方的少年🐬 阅读(1058) 评论(0) 推荐(0) 编辑
摘要: "thunk" 是什么? 单词“thunk”是一个编程术语,意思是“一段做延迟工作的代码”。不需要现在执行一些逻辑,我们可以编写一个函数体或代码,用于以后执行这些工作。 特别是对于Redux来说,“thunks”是一种编写带有内部逻辑的函数的模式,它可以与Redux存储的调度和getState方法交 阅读全文
posted @ 2022-01-18 18:06 远方的少年🐬 阅读(491) 评论(0) 推荐(0) 编辑
摘要: 前言 React和Redux都遵守组件状态为不可变(immutable)的理念,使用 immer 可将对象设置为 immutable,防止意外的修改。 Immer 是一个支持柯里化,仅支持同步计算的工具,所以非常适合作为 redux 的 reducer 使用。 import produce from 阅读全文
posted @ 2022-01-17 18:45 远方的少年🐬 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 什么是 css in js 用 js 的方式管理 css。 这段代码来自 styled-components 官网。 Button 是一个样式组件。 const Button = styled.a` display: inline-block; border-radius: 3px; padding 阅读全文
posted @ 2022-01-12 17:15 远方的少年🐬 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 1、CommonJS require("module"); require("../file.js"); exports.doStuff = function() {}; module.exports = someValue; 优点:Node.js采用了这个规范,npm中模块数量多 缺点:同步加载模 阅读全文
posted @ 2021-12-29 16:27 远方的少年🐬 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 1、ES模块是如何使用的 通常我们使用 ES module 都是 // app.tsx import React, { Component } from 'react' import { Provider } from 'react-redux' import { store } from './s 阅读全文
posted @ 2021-12-29 16:26 远方的少年🐬 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 1、原型链继承 原理:把子类的 prototype(原型对象)直接设置为父类的实例 缺点:因为子类只进行一次原型更改,所以子类的所有实例保存的是同一个父类的值。 当子类对象上进行值修改时,如果是修改的原始类型的值,那么会在实例上新建这样一个值; 但如果是引用类型的话,他就会去修改子类上唯一一个父类实 阅读全文
posted @ 2021-12-28 10:25 远方的少年🐬 阅读(398) 评论(0) 推荐(0) 编辑
摘要: const myDeepCopy = JSON.parse(JSON.stringify(myOriginal)); 这种方法缺点很多: 循环引用:JSON.stringify() 的对象中如果有循环引用会抛出异常 Converting circular structure to JSON。 其他数 阅读全文
posted @ 2021-12-27 18:23 远方的少年🐬 阅读(43) 评论(0) 推荐(0) 编辑
摘要: debonce 防抖,在 wait 时间内只执行最后一次 高频率触发的事件,在指定的单位时间内,只响应最后一次 function myDebounce(fn, wait = 0) { let timer = null; function debounce() { let _context = thi 阅读全文
posted @ 2021-12-06 18:13 远方的少年🐬 阅读(38) 评论(0) 推荐(0) 编辑