Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electrum-events

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electrum-events - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

8

lib/event-handlers.js

@@ -42,2 +42,3 @@ 'use strict';

};
this._obj._eventHandlers = this;

@@ -157,3 +158,3 @@ if (typeof bus === 'function') {

if (typeof this._debug === 'function') {
this._debug(source, ev);
this._debug(this.component, source, ev);
} else {

@@ -165,2 +166,7 @@ console.log(source + ': %O', ev);

}, {
key: 'component',
get: function get() {
return this._obj;
}
}, {
key: 'props',

@@ -167,0 +173,0 @@ get: function get() {

2

package.json
{
"name": "electrum-events",
"version": "1.1.1",
"version": "1.1.2",
"description": "Electrum Events forwards web component events to the bus.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,3 +5,3 @@ # Electrum Events

[![Build Status](https://travis-ci.org/epsitec-sa/electrum-events.svg?branch=master)](https://travis-ci.org/epsitec-sa/electrum-events)
[![Build status](https://ci.appveyor.com/api/projects/status/8c6nooep3fbnoytc?svg=true)](https://ci.appveyor.com/project/epsitec/electrum-events)
[![Build status](https://ci.appveyor.com/api/projects/status/0kuudrbhwiunp0k0?svg=true)](https://ci.appveyor.com/project/epsitec/electrum-events)

@@ -25,2 +25,34 @@ The `electrum-events` module forwards web component events to the bus.

# Using EventHandlers
Usually, you won't use `EventHandlers` yourself. It is Electrum's
responsibility to _inject_ the handlers into wrapped components.
This is handled by Electrum's `InjectingMiddleware`:
```javascript
class Electrum {
...
reset () {
...
this._injectingMiddleware = new InjectingMiddleware ();
this._injectingMiddleware.register ('events', obj => {
obj._eventHandlers = EventHandlers.inject (obj, () => this.bus);
});
...
}
}
```
The instance of the event handlers class attached to a component
can be accessed through `obj._eventHandlers`. This might be useful
when debugging (see below).
# EventHandlers properties
Every event handlers instance provides the following public properties:
* `component` → the component to which the handlers are attached.
* `props` → the properties of the component.
* `bus` → the bus to which the events will be sent.
# Debug with active logging

@@ -36,7 +68,8 @@

const eh = new EventHandlers (obj, bus);
eh.debug = (source, event) => { /* ... */ };
eh.debug = (component, source, event) => { /* ... */ };
```
The `source` argument will be one of `focus`, `change`, `key-down`,
`key-up`, `key-press` and `select`, while the `event` property gives
full access to the event being processed.
The `component` argument refers to the component on which the event
was notified. The `source` argument is one of `focus`, `change`,
`key-down`, `key-up`, `key-press` and `select`, while the `event`
argument gives full access to the event being processed.

@@ -22,2 +22,3 @@ 'use strict';

this._statesGetter = target => getStates (target);
this._obj._eventHandlers = this;

@@ -31,2 +32,6 @@ if (typeof bus === 'function') {

get component () {
return this._obj;
}
get props () {

@@ -157,3 +162,3 @@ return this._obj.props;

if (typeof this._debug === 'function') {
this._debug (source, ev);
this._debug (this.component, source, ev);
} else {

@@ -160,0 +165,0 @@ console.log (`${source}: %O`, ev);

@@ -22,3 +22,11 @@ 'use strict';

expect (eh).to.have.property ('bus', undefined);
expect (eh).to.have.property ('component', emptyObj);
});
it ('attaches EventHandlers to component', () => {
delete emptyObj._eventHandlers;
expect (emptyObj._eventHandlers).to.be.undefined ();
const eh = new EventHandlers (emptyObj);
expect (emptyObj._eventHandlers).to.equal (eh);
});
});

@@ -127,3 +135,6 @@

let log = '';
eh.debug = (s, e) => log = `${s}: ${e.target.value}`;
eh.debug = (c, s, e) => {
expect (c).to.equal (emptyObj);
log = `${s}: ${e.target.value}`;
};
ev.target = {value: 'x', nodeName: 'INPUT', nodeType: 1};

@@ -130,0 +141,0 @@ eh.handleKeyDown (ev);

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