Skip to content

Commit 1d130d5

Browse files
authored
Merge pull request #2 from burdiuz/rollup
Update build process, webpack > rollup, chai+sinon > jest
2 parents f339a34 + 36560e9 commit 1d130d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+11056
-17575
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# Matches multiple files with brace expansion notation
12+
# Set default charset
13+
[*.js]
14+
charset = utf-8
15+
indent_style = space
16+
indent_size = 2
17+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

.eslintrc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
"browser": true,
1313
"node": true
1414
},
15+
"globals": {
16+
"jest": true,
17+
"describe": true,
18+
"it": true,
19+
"test": true,
20+
"expect": true,
21+
"should": true,
22+
"assert": true,
23+
"beforeEach": true,
24+
"afterEach": true,
25+
"beforeAll": true,
26+
"afterAll": true,
27+
"before": true,
28+
"after": true
29+
},
1530
"rules": {
1631
"arrow-parens": [
1732
"error",
@@ -25,6 +40,10 @@
2540
],
2641
"no-param-reassign": 1,
2742
"padded-blocks": 0,
28-
"no-plusplus": 0
43+
"no-plusplus": 0,
44+
"function-paren-newline": 0,
45+
"object-curly-newline": 0,
46+
"no-bitwise": 0,
47+
"max-len": ["error", { "code": 120 }]
2948
}
3049
}

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=auto eol=lf
33

44
# Custom for Visual Studio
55
*.cs diff=csharp

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Thumbs.db
33
ehthumbs.db
44

55
.idea/
6+
.history/
7+
.vscode/
68

79
bower_components/
810
node_modules/

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.*
2+
docs/
3+
coverage/
4+
fixtures/
5+
source/
6+
__tests__/
7+
rollup.*

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"arrowParens": "always",
5+
"parser": "flow",
6+
"printWidth": 80
7+
}

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
language: node_js
22
node_js:
33
- "8"
4-
addons:
5-
firefox: "latest"
64
before_script:
7-
- export DISPLAY=:99.0
8-
- sh -e /etc/init.d/xvfb start
9-
- sleep 3
10-
- webpack
5+
- npm install rollup jest-cli eslint coveralls -g
6+
- npm run build
7+
- npm run lint
8+
script: npm run test -- --coverage --coverageReporters=text-lcov | coveralls

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,41 @@
33
[![Build Status](https://travis-ci.org/burdiuz/js-worker-event-dispatcher.svg?branch=master)](https://travis-ci.org/burdiuz/js-worker-event-dispatcher)
44
[![Coverage Status](https://coveralls.io/repos/github/burdiuz/js-worker-event-dispatcher/badge.svg?branch=master)](https://coveralls.io/github/burdiuz/js-worker-event-dispatcher?branch=master)
55

6-
> Note: This project was renamed from WorkerEventDispatcher and its API was slightly updated, so this readme may be not relevant until(i hope, short coming) review.
7-
86
This is extension of [MessagePortDispatcher](https://github.com/burdiuz/js-messageport-event-dispatcher) to work with Dedicated and Shared Workers. It makes possible two-way communication with Workers using custom events. So, instead of using `postMessage()` and catching `message` event all the time, you are free to send any type of events to and from worker.
97

8+
[Demo with dedicated and shared workers](http://burdiuz.github.io/js-worker-event-dispatcher/index.html)
9+
1010
## Installation
11-
WorkerDispatcher is available via [bower](http://bower.io/)
12-
```
13-
bower install worker-event-dispatcher --save
11+
Easy to install with [npm](https://www.npmjs.com/) package manager
12+
```javascript
13+
npm install --save @actualwave/worker-dispatcher
1414
```
15-
If you want to use it with [npm](https://www.npmjs.com/) package manger, add it to `dependencies`section of your package.json file.
15+
with [yarn](https://yarnpkg.com/) package manager
1616
```javascript
17-
"dependencies": {
18-
"worker-event-dispatcher": "git://github.com/burdiuz/js-worker-event-dispatcher.git"
19-
}
17+
yarn add @actualwave/worker-dispatcher
2018
```
21-
Also WorkerDispatcher has standalone distribution file that includes all dependencies, so you can just [download single file](https://github.com/burdiuz/js-worker-event-dispatcher/blob/master/dist/worker-event-dispatcher.standalone.min.js) with everything needed to start using it.
2219

2320
## Usage
24-
WorkerDispatcher should be used on HTML page and in Worker script to properly handle communication.
21+
> Note: WorkerDispatcher distribution package contains `dist/` folder with package wrapped into [UMD](https://github.com/umdjs/umd) wrapper, so it can be used with any AMD module loader, nodejs `require()` or without any.
22+
23+
**WorkerDispatcher should be used on HTML page and in Worker script to properly handle communication.**
2524

2625
#### Dedicated Worker
27-
WorkerDispatcher for Dedicated Worker can be created via operator `new`
28-
```javascript
29-
var worker = new Worker('/workers/worker.js');
30-
var dispatcher = new WorkerDispatcher(worker);
31-
```
32-
or `WorkerDispatcher.create()` factory method
26+
WorkerDispatcher for Dedicated Worker can be created via `WorkerDispatcher.create()` factory function
3327
```javascript
3428
var worker = new Worker('/workers/worker.js');
3529
var dispatcher = WorkerDispatcher.create(worker);
36-
/* or you can specify worker type */
30+
/* or you can explicitly specify worker type */
3731
var dispatcher = WorkerDispatcher.create(worker, WorkerDispatcher.DEDICATED_WORKER);
3832
```
3933
Within Worker script it can be created via `WorkerDispatcher.createForSelf()`, don't need to pass anything, it grabs Worker's global scope object to communicate.
40-
```javascript
34+
```javascript
4135
var dispatcher = WorkerDispatcher.createForSelf();
4236
```
4337
WorkerDispatcher accepts Worker objects or string URL to JS file that should be launched in worker.
4438
Here Worker will be created from passed URL string:
4539
```javascript
46-
var dispatcher = new WorkerDispatcher('/workers/worker.js');
40+
var dispatcher = WorkerDispatcher.create('/workers/worker.js');
4741
```
4842

4943
#### Shared Worker
@@ -68,8 +62,8 @@ dispatcher.addEventListener(WorkerDispatcher.WorkerEvent.CONNECT, function(event
6862

6963
#### Sending and receiving messages
7064
To send messages use `dispatchEvent()` event and to receive messages add event listeners. Sent events will not be fired for sender dispatcher, so you cannot listen for event you just sent
71-
```javascript
72-
var dispatcher = new WorkerDispatcher('/workers/worker.js');
65+
```javascript
66+
var dispatcher = WorkerDispatcher.create('/workers/worker.js');
7367
dispatcher.addEventListener('anyEvent', function(){
7468
console.log('Event received');
7569
});
@@ -101,7 +95,7 @@ Project contains `example` folder with examples for Dedicated and Shared workers
10195
#### WorkerDispatcher shared instance members
10296
WorkerDispatcher is a base class and it shares functionality across all types of WorkerDispatcher's. When WorkerDispatcher instantiated directly, it actually creates DedicatedWorkerDispatcher.
10397

104-
- **type**:String - type of the worker
98+
- **type**:String - type of the worker
10599
Including [all members of MessagePortDispatcher](https://github.com/burdiuz/js-messageport-event-dispatcher/blob/master/README.md#messageportdispatcher-instance-members), some most important:
106100
- **addEventListener**(eventType:String, listener:Function):void - add listener for incoming events. This method copied from `receiver`.
107101
- **hasEventListener**(eventType:String):Boolean - check if incoming event has listeners. This method copied from `receiver`.
@@ -117,19 +111,19 @@ Including [all members of MessagePortDispatcher](https://github.com/burdiuz/js-m
117111
- **create**(target:String|Worker|SharedWorker, type?:String, receiverEventPreprocessor?:Function, senderEventPreprocessor?:Function):WorkerDispatcher - Creates WorkerDispatcher instance based on type. Currently supported types are `WorkerDispatcher.DEDICATED_WORKER` and `WorkerDispatcher.SHARED_WORKER`. By default will create dispatcher for Dedicated Worker.
118112
- **self**(receiverEventPreprocessor?:Function, senderEventPreprocessor?:Function):WorkerDispatcher - Can be used in Worker script, it checks what kind of worker is used and returns proper dispatcher object for WorkerGlobalScope. For Dedicated Worker returns instance of DedicatedWorkerDispatcher and for Shared Worker -- ServerEventDispatcher.
119113

120-
- WorkerEvent:Object - Worker event types
114+
- WorkerEvent:Object - Worker event types
121115
- CONNECT:String - Mirroring connect event fired from WorkerGlobalScope, fired when new client connected. Event object contains field `client` with `ClientEventDispatcher` instance, to communicate with client.
122116
- ERROR:String - Mirroring [error event](https://developer.mozilla.org/en-US/docs/Web/Events/error) fired from WorkerGlobalScope
123117
- LANGUAGECHANGE:String - Mirroring [languagechange event](https://developer.mozilla.org/en-US/docs/Web/Events/languagechange) fired from WorkerGlobalScope
124-
- ONLINE:String - Mirroring [online event](https://developer.mozilla.org/en-US/docs/Web/Events/online) fired from WorkerGlobalScope
118+
- ONLINE:String - Mirroring [online event](https://developer.mozilla.org/en-US/docs/Web/Events/online) fired from WorkerGlobalScope
125119
- OFFLINE:String - Mirroring [offline event](https://developer.mozilla.org/en-US/docs/Web/Events/offline) fired from WorkerGlobalScope
126120
- WorkerType:Object - Possible dispatcher types, used with `WorkerDispatcher.create()`
127121
- DEDICATED_WORKER:String - Default type, will create DedicatedWorkerDispatcher
128122
- SHARED_WORKER:String - Will create SharedWorkerDispatcher
129123
- SHARED_WORKER_SERVER:String - For internal usage, will create ServerEventDispatcher
130124
- SHARED_WORKER_CLIENT:String - For internal usage, will create ClientEventDispatcher
131125
- DedicatedWorker:Function - Constructor of DedicatedWorkerDispatcher
132-
- SharedWorker:Function - Constructor of SharedWorkerDispatcher
126+
- SharedWorker:Function - Constructor of SharedWorkerDispatcher
133127
- Server:Function - Constructor of ServerEventDispatcher
134128
- Client:Function - Constructor of ClientEventDispatcher
135129

@@ -143,7 +137,7 @@ Created when `WorkerDispatcher.DEDICATED_WORKER` used, when `WorkerDispatcher.cr
143137
Created when WorkerDispatcher.SHARED_WORKER used. When created using `WorkerDispatcher.create()`, worker's name will default to `null`, if you need to specify name, you can instantiate it with constructor.
144138
```javascript
145139
var dispatcher = new WorkerDispatcher.SharedWorkerDispatcher('/workers/sharedworker.js', 'worker-name');
146-
```
140+
```
147141

148142
#### ServerEventDispatcher
149143
Created when WorkerDispatcher.createForSelf() called in Shared Worker. It differs from other types of WorkerDispatcher's because **does not have `dispatchEvent()` method**, so it can only listen for events, like WorkerEvent.CONNECT to accept connections. Since it cannot send data, it does not have `sender` EventDispatcher either, only `receiver` available.
@@ -167,7 +161,7 @@ dispatcher.addEventListener(WorkerDispatcher.WorkerEvent.CONNECT, function(event
167161
client.dispatchEvent('initialize');
168162
});
169163
```
170-
164+
171165
### Links
172166
[MDN - Using web workers](https://developer.mozilla.org/ru/docs/DOM/Using_web_workers)
173167
[https://www.w3.org/TR/workers/](https://www.w3.org/TR/workers/)

bower.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)