Skip to content

Commit

Permalink
perf: proxy assign
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 30, 2018
1 parent 4dd6070 commit 53e9ce8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ function get(state, prop) {
}

function set(state, prop, value) {
// TODO: optimize
state.assigned[prop] = true
if (!state.modified) {
if (
(prop in state.base && is(state.base[prop], value)) ||
(has(state.proxies, prop) && state.proxies[prop] === value)
)
return true
// Optimize based on value's truthiness. Truthy values are guaranteed to
// never be undefined, so we can avoid the `in` operator. Lastly, truthy
// values may be proxies, but falsy values are never proxies.
const isUnchanged = value
? is(state.base[prop], value) || value === state.proxies[prop]
: is(state.base[prop], value) && prop in state.base
if (isUnchanged) return true
markChanged(state)
}
state.assigned[prop] = true
state.copy[prop] = value
return true
}
Expand Down

0 comments on commit 53e9ce8

Please sign in to comment.