tune perf of has() more

proxied-state-set
Dominic Gannaway 12 months ago
parent 676ef455b6
commit e2a6619a53

@ -103,16 +103,23 @@ const handler = {
return delete target[prop]; return delete target[prop];
}, },
has(target, prop) { has(target, prop) {
if (prop === STATE_SYMBOL) {
return true;
}
const metadata = target[STATE_SYMBOL]; const metadata = target[STATE_SYMBOL];
const has = Reflect.has(target, prop); const has = Reflect.has(target, prop);
let s = metadata.s.get(prop); let s = metadata.s.get(prop);
if (!has || s !== undefined || get_descriptor(target, prop)?.writable) {
if (s === undefined) { if (s === undefined) {
s = source(has ? proxy(target[prop]) : UNINITIALIZED); s = source(has ? proxy(target[prop]) : UNINITIALIZED);
increment(metadata.v);
metadata.s.set(prop, s); metadata.s.set(prop, s);
} }
const value = get(s); const value = get(s);
return value === UNINITIALIZED ? false : has; if (value === UNINITIALIZED) {
return false;
}
}
return has;
}, },
ownKeys(target) { ownKeys(target) {
const metadata = target[STATE_SYMBOL]; const metadata = target[STATE_SYMBOL];

Loading…
Cancel
Save