funcproxy
v1.0.14
Published
Wrapper for Proxy that passes all handler methods to a function
Downloads
8
Maintainers
Readme
#Wrapper for Proxy that passes all handler methods to a function
##Install
$ npm install funcproxy
##Requires
funcproxy
requires a Javascript version that supports the following features:
Proxy
Object.freeze
For example, Node version 6.4 or higher.
##What it does
Javascript's Proxy
constructor takes two arguments: the target
of the proxy and a handler
object that can contain methods from the following list:
getPrototypeOf
setPrototypeOf
isExtensible
preventExtension
getOwnPropertyDescriptor
defineProperty
has
get
set
deleteProperty
ownKeys
apply
construct
Each of these functions defines some kind of behavior for the proxy.
The point of funcproxy
is to be able to set up a proxy by passing in one general function that can
handle any and all of the above handler methods, so that it is not necessary to set up separate handler methods.
##Using funcproxy to create a proxy instance
The funcproxy
module exports a function. This function takes one argument, an object with setup options, and returns a proxy. The possible options that can be passed in are described in the next section. If no arguments at all are provided to the funcproxy
function, the case is treated the same as if an empty object had been passed in.
##Options
target
- The target of the proxy. If this option is missing, a newly-created object with no properties will be used as the proxy target.isRevocable
- Determines whether the proxy will be revocable or not. If this option is missing, it will default tofalse
.func
- A function that controls the behavior of the proxy. When any handler method is invoked on the proxy,func
is called with one argument, an object that contains the following properties:method
- The handler method. For example, 'set' or 'ownKeys'.methodArgsArray
- An array of the original arguments that the proxy passed into the handler method.methodArgs
- An object that contains the handler method arguments as properties, with appropriate keys. For example, if the handler method isget
, themethodArgs
object will have the properties 'target', 'property', and 'receiver'.methodThis
- Thethis
value in the handler method.options
- The setup options of thisfuncproxy
instance. These options are frozen and cannot be modified.proxy
- The proxy.funcproxy
- The function exported by thefuncproxy
module. If thefunc
option is missing, an empty function (a function that does nothing) will be used.
methods
- The handler methods that will be used by the proxy. This option can be given the following values:true
to use all methods,false
to use no methods, or a string array of method names to use just those methods. If this option is missing, all methods will be used.