gullerya / object-observer

Object Observer functionality of JavaScript objects/arrays via native Proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method to access the original underlying object?

dilan-dio4 opened this issue · comments

Hello,

I was wondering if there was an easy way to access the the original object from just the proxy. I'm looking for the actual object reference, not just a copy.

If not, would it be possible to add a function that would work as follows:

const order = { type: 'book', pid: 102, ammount: 5, remark: 'remove me' };
const observableOrder = Observable.from(order);
const originalOrder = Observable.original(observableOrder);

order === originalOrder // true

Hi,
First, sorry for somewhat late answer.

I'm afraid, just off the top of my head, that it is not possible.

Let's settle the use-case and a bit of internals, since I quite not getting the need:

  • when observable created the original object is cloned and THIS cloned version of that is being proxified
  • it is this cloned version that is getting updated along the work with observable, the original object is NOT getting any changes performed on observable

So in order to implement the API you suggest I could, theoretically, keep a reference to the original object. But the same thing a consuming application may do, and I'd prefer not to keen a references to anything that is not in framework's possession.

Understood.

Thanks for the detailed answer