proxify-js
v0.1.4
Published
An ES6 library for wrapping objects in proxies that provide logging and profiling information
Downloads
4
Maintainers
Readme
proxify
proxify provides ES6 proxies of objects, arrays, and functions with embedded logging functionality to assist in diagnostics or profiling.
Installation
npm install --save proxify-js
Features
import { proxify } from 'proxify-js';
const target = new MyObject();
const proxy = proxify(target);
Once an object has been proxified, you can send it on its merry way through the rest of your application and see logging statements indicating how your application is consuming your object.
function doSomething(obj) {
const price = obj.price;
const quantity = obj.quantity;
obj.total = price * quantity;
}
// send in the proxy instead of the original object
doSomething(proxy);
You'll seen an output in the console similar to this:
Property access on [object Object], property: price
Property access on [object Object], property: quantity
Property write on [object Object], property: total, value: price * quantity
Property descriptor access on [object Object], property: total
Property definition on [object Object], property: total, descriptor { ... }
Notes
- It's useful to override Object#toString() to get a more helpful description of your object in the logs
- Proxies are only available in the latest browsers. Check the ES6 Compatibility table.
- Check out the awesome MDN documentation on proxies to learn more about the various traps and the operations they intercept.
Development
To start the Webpack dev server:
npm start
To run Karma unit tests and generate Istanbul coverage reports:
npm test
To build Webpack bundles:
npm run build:dev
npm run build:prod
To generate jsdoc documentation:
npm run doc
Roadmap
- Configuration layer (customize which keys and traps trigger logging)
- Use EventEmitter within the traps for improved performance and to support multiple/custom reporters
- Deep (recursive) proxification
- Add more useful metadata to logs (stack traces, timestamps, etc)