@springernature/global-javascript
Advanced tools
Comparing version 2.0.0 to 2.1.0
# 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` |
{ | ||
"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}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9467
10
195
107