
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
gr-event-dispatcher
Advanced tools
JavaScript events for custom objects
$ npm install gr-event-dispatcher
Object
Boolean
Object
Object
Object
Object
Registers the specified listener
on the event target it's called on.
Kind: inner method of eventDispatcher
Returns: Object
- The eventDispatcher
object.
Throws:
TypeError
If the object that eventDispatcher
is applied to is not extensible.Param | Type | Description |
---|---|---|
type | String | A string representing the event type to listen for. |
listener | function | A function to be executed when an event of the specified type occurs. |
Boolean
Checks if the target object has a listener
registered on for specific event type
.
Kind: inner method of eventDispatcher
Returns: Boolean
- True if target object has listener
registered for specific event type
; otherwise false.
Param | Type | Description |
---|---|---|
type | String | A string representing the event type. |
listener | function | The event listener to check if registered for the specified event type . |
Object
Removes the previously registered event listener
from the event target.
Kind: inner method of eventDispatcher
Returns: Object
- The eventDispatcher
object.
Param | Type | Description |
---|---|---|
type | String | A string representing the event type to remove. |
listener | function | The event listener function to remove from the event target. |
Object
Dispatches an event at the specified event target.
Kind: inner method of eventDispatcher
Returns: Object
- The eventDispatcher
object.
Param | Type | Description |
---|---|---|
event | Object | The event object to be dispatched. |
Object
Applies the eventDispatcher
prototype methods to the event target.
Kind: inner method of eventDispatcher
Returns: Object
- The eventDispatcher
object.
Throws:
TypeError
If the object that eventDispatcher
is applied to is not extensible.Param | Type | Description |
---|---|---|
object | Object | The event target object. |
var car = {
start: function (afterStartCallback) {
// Dispatch `start` event.
this.dispatchEvent({type: 'start', message: 'Start engines'});
afterStartCallback && afterStartCallback(this);
},
stop: function () {
// Dispatch `stop` event.
this.dispatchEvent({type: 'stop', message: 'Stop engines'});
}
};
function startEngines(event) {
console.log(event.message);
}
function stopEngines(event) {
console.log(event.message);
}
// Apply `eventDispatcher` methods to the prototype of the event target.
eventDispatcher.apply(Object.getPrototypeOf(car));
// Register event listeners to event target.
car
.addEventListener('start', startEngines)
.addEventListener('afterStart', startEngines)
.addEventListener('stop', stopEngines);
// `start` event fires first, then `afterStart` and finally
// after two seconds `stop` events fires.
car.start(function (self) {
// Dispatch `afterStart` event.
self.dispatchEvent({type: 'afterStart', message: 'Car has started'});
});
console.log(car.hasEventListener('start', startEngines)); // -> true
console.log(car.hasEventListener('afterStart', startEngines)); // -> true
console.log(car.hasEventListener('stop', startEngines)); // -> false
console.log(car.hasEventListener('stop', stopEngines)); // -> true
setTimeout(function () {
car.stop();
// Remove all event listeners from event target.
car
.removeEventListener('start', startEngines)
.removeEventListener('afterStart', startEngines)
.removeEventListener('stop', stopEngines);
}, 2000);
FAQs
JavaScript events for custom objects
We found that gr-event-dispatcher 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.