Search code examples
javascriptobjectes6-proxy

How to check if we have already created proxy on Object using ObservableSlim?


I am using ObservableSlim to create proxy.

The create method of ObservableSlip will return a standard ES6 Proxy.

I have created a proxy on object like this:

const proxy = ObservableSlim.create(model, null, (changes) => {});

Problem:

How will i know that proxy is ES6 Proxy?


Solution

  • As covered here, this is impossible in the general case (without dirty hacks at least), because Proxy objects are by design transparent and mimic their targets on every system call.

    However, library authors realize that that might be inconvenient sometimes and provide hooks in their Proxy objects so that the user can detect them. For the library in question, the returned Proxy exposes the property __isProxy for this exact purpose.