Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
/ object-proxy-js Public archive

Wrap a proxy object around any object for method invocation hooks [DEPRECATED]

License

Notifications You must be signed in to change notification settings

finn-no/object-proxy-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED

This project is not maintained, use ES6 proxies instead! Project not deleted as other some internal projects are still using it.

object-proxy [WIP] travis status

Module to wrap a proxy object around any object, primarly for method invocation hooks.

Usage

var originalObj = {
    greet: function(name){
        console.log('Hello ' + name);
    }
};

before hook

Register a callback which gets called just before the actual method gets invoked.

var objectProxy = require('object-proxy');
var proxied = objectProxy(originalObj, {
    before: function(parentObjectName, methodName, args) {
        console.log('just before ' + methodName + ' is called');
    }
});

proxied.greet('world');
// just before greet is called
// Hello world

after hook

Register a callback which gets called just after the actual method was invoked.

var objectProxy = require('object-proxy');
var proxied = objectProxy(originalObj, {
    after: function(parentObjectName, methodName, args) {
        console.log('just after ' + methodName + ' was called');
    }
});

proxied.greet('world');
// Hello world
// just after greet was called

Utilities

invoke history

Record history of all method invocations on the proxied object.

var objectProxy = require('object-proxy');
var invokeHistory = require('object-proxy/util/invokeHistory');

var history = invokeHistory.create();
var proxied = objectProxy(originalObj, {
    after: history.recorder
});

proxied.greet('world');
// Hello world

console.log(history.recordings);
// [ 'greet("world")' ]

Running sample in samples/invokeHistory.js

About

Wrap a proxy object around any object for method invocation hooks [DEPRECATED]

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published