added unit testing, and started implementing unit tests...phew
This commit is contained in:
6
node_modules/yaeti/.jscsrc
generated
vendored
Normal file
6
node_modules/yaeti/.jscsrc
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"preset": "crockford",
|
||||
"validateIndentation": "\t",
|
||||
"disallowKeywords": ["with"],
|
||||
"disallowDanglingUnderscores": null
|
||||
}
|
27
node_modules/yaeti/.jshintrc
generated
vendored
Normal file
27
node_modules/yaeti/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"bitwise": false,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
"freeze": true,
|
||||
"latedef": "function",
|
||||
"noarg": true,
|
||||
"nonbsp": true,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"strict": false,
|
||||
"maxparams": 6,
|
||||
"maxdepth": 4,
|
||||
"maxstatements": false,
|
||||
"maxlen": 200,
|
||||
"browser": true,
|
||||
"browserify": true,
|
||||
"devel": true,
|
||||
"jquery": false,
|
||||
"mocha": true,
|
||||
"node": false,
|
||||
"shelljs": false,
|
||||
"worker": false
|
||||
}
|
1
node_modules/yaeti/.npmignore
generated
vendored
Normal file
1
node_modules/yaeti/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
/node_modules/
|
21
node_modules/yaeti/LICENSE
generated
vendored
Normal file
21
node_modules/yaeti/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Iñaki Baz Castillo, <ibc@aliax.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
98
node_modules/yaeti/README.md
generated
vendored
Normal file
98
node_modules/yaeti/README.md
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
# yaeti
|
||||
|
||||
Yet Another [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) Implementation.
|
||||
|
||||
The library exposes both the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface and the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install yaeti --save
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var yaeti = require('yaeti');
|
||||
|
||||
|
||||
// Custom class we want to make an EventTarget.
|
||||
function Foo() {
|
||||
// Make Foo an EventTarget.
|
||||
yaeti.EventTarget.call(this);
|
||||
}
|
||||
|
||||
// Create an instance.
|
||||
var foo = new Foo();
|
||||
|
||||
function listener1() {
|
||||
console.log('listener1');
|
||||
}
|
||||
|
||||
function listener2() {
|
||||
console.log('listener2');
|
||||
}
|
||||
|
||||
foo.addEventListener('bar', listener1);
|
||||
foo.addEventListener('bar', listener2);
|
||||
foo.removeEventListener('bar', listener1);
|
||||
|
||||
var event = new yaeti.Event('bar');
|
||||
|
||||
foo.dispatchEvent(event);
|
||||
|
||||
|
||||
// Output:
|
||||
// => "listener2"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## API
|
||||
|
||||
|
||||
#### `yaeti.EventTarget` interface
|
||||
|
||||
Implementation of the [EventTarget](https://developer.mozilla.org/es/docs/Web/API/EventTarget) interface.
|
||||
|
||||
* Make a custom class inherit from `EventTarget`:
|
||||
```javascript
|
||||
function Foo() {
|
||||
yaeti.EventTarget.call(this);
|
||||
}
|
||||
```
|
||||
|
||||
* Make an existing object an `EventTarget`:
|
||||
```javascript
|
||||
yaeti.EventTarget.call(obj);
|
||||
```
|
||||
|
||||
The interface implements the `addEventListener`, `removeEventListener` and `dispatchEvent` methods as defined by the W3C.
|
||||
|
||||
|
||||
##### `listeners` read-only property
|
||||
|
||||
Returns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types.
|
||||
|
||||
|
||||
#### `yaeti.Event` interface
|
||||
|
||||
Implementation of the [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) interface.
|
||||
|
||||
*NOTE:* Just useful in Node (the browser already exposes the native `Event` interface).
|
||||
|
||||
```javascript
|
||||
var event = new yaeti.Event('bar');
|
||||
```
|
||||
|
||||
|
||||
## Author
|
||||
|
||||
[Iñaki Baz Castillo](https://github.com/ibc)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE)
|
23
node_modules/yaeti/gulpfile.js
generated
vendored
Normal file
23
node_modules/yaeti/gulpfile.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
var
|
||||
/**
|
||||
* Dependencies.
|
||||
*/
|
||||
gulp = require('gulp'),
|
||||
jscs = require('gulp-jscs'),
|
||||
jshint = require('gulp-jshint'),
|
||||
stylish = require('gulp-jscs-stylish');
|
||||
|
||||
|
||||
gulp.task('lint', function () {
|
||||
var src = ['gulpfile.js', 'index.js', 'lib/**/*.js'];
|
||||
|
||||
return gulp.src(src)
|
||||
.pipe(jshint('.jshintrc')) // Enforce good practics.
|
||||
.pipe(jscs('.jscsrc')) // Enforce style guide.
|
||||
.pipe(stylish.combineWithHintResults())
|
||||
.pipe(jshint.reporter('jshint-stylish', {verbose: true}))
|
||||
.pipe(jshint.reporter('fail'));
|
||||
});
|
||||
|
||||
|
||||
gulp.task('default', gulp.task('lint'));
|
4
node_modules/yaeti/index.js
generated
vendored
Normal file
4
node_modules/yaeti/index.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
EventTarget : require('./lib/EventTarget'),
|
||||
Event : require('./lib/Event')
|
||||
};
|
5
node_modules/yaeti/lib/Event.browser.js
generated
vendored
Normal file
5
node_modules/yaeti/lib/Event.browser.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* In browsers export the native Event interface.
|
||||
*/
|
||||
|
||||
module.exports = global.Event;
|
13
node_modules/yaeti/lib/Event.js
generated
vendored
Normal file
13
node_modules/yaeti/lib/Event.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Expose the Event class.
|
||||
*/
|
||||
module.exports = _Event;
|
||||
|
||||
|
||||
function _Event(type) {
|
||||
this.type = type;
|
||||
this.isTrusted = false;
|
||||
|
||||
// Set a flag indicating this is not a DOM Event object
|
||||
this._yaeti = true;
|
||||
}
|
119
node_modules/yaeti/lib/EventTarget.js
generated
vendored
Normal file
119
node_modules/yaeti/lib/EventTarget.js
generated
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Expose the _EventTarget class.
|
||||
*/
|
||||
module.exports = _EventTarget;
|
||||
|
||||
function _EventTarget() {
|
||||
// Do nothing if called for a native EventTarget object..
|
||||
if (typeof this.addEventListener === 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
this._listeners = {};
|
||||
|
||||
this.addEventListener = _addEventListener;
|
||||
this.removeEventListener = _removeEventListener;
|
||||
this.dispatchEvent = _dispatchEvent;
|
||||
}
|
||||
|
||||
Object.defineProperties(_EventTarget.prototype, {
|
||||
listeners: {
|
||||
get: function () {
|
||||
return this._listeners;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function _addEventListener(type, newListener) {
|
||||
var
|
||||
listenersType,
|
||||
i, listener;
|
||||
|
||||
if (!type || !newListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
listenersType = this._listeners[type];
|
||||
if (listenersType === undefined) {
|
||||
this._listeners[type] = listenersType = [];
|
||||
}
|
||||
|
||||
for (i = 0; !!(listener = listenersType[i]); i++) {
|
||||
if (listener === newListener) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
listenersType.push(newListener);
|
||||
}
|
||||
|
||||
function _removeEventListener(type, oldListener) {
|
||||
var
|
||||
listenersType,
|
||||
i, listener;
|
||||
|
||||
if (!type || !oldListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
listenersType = this._listeners[type];
|
||||
if (listenersType === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; !!(listener = listenersType[i]); i++) {
|
||||
if (listener === oldListener) {
|
||||
listenersType.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (listenersType.length === 0) {
|
||||
delete this._listeners[type];
|
||||
}
|
||||
}
|
||||
|
||||
function _dispatchEvent(event) {
|
||||
var
|
||||
type,
|
||||
listenersType,
|
||||
dummyListener,
|
||||
stopImmediatePropagation = false,
|
||||
i, listener;
|
||||
|
||||
if (!event || typeof event.type !== 'string') {
|
||||
throw new Error('`event` must have a valid `type` property');
|
||||
}
|
||||
|
||||
// Do some stuff to emulate DOM Event behavior (just if this is not a
|
||||
// DOM Event object)
|
||||
if (event._yaeti) {
|
||||
event.target = this;
|
||||
event.cancelable = true;
|
||||
}
|
||||
|
||||
// Attempt to override the stopImmediatePropagation() method
|
||||
try {
|
||||
event.stopImmediatePropagation = function () {
|
||||
stopImmediatePropagation = true;
|
||||
};
|
||||
} catch (error) {}
|
||||
|
||||
type = event.type;
|
||||
listenersType = (this._listeners[type] || []);
|
||||
|
||||
dummyListener = this['on' + type];
|
||||
if (typeof dummyListener === 'function') {
|
||||
dummyListener.call(this, event);
|
||||
}
|
||||
|
||||
for (i = 0; !!(listener = listenersType[i]); i++) {
|
||||
if (stopImmediatePropagation) {
|
||||
break;
|
||||
}
|
||||
|
||||
listener.call(this, event);
|
||||
}
|
||||
|
||||
return !event.defaultPrevented;
|
||||
}
|
57
node_modules/yaeti/package.json
generated
vendored
Normal file
57
node_modules/yaeti/package.json
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"_from": "yaeti@^0.0.6",
|
||||
"_id": "yaeti@0.0.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=",
|
||||
"_location": "/yaeti",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "yaeti@^0.0.6",
|
||||
"name": "yaeti",
|
||||
"escapedName": "yaeti",
|
||||
"rawSpec": "^0.0.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.0.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/websocket"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||
"_shasum": "f26f484d72684cf42bedfb76970aa1608fbf9577",
|
||||
"_spec": "yaeti@^0.0.6",
|
||||
"_where": "/Users/josh.burman/Projects/braid/node_modules/websocket",
|
||||
"author": {
|
||||
"name": "Iñaki Baz Castillo",
|
||||
"email": "ibc@aliax.net"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/Event.js": "./lib/Event.browser.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ibc/yaeti/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Yet Another EventTarget Implementation",
|
||||
"devDependencies": {
|
||||
"gulp": "git+https://github.com/gulpjs/gulp.git#4.0",
|
||||
"gulp-jscs": "^1.6.0",
|
||||
"gulp-jscs-stylish": "^1.1.0",
|
||||
"gulp-jshint": "^1.11.2",
|
||||
"jshint-stylish": "~1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.32"
|
||||
},
|
||||
"homepage": "https://github.com/ibc/yaeti#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "yaeti",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ibc/yaeti.git"
|
||||
},
|
||||
"version": "0.0.6"
|
||||
}
|
Reference in New Issue
Block a user