Socket
Socket
Sign inDemoInstall

@springernature/global-javascript

Package Overview
Dependencies
Maintainers
12
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@springernature/global-javascript - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

__tests__/unit/util/create-event.spec.js

3

HISTORY.md
# History
## 2.1.0 (2020-06-17)
* FEATURE: createEvent, custom namespaced events
## 2.0.0 (2020-05-13)

@@ -4,0 +7,0 @@ * BREAKING: Rename folder from `js` to `src`

2

package.json
{
"name": "@springernature/global-javascript",
"version": "2.0.0",
"version": "2.1.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Globally shared Javascript helpers",

@@ -19,2 +19,3 @@ # Global Javascript

- [makeArray](#makearray)
- [createEvent](#createevent)

@@ -37,6 +38,32 @@

elementsArray.forEach(element => {
// Do something
// Do something
});
```
#### createEvent
Simple wrapper for [`customEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) that enforces an event namespace of the form `namespace:event`.
This should be the **default** method for component module communication, where the name of the component is used as the namespace.
```javascript
const elementToBind = document.getElementById('element');
// Create event namespaced to component
const event = createEvent('eventName', 'componentName', {
bubbles:true,
cancelable: true,
detail: {
hazcheeseburger: true
}
});
// Dispatch event
elementToBind.dispatchEvent(event);
// Listen for event
elementToBind.addEventListener('componentName:eventName', function (event) {
// Do something
}, false);
```
### Dom

@@ -56,5 +83,5 @@ Dom helpers are used to help achieve JavaScript tasks that involve getting information from, or manipulating the DOM.

const DataOptions = {
OPTION_1: 'data-mycomponent-option1',
OPTION_2: 'data-mycomponent-option2',
OPTION_3: 'data-mycomponent-option3',
OPTION_1: 'data-mycomponent-option1',
OPTION_2: 'data-mycomponent-option2',
OPTION_3: 'data-mycomponent-option3',
};

@@ -61,0 +88,0 @@

// Util
import {makeArray} from './util/make-array';
import {createEvent} from './util/create-event';

@@ -7,2 +8,2 @@ // Dom

export {makeArray, getDataOptions};
export {makeArray, createEvent, getDataOptions};
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