New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

event-actions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-actions - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

50

index.js

@@ -147,6 +147,6 @@ "use strict";

/**
* Pipe events from sender to this action
* Pipe emitter event to EventActions actions
*/
EventActions.prototype.bindAction = function(sender, event, toAction) {
sender.on(event, this.actions.emit.bind(this.actions, this._getEventName(toAction)));
EventActions.prototype.pipeToAction = function(emitter, event, toAction) {
emitter.on(event, this.actions.emit.bind(this.actions, this._getEventName(toAction)));
return this;

@@ -198,6 +198,6 @@ };

/**
* Pipe events from sender to this event
* Pipe emitter event to EventActions event
*/
EventActions.prototype.bindEvent = function(sender, event, toEvent) {
sender.on(event, this.events.emit.bind(this.events, this._getEventName(toEvent)));
EventActions.prototype.pipeToEvent = function(emitter, event, toEvent) {
emitter.on(event, this.events.emit.bind(this.events, this._getEventName(toEvent)));
return this;

@@ -214,1 +214,39 @@ };

//
// EventActions piping
//
/**
* Pipe event to event
*/
EventActions.prototype.pipeEventToEvent = function(from, to) {
this.onEvent(from, this.events.emit.bind(this.events, this._getEventName(to)));
return this;
};
/**
* Pipe event to action
*/
EventActions.prototype.pipeEventToAction = function(from, to) {
this.onEvent(from, this.actions.emit.bind(this.actions, this._getEventName(to)));
return this;
};
/**
* Pipe action to action
*/
EventActions.prototype.pipeActionToAction = function(from, to) {
this.onAction(from, this.actions.emit.bind(this.actions, this._getEventName(to)));
return this;
};
/**
* Pipe action to event
*/
EventActions.prototype.pipeActionToEvent = function(from, to) {
this.onAction(from, this.events.emit.bind(this.events, this._getEventName(to)));
return this;
};
{
"name": "event-actions",
"description": "Application level event and action emitter",
"version": "0.2.2",
"version": "0.2.3",
"main": "index.js",

@@ -10,3 +10,7 @@ "author": {

},
"repository": {
"type": "git",
"url": "https://github.com/hakovala/node-event-actions.git"
},
"license": "MIT"
}

71

README.md

@@ -69,3 +69,3 @@ # EventActions

See 'example.js' for more complete usage example.
See [`example.js`](example.js) for more complete usage example.

@@ -76,5 +76,5 @@ ## Namespacing

Either absolute or relative namespaces can be used when adding listeners or emitting events. Relative namespace starts with ':' and will be prepend with EventActions instances namespace.
Either absolute or relative namespaces can be used when adding listeners or emitting events. Relative namespace starts with `:` and will be prepend with EventActions instances namespace.
In example if EventActions namespace is 'root:child', then emitting ':action' will actually trigger listeners registered for 'root:child:action'. Same goes for registering listeners. Adding listener for ':action' on EventActions that has namespace 'root:child', it will listen for events 'root:child:action'.
In example if EventActions namespace is `root:child`, then emitting `:action` will actually trigger listeners registered for `root:child:action`. Same goes for registering listeners. Adding listener for `:action` on EventActions that has namespace `root:child`, it will listen for events `root:child:action`.

@@ -85,5 +85,5 @@ ## Events

* target Target namespace of the action
* action Name of the action
* args Arguments passed with action
* `target` Target namespace of the action
* `action` Name of the action
* `args` Arguments passed with action

@@ -94,5 +94,5 @@ Emitted when action is emitted from any emitter that share same root emitter.

* target Target namespace of the event
* event Name of the event
* args Arguments passed with event
* `target` Target namespace of the event
* `event` Name of the event
* `args` Arguments passed with event

@@ -108,6 +108,6 @@ ## EventEmitters

* ns Namespace
* `ns` Namespace
Create namespaced version of EventActions instance.
Namespaced instances use root emitters.
Namespaced instances share emitters with root.
Namespace is appended to relative action/event names.

@@ -125,4 +125,4 @@

* name Action/event name, absolute or relative
* listener Action/event listener
* `name` Action/event name, absolute or relative
* `listener` Action/event listener

@@ -133,4 +133,4 @@ Add listener for action/event.

* name Action/event name, absolute or relative
* arguments
* `name` Action/event name, absolute or relative
* `arguments` ...

@@ -141,4 +141,4 @@ Triggers action/event listener with given name.

* name Action/event name, absolute or relative
* listener Action/event listener to remove (optional)
* `name` Action/event name, absolute or relative
* `listener` Action/event listener to remove (optional)

@@ -149,12 +149,12 @@ Remove all or specific listener with given name.

* name Action/event name, absolute or relative
* listener Action/event listener
* `name` Action/event name, absolute or relative
* `listener` Action/event listener
Listen for action/event. Listener is removed after triggering.
### `bindAction` / `bindEvent`
### `pipeToAction` / `pipeToEvent`
* sender Emitter to listen, any EventEmitter
* event Event to listen for
* toName Bind to name
* `emitter` Emitter to listen, any EventEmitter
* `event` Event to listen for
* `toName` Bind to name

@@ -164,6 +164,31 @@ Binds any EventEmitter event to specified action or event.

### `pipeEventToEvent` / 'pipeEventToAction' / 'pipeActionToAction' / 'pipeActionToEvent'
* `from` event/action to pipe from
* `to` event/action to pipe to
Pipes the given event/action to other event/action in same EventActions object.
Example of piping:
```javascript
var emitter = new EventEmitter();
var A = new EventActions();
var B = new EventActions();
// pipe emitter 'remove' event to A 'emitter:remove' action
A.pipeToAction(emitter, 'remove', 'emitter:remove');
// pipe emitter 'removed' event to B 'emitter:changed' event
B.pipeToEvent(emitter, 'changed', 'emitter:changed');
// pipe B event to other B event
B.pipeEventToEvent(':first', 'second');
// pipe B event to B action
B.pipeEventToAction(':first', 'third');
// NOTE: while piping things between two different EventActions object
// 'events' and 'actions' properties have to be used as normal EventEmitters
// when 'click' action is emitted from A, it is piped to B action 'child:action'

@@ -170,0 +195,0 @@ B.bindAction(A.actions, 'click', 'child:action');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc