Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
observingproxy
Advanced tools
A proxy for observing object state changes.
This module is based on the Object.defineProperty
method and serves as an interface to the user provided object, notifying subscribers about the user object changes.
var obj={person:'Eddie',age:22};
_o.onUpdate(obj,{
age:function(value){
if(value>this.oldValue)
console.log('Happy birthday, Peter!')
},
person:function(value){
console.log(this.oldValue+' is now '+value);
}
});
_o(obj).person='Peter';
//> Eddie is now Peter
_o(obj).age++;
//> Happy birthday, Peter!
npm install observingproxy
or
bower install observingproxy
var obj={person:'Peter',age:22};
_o.observe(obj,function(changes){
for(var i=0;i<changes.length;i++)
if(changes[i].name==='age')
if(changes[i].object.age>changes[i].oldValue)
console.log('Happy birthday, Peter!')
});
_o(obj).age++;
//> Happy birthday, Peter!
Note: it works only with property
update
.add
ordelete
operations are not supported.
var arr=[1,2,3];
_o.observe(arr,function(changes){
for(var i=0;i<changes.length;i++)
if(changes[i].type==='splice')
console.log('Array changed')
});
_o(arr).push(4);
//> Array changed
var observer=_o.onUpdate(null,'name',function(value){
//...
});
// Throw observation exception here
try{
observer.report();
}
catch(e){throw e}
// Observing proxy error: target is null
// Destroy your observer
observer.destroy();
While proxy applies property modification immediately, it sends the observer notification call to the end of execution thread using setTimeout
method as a wrapper.
So now, if you do
_o.observe(obj,function(changes){
// iterate changes
});
_o(obj).p1=1;
_o(obj).p2=2;
_o(obj).p3=3;
observer is notified only once with changes
argument containing latest modifications. It makes observer a load sustainable to an observed object being intensively modified.
FAQs
A proxy for observing object state changes.
The npm package observingproxy receives a total of 1 weekly downloads. As such, observingproxy popularity was classified as not popular.
We found that observingproxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.