Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
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.
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.