目录
很多小伙伴喜欢看code-review, 但其实无非就是那些问题,只要日常工作中做好:
- 做完一个功能,测试各种case是否符合预期
- 代码优化包括(命名、简化代码、设计规范、性能问题)
store的单个状态监听
有时会有业务需求,要对某个状态的变化而更新组件或者视图
class Tray { private unsubscribe?: () => void async init() {
let trayId = store.app.trayId this.handleTrayChange(trayId) // 初始 执行一次
this.unsubscribe = store.subscribe(() => {
const newState = store.app.trayId
if (newState!== trayId) {
trayId = newState this.handleTrayChange(trayId) // trayId更新才执行
}
}
)
} destory()
{ this.unsubscribe?.() } }
- 其一、监听store时,将取消监听函数保存下来,在实例销毁时调用
- 其二、store变化时,判断trayId前后有没有变化,变了才触发任务
通过全局变量userData保存之前的接口数据
最后⭐️
其实还有很多问题不了解业务场景,没有办法分享出来,这里主要捡一些能讲明白的问题。
文章宗旨:还是那句话,看到就是学到