Skip to content

Commit

Permalink
Simplified the usage by self invoking the function when it isrequired…
Browse files Browse the repository at this point in the history
… or imported
  • Loading branch information
Galeel Bhasha Satthar committed Oct 30, 2017
1 parent 987e7c9 commit 75229c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
27 changes: 12 additions & 15 deletions CustomEvent.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
function CustomEvent ( event, params ) {
params = params || {
bubbles: false,
cancelable: false,
detail: undefined,
};
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
(function() {
if (typeof window === "undefined") return false;
if (typeof window.CustomEvent === "function") return false;

function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}

module.exports = function ( undefined ) {
if ( typeof window.CustomEvent === 'function' ) {
return;
};
CustomEvent.prototype = window.Event.prototype;

window.CustomEvent = CustomEvent;
};
})();
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ npm install --save-dev jspolyfill-custom-event
# Usage

```js
require( 'jspolyfill-custom-event' )();
require('jspolyfill-custom-event');
```

or

```js
import('jspolyfill-custom-event');
```

**Note**: Make sure to add the extra set of parenthesis at the end to fire the `function` that
registers the creation of the polyfill.

# Syntax

Expand Down

1 comment on commit 75229c1

@gbhasha
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the usage. Self-invoking function helps us to get rid of adding the extra set of parenthesis during the import or require.

Please sign in to comment.