
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
action-emitter
Advanced tools
Action emitter based on fbemitter. Instead of string event types we use classes (functions).
Action emitter based on fbemitter. Instead of string event types we use classes (functions). The package is most useful when used with TypeScript.
$ npm install action-emitter --save-dev
First import the action-emitter
package and then create a new emitter instance.
import { ActionEmitter } from "action-emitter";
const Emitter = new ActionEmitter();
constructor(): void
Create a new emitter instance.
const Emitter = new ActionEmitter();
addListener(actionClass, callback): EventSubscription
Register a specific callback to be called on a particular action event. A subscription is returned that can be called to remove the listener.
Argument | Type | Description |
---|---|---|
actionClass | Function | Action class function. |
callback | (action: TAction) => void | Listener callback function. |
class MyAction {
constructor(private value: string) { }
public get Value() {
return this.value;
}
}
let subsciption = Emitter.addListener<MyAction>(MyAction, action => {
console.log(action.Value);
});
once(actionClass, callback): EventSubscription
Similar to addListener()
but the callback is removed after it is invoked once. A subscription is returned that can be called to remove the listener.
Argument | Type | Description |
---|---|---|
actionClass | Function | Action class function. |
callback | (action: TAction) => void | Listener callback function. |
class MyAction {
constructor(private value: string) { }
public get Value() {
return this.value;
}
}
let subsciption = Emitter.once<MyAction>(MyAction, action => {
console.log(action.Value);
});
removeAllListeners(actionClass): void
Removes all of the registered listeners. If provide actionClass
, only listeners for that action class are removed.
Argument | Type | Description |
---|---|---|
actionClass [*] | Function | Action class function. |
[*] - optional.
class MyAction {
constructor(private value: string) { }
public get Value() {
return this.value;
}
}
Emitter.removeAllListeners(MyAction);
// Or
Emitter.removeAllListeners();
listeners(actionClass): Function[]
Return an array of listeners that are currently registered for the given action class.
Argument | Type | Description |
---|---|---|
actionClass | Function | Action class function. |
class Action {
constructor(private value: string) { }
public get Value() {
return this.value;
}
}
Emitter.removeAllListeners(Action);
// Or
Emitter.removeAllListeners();
emit(action): void
Emits an action event with the given data. All callbacks that are listening to the particular action event will be notified.
Argument | Type | Description |
---|---|---|
action | TAction | Action class instance. |
class MyAction {
constructor(private value: string) { }
public get Value() {
return this.value;
}
}
Emitter.emit<MyAction>(new MyAction("value"));
//or
Emitter.emit(new MyAction("value"));
You can listen all actions with AnyAction
class. If you registered this action with once
, then subscription remover does not work.
import { AnyAction } from "action-emitter";
Emitter.addListener(AnyAction, anyAction => {
let actionInstance = anyAction.Action;
console.log(actionInstance);
});
Released under the MIT license.
FAQs
Action emitter based on fbemitter. Instead of string event types we use classes (functions).
The npm package action-emitter receives a total of 31 weekly downloads. As such, action-emitter popularity was classified as not popular.
We found that action-emitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.