Skip to content

Commit

Permalink
Merge pull request #5 from burdiuz/rollup
Browse files Browse the repository at this point in the history
update setup, move to rolllup, update build
  • Loading branch information
burdiuz committed May 31, 2018
2 parents 1c13e56 + f2244cf commit fab9d13
Show file tree
Hide file tree
Showing 29 changed files with 6,234 additions and 6,089 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
dist/
node_modules/
6 changes: 3 additions & 3 deletions .gitattributes
@@ -1,12 +1,12 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Expand Up @@ -8,8 +8,6 @@ bower_components/
node_modules/
coverage/

*.log

# Folder config file
Desktop.ini

Expand Down
10 changes: 4 additions & 6 deletions .travis.yml
@@ -1,10 +1,8 @@
language: node_js
node_js:
- "8"
addons:
firefox: "latest"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
- webpack
- npm install rollup jest-cli eslint coveralls -g
- npm run build
- npm run lint
script: npm run test -- --coverage --coverageReporters=text-lcov | coveralls
26 changes: 12 additions & 14 deletions README.md
Expand Up @@ -6,15 +6,13 @@
Just another EventDispatcher/[EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) implementation.

## Installation
Easy to install with [bower](http://bower.io/) or [npm](https://www.npmjs.com/) package manager, by adding this repository to dependencies
Easy to install with [npm](https://www.npmjs.com/) package manager
```javascript
"dependencies": {
"event-dispatcher": "git://github.com/burdiuz/js-event-dispatcher.git"
}
npm install @actualwave/event-dispatcher
```

## Usage
`Note: When used directly in browser you may want to use "dist/event-dispatcher.direct.js" file, it provides globally accessible EventDispatcher object.
`Note: When used directly in browser you may want to use "dist/event-dispatcher.direct.js" file, it provides globally accessible EventDispatcher object.

EventDispatcher distribution package is wrapped into UMD wrapper, so it can be used with any AMD module loader, nodejs `require()` or without any.
To start using EventDispatcher, just instantiate it on its own
Expand Down Expand Up @@ -83,8 +81,8 @@ function eventPreprocessor(event){
var dispatcher = new EventDispatcher(eventPreprocessor);
dispatcher.dispatchEvent('eventType');
```
`eventPreprocessor()` function will be called with event object and returned object will be used.
`eventPreprocessor()` function will be called with event object and returned object will be used.

Example available in project's `example` folder. To try example first run server
```javascript
npm run server
Expand All @@ -94,26 +92,26 @@ And then go to [http://localhost:8081/example/index.html](http://localhost:8081/
## API

### EventDispatcher
* **addEventListener**(eventType:String, listener:Function, priority:int=0):void - Add listener to event type. Additionally priority can be set, higher values allow call listeners before others, lower -- after. Same listener can be added to event type using different priorities. By default, 0.
* **hasEventListener**(eventType:String):void - Check if listener was added to event type.
* **addEventListener**(eventType:String, listener:Function, priority:int=0):void - Add listener to event type. Additionally priority can be set, higher values allow call listeners before others, lower -- after. Same listener can be added to event type using different priorities. By default, 0.
* **hasEventListener**(eventType:String):void - Check if listener was added to event type.
* **removeEventListener**(eventType:String, listener:Function):void - Remove event listener from event of specified type.
* **removeAllEventListeners**(eventType:String):void - Remove all listeners from event of specified type.
* **dispatchEvent**(eventType:String, data:Object=null):void - Dispatch event of `eventType` and pass `data`. Will create object of built-in class Event and pass it as first argument to listeners.
* **dispatchEvent**(event:Object):void - Event object that should be fired, can be any object. Only requirement -- it must contain field `type` with event type.

EventDispatcher constructor accepts optional argument `eventPreprocessor(event:Object):Object`, function that receive event object as argument and should return same or new/changed event object that will be passed to event listeners.
EventDispatcher constructor accepts optional argument `eventPreprocessor(event:Object):Object`, function that receive event object as argument and should return same or new/changed event object that will be passed to event listeners.

### Event
Built-in class to represent dispatched event.
Objects of Event class are used when dispatchEvent() method is called with `eventType`.
Objects of Event class are used when dispatchEvent() method is called with `eventType`.
* **type**:String - Event type.
* **data**:Object - Data object passed to `EventDispatcher.dispatchEvent()` method.
* **preventDefault**():void - Will change "prevented" flag from FALSE to TRUE, it can be requested via `isDefaultPrevented()` method.
* **isDefaultPrevented**():Boolean - Will return TRUE if `preventDefault()` was called.

Any event(instance of built-in Event class or any other object passed as event) gains additional methods when its being dispatched. After cycle finished, these methods will be removed from event object.
* **stopPropagation**():void - Stop event propagation after processing all listeners of same priority.
* **stopImmediatePropagation**():void - Stop event propagation on current listener.
* **stopImmediatePropagation**():void - Stop event propagation on current listener.


> Written with [StackEdit](https://stackedit.io/).
44 changes: 0 additions & 44 deletions bower.json

This file was deleted.

4 changes: 2 additions & 2 deletions dist/event-dispatcher.direct.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/event-dispatcher.direct.js.map

Large diffs are not rendered by default.

0 comments on commit fab9d13

Please sign in to comment.