
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
async-watch
Advanced tools
[](https://travis-ci.org/wiresjs/async-watch) [](https://gitter.im/I-Hate-React/Lobby)
AsyncWatch is a small library for watching javascript/node.js objects. It uses Object.defineProperty which makes it compatible with most browsers. Any changes happening within present tick will be called on the next available one.

requestAnimationFrame in browser and on process.nextTick in Node)Object.observeObject.defineProperty() makes it compatible with all modern browser down to IE 9init,splice, push)DOM Node properties and attributesnpm install async-watch --save
var AsyncWatch = require('async-watch').AsyncWatch;
var obj = {}; // creating an empty object
AsyncWatch(obj, 'a.b.c', function(value){
console.log('set', value);
});
// You can pass an array as well
//AsyncWatch(obj, ['a', 'b', 'c'])
As you can see here, we start with an empty object. AsyncWatch will set a watcher on property "a", which knows about its descendands
obj.a = {
b : {
c : 1
}
};
obj.a.b.c = 2;
obj.a.b.c = 3;
setTimeout(function(){
obj.a.b.c = 4;
},0)
The output will look like this:
set 3
set 4
Callback is called on "transaction commit". Each transaction is a requestAnimationFrame tick. Surely, initial transaction loop happens when first value is changed.
Worth mentioning: Transactions happen on demand, without "perpetual" loop or/and any other dirty checkers.
Destroys a watcher (does not destroy its descendants or similar watchers)
var watcher = AsyncWatch(obj, 'a', function(value) {
});
watcher.destroy();
watchAll is not implemented yet, however subscriptions are introduced. Each watcher returns a "transaction" / watcher.
var obj = {
a : 1,
b : 2
}
var watcher1 = AsyncWatch(obj, 'a', function(value) {
});
var watcher2 = AsyncWatch(obj, 'b', function(value) {
});
var subscription = AsyncWatch.subscribe([watcher1, watcher2], function(changes){
console.log(changes)
})
Subscribers' callback guarantees all watchers to be in sync.
Outputs:
{a : 1, b: 2 }
Unfortunately, subscriptions won't clean up themselves, you need to do it manually.
subscription.unsubscribe();
If you want to unsubscribe and destroy corresponding watchers:
subscription.destroy();
You can define a computed property.
var obj = {
firstName : "Bob",
lastName : "Marley"
}
AsyncComputed(obj, 'fullName', ['firstName', 'lastName'],
self =>`Name is ${self.firstName} ${self.lastName}`);
obj.lastName = "Foo";
obj.lastName = "Foo1";
AsyncWatch(obj, 'fullName', (value) => {
// Name is Bob Foo1
});
var obj = {
users : [{name : "John"}, {name : "Bob"}]
}
AsyncWatchArray(obj, 'users', function(array,events){
console.log(events);
});
Triggers events: "init" "push" "splice"
To have better understanding check these test/sync_test.js
Contribution is greatly appreciated! Please, run tests before submitting a pull request.
FAQs
[](https://travis-ci.org/wiresjs/async-watch) [](https://gitter.im/I-Hate-React/Lobby)
The npm package async-watch receives a total of 104 weekly downloads. As such, async-watch popularity was classified as not popular.
We found that async-watch 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.