3 ms·
Recently I implemented a wrapper function that given an object returns a Proxy which has a get method that recursively calls itself with the accessed object pat
by spraak 8y ago
Recently I implemented a wrapper function that given an object returns a Proxy which has a get method that recursively calls itself with the accessed object path and finally returns the object and logs the full path. (The code is not complicated and only about as long as this post, but it's hard to type code on a phone)
The reason for this is to give me logging for this part of the application to aid in extracting it out to a separate service. That is, to see what from this part of the application is actually being used/called.
Edit: I meant to say that I wanted to share this because previously I hadn't yet found an interesting use for a Proxy.
Also, I thought of another use case: in the get method you could return a percentage of the time a different object, i.e. an A/B test.
- adrianhel 8y agoI wrote a package that creates a mock object that can be used for pretty much anything. It's a joy to use when testing. It's called @adrianhelvik/mock https://www.npmjs.com/package/@adrianhelvik/mock https://www.npmjs.com/package/@adrianhelvik/mock