Skip to content

Commit

Permalink
fix(observable): preserve proxy invariants on get
Browse files Browse the repository at this point in the history
  • Loading branch information
Igmat committed May 4, 2020
1 parent 12300ca commit 0c613ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/observable/src/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export function observeObj<T extends {}>(obj: T, onSet?: (tx: ITransaction) => v
return new Proxy(obj, {
// TODO: fix `symbol` type
get(target, p: string | number, receiver) {
// preserving Proxy invariant
const desc = Reflect.getOwnPropertyDescriptor(target, p);
if (desc && !desc.configurable && !desc.writable) {
return Reflect.get(target, p, receiver);
}
const atom = createAtomIfNotExists(p);

return calculate(atom, () => Reflect.get(target, p, receiver), observe);
Expand Down

0 comments on commit 0c613ae

Please sign in to comment.