shfshanyue / Daily-Question

互联网大厂内推及大厂面经整理,并且每天一道面试题推送。每天五分钟,半年大厂中
https://q.shanyue.tech
4.94k stars 511 forks source link

【Q614】immer 的原理是什么,为什么它的性能更高 #632

Open shfshanyue opened 3 years ago

shfshanyue commented 3 years ago
const state = {
  user: { id: 3 },
  role: { name: 'admin' }
}

const proxyState = new Proxy(state, {
  get (target, prop) {
    return target[prop]
  },
})
//=> True
state !== proxyState

//=> True
state.user === proxyState.user