https://github.com/shaack/svjs-observe
Observe properties, Arrays, Sets and Maps of an Object. Can also intercept function calls.
https://github.com/shaack/svjs-observe
Last synced: about 2 months ago
JSON representation
Observe properties, Arrays, Sets and Maps of an Object. Can also intercept function calls.
- Host: GitHub
- URL: https://github.com/shaack/svjs-observe
- Owner: shaack
- License: mit
- Created: 2017-11-28T12:23:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T22:55:57.000Z (about 8 years ago)
- Last Synced: 2025-03-08T10:51:58.120Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# svjs-observe
An ES6 Module to observe properties (simple properties, Arrays, Sets and Maps)
of an Object. Can also intercept function calls.
Observing means to call a callback-function every value change of an Object property.
## Methods
### Observe.property(object, propertyName, callback)
Observe properties (attributes) of an object. Works also with Arrays, Maps and Sets.
The parameter `propertyName` can be an array of names to observe multiple properties.
#### callback params
`{ propertyName: propertyName, oldValue: oldValue, newValue: newValue }`
#### Example
``` JavaScript
Observe.property(model, ["property1","property2"], (params) => {
console.log("property changed", params.propertyName);
console.log("oldValue", params.oldValue);
console.log("newValue", params.newValue);
})
```
### Observe.preFunction(object, functionName, callback)
Intercept a function call, before the function is executed. Can manipulate
arguments in the callback.
#### callback params
`{functionName: functionName, arguments: functionArguments}`
### Observe.postFunction(object, functionName, callback)
Intercept a function call, after the function is executed. Can manipulate
returnValue in callback.
#### callback params
`{functionName: functionName, arguments: functionArguments, returnValue: returnValue}`