Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
@jalik/observer
Advanced tools
The classic observer design pattern.
The Observer design pattern is a well known pattern to create reactive applications. For example, your can attach listeners to a form text field, then when the text field value changes, all listeners are notified of that change and thus can do something in response.
This library is tested with unit tests.
The following code shows how to attach a listener and how to notify it of events.
import Observer from "@jalik/observer";
class Person {
constructor(name) {
this.name = name;
// Create the observer with current context
this.observer = new Observer(this);
}
on(event, listener) {
// Attach listener
this.observer.attach(event, listener);
}
say(words) {
console.log(words);
// Notify listeners
this.observer.notify("say", words, new Date());
}
}
const karl = new Person("karl");
// When this person says something,
// we will display it in the console with the time
karl.on("say", function(words, date) {
console.log(`${this.name} said: "${words}" at ${date.toString()}`);
});
In the case that you need to remove a previously attached listener, here is the code.
import Observer from "@jalik/observer";
const doubleClickListener = function() {
console.log("double click detected");
// This avoid the current function to be called
// on the next "doubleClick" event notification.
observer.detach("doubleClick", doubleClickListener);
};
const observer = new Observer();
observer.attach("doubleClick", doubleClickListener);
// This will call the doubleClickListener once.
observer.notify("doubleClick");
// This will not call the doubleClickListener
// since it has been detached in the previous call.
observer.notify("doubleClick");
Observer
using ES6 default exportThe code is released under the MIT License.
If you find this lib useful and would like to support my work, donations are welcome :)
v1.0.2 (2018-03-11)
Observer
using ES6 default exportFAQs
A library to observe events and trigger callbacks.
The npm package @jalik/observer receives a total of 71 weekly downloads. As such, @jalik/observer popularity was classified as not popular.
We found that @jalik/observer demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.