object-proxy

0.0.1 • Public • Published

node-object-proxy

Synopsis

Browser

obj = {
    fancyFunction : (arg1, arg2, arg3)->
        do(fancy(operation(arg3), arg2), arg1)
}

# Create a function that intercepts a call and does 
# something

remote = (obj, func, funcName)->
    ()->
        args = Array.prototype.slice.call arguments
        
        # Run the function remotely
        jsonRPC(funcName, args)
        
        # But also locally
        func.apply obj, args

# Decorate all of obj's methods with the function above

proxiedObj = proxy.proxy(obj, remote)

Server

proxy = require 'object-proxy'

obj = {
    fancyFunction : (arg1, arg2, arg3)->
        do(fancy(operation(arg3), arg2), arg1)
}

call = (name, args)->
    func = proxy.resolve(obj, name)
    func.apply obj, args

Readme

Keywords

none

Package Sidebar

Install

npm i object-proxy

Weekly Downloads

2

Version

0.0.1

License

none

Last publish

Collaborators

  • flashingpumpkin