Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clubajax/proxify
https://github.com/clubajax/proxify
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/clubajax/proxify
- Owner: clubajax
- License: mit
- Created: 2018-07-15T16:55:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-21T22:45:27.000Z (about 6 years ago)
- Last Synced: 2024-10-23T04:24:56.832Z (22 days ago)
- Language: HTML
- Size: 25.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# proxify
Deep replace data with a new Proxy listeners
`proxify` uses UMD, so it will work with globals, AMD, or Node-style module exports.
## Installation
To install using npm:
npm install @clubajax/proxify --save
You can clone the repository with your generic clone commands as a standalone
repository or submodule.git clone git://github.com/clubajax/proxify.git
`proxify` has no dependencies.
## Description
The primary function is to make it to set change an object and all of its child objects to Proxies,
so all changes will emit change-callbacks.## Support
`proxify` supports modern browsers. IE11 is not tested but should work with a [proxy shim](https://github.com/GoogleChrome/proxy-polyfill).
This library uses UMD, meaning it can be consumed with RequireJS, Browserify (CommonJS),
or a standard browser global.## Usage
Signature:
proxifiedData = proxify(dataToBeProxified, options)
### options:
* **onChange:** called back when a property is set
* **onSet:** same as `onChange`
* **onGet:** called back when a property is accessed
* **filter:** a function that returns a boolean. If the result is true, the passed data will not be proxified.
properties will still be set, but events will not fire.```jsx harmony
const data = {
x: 1,
deep: {
y: 2
}
};const proxifiedData = proxify(data, {
onChange: function (value, key, target) {
console.log('changed', key, value);
},
filter (key) {
return key !== 'foo';
}
});
```### extras
While debugging, a proxified object is difficult to inspect, because of the Proxy layers.
To help with this, there are two methods, `copy` and `log`:proxifiedData.copy(); // returns a non-proxy copy
proxifiedData.log(message); // sends a non-proxy copy to the console, with optionsla message
## LicenseThis uses the [MIT license](./LICENSE). Feel free to use, and redistribute at will.