diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b3dfee7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 2125666..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto \ No newline at end of file diff --git a/GruntFile.js b/GruntFile.js deleted file mode 100644 index 480e8ed..0000000 --- a/GruntFile.js +++ /dev/null @@ -1,2 +0,0 @@ -//github.com/ryanve/universal#grunt -module.exports = require('universal/GruntFile'); \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..30c9bec --- /dev/null +++ b/LICENSE.md @@ -0,0 +1 @@ +[![CC0 1.0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/) diff --git a/README.md b/README.md index 63e1063..a85284a 100644 --- a/README.md +++ b/README.md @@ -95,20 +95,3 @@ var emitter = new energy() ## Compatibility Works in [node](http://nodejs.org) **and** in any browser. Tested in node, Chrome, FF, Opera, IE8 - -## Contribute -To make edits, first [fork the repo](https://help.github.com/articles/fork-a-repo), clone your fork, and `cd` into it. Run [tests](test) via the commands below and/or in a [browser](test/index.html). Make edits in [src](src) and [test](test) as needed. Push your changes and then submit a [pull request](https://help.github.com/articles/using-pull-requests). Builds (in the [project root](../../)) are created later via `grunt` and should not be changed in pull requests. CLI commands require [node](http://nodejs.org) and the [grunt-cli](http://gruntjs.com/getting-started) on your system. - - -```sh -$ npm install -g grunt-cli # install grunt-cli if you haven't already -$ npm install # install devDependencies from package.json -$ grunt jshint:sub # lint sub dirs -$ grunt test # run tests -``` - -## Fund -Support this project by [tipping the developer](https://www.gittip.com/ryanve/) =) - -## License -MIT diff --git a/energy.js b/energy.js index d013b34..d5c4838 100644 --- a/energy.js +++ b/energy.js @@ -1,8 +1,4 @@ -/*! - * energy 0.7.1+201509080043 - * https://github.com/ryanve/energy - * @license MIT - */ +/** @preserve npm.im/energy */ !function(root, name, make) { if (typeof module != 'undefined' && module.exports) module.exports = make() else root[name] = make() diff --git a/energy.min.js b/energy.min.js deleted file mode 100644 index 8610890..0000000 --- a/energy.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * energy 0.7.1+201509080043 - * https://github.com/ryanve/energy - * @license MIT - */ -!function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=c():a[b]=c()}(this,"energy",function(){function a(a,b){for(var c in b)void 0===a[c]&&(a[c]=b[c]);return a}function b(){this[m]={}}function c(a){return a instanceof b?a[p]():new b}function d(a,b,c,d){var e=a&&a.length,f=0;for(d=void 0===d?i:d;e>f&&d!==a[f++].apply(b,c););return f}function e(a,b,c){a[b]=l.call(this,b)&&this[b]||c}function f(a,b){return a===b||!!a&&a[n]===b}function g(a,b,c){c>>=0;for(var d=a.length;d--&&(!f(a[d],b)||!a.splice(d,1)||--c););}var h=c.prototype=b.prototype,i={},j=[],k=j.slice,l=i.hasOwnProperty,m="_events",n="_origin",o="emit",p="init",q="listeners",r=function(a){return a instanceof Array&&a};return c.to=function(b){return a(b,this.call())},h.to=function(b){return a(b,this),this},h[p]=function(){return e(this,m,{}),this},h[o]=function(a){var b=k.call(arguments,1),c=d(this[q](a),this,b);return c},h[q]=function(a){if(null==a)throw new TypeError("@listeners");return this[m][a]=r(this[m][a])||[]},h.clone=function(){var c=new b(this);return a(c[m],this[m]),c},h.on=function(a,b){if(null==a||null==b)throw new TypeError("@on");return this[q](a).push(b),this},h.off=function(a,b,c){return null!=b?g(this[q](a),b,c):null!=a?this[m][a]=void 0:arguments.length||(this[m]={}),this},h.once=function(a,b){var c=this,d=function(){return c.off(a,d),b.apply(this,arguments)};return d[n]=b,this.on(a,d)},c.applies=d,c}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f636d1f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,271 @@ +{ + "name": "energy", + "version": "0.7.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "aok": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/aok/-/aok-1.9.0.tgz", + "integrity": "sha1-l/JI7tfZ8d4eb4L3puaRgYBeATk=", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", + "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", + "dev": true, + "requires": { + "exit": "0.1.2", + "glob": "7.1.2" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "dev": true, + "requires": { + "date-now": "0.1.4" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", + "dev": true + }, + "deep-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", + "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", + "dev": true + }, + "dom-serializer": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.0.tgz", + "integrity": "sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=", + "dev": true, + "requires": { + "domelementtype": "1.1.3", + "entities": "1.1.1" + }, + "dependencies": { + "domelementtype": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", + "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=", + "dev": true + }, + "entities": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", + "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", + "dev": true + } + } + }, + "domelementtype": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.0.tgz", + "integrity": "sha1-sXrtguirWeUt2cGbF1bg/BhyBMI=", + "dev": true + }, + "domhandler": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", + "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", + "dev": true, + "requires": { + "domelementtype": "1.3.0" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "dev": true, + "requires": { + "dom-serializer": "0.1.0", + "domelementtype": "1.3.0" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "htmlparser2": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", + "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", + "dev": true, + "requires": { + "domelementtype": "1.3.0", + "domhandler": "2.3.0", + "domutils": "1.5.1", + "entities": "1.0.0", + "readable-stream": "1.1.14" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "jshint": { + "version": "2.9.5", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.9.5.tgz", + "integrity": "sha1-HnJSkVzmgbQIJ+4UJIxG006apiw=", + "dev": true, + "requires": { + "cli": "1.0.1", + "console-browserify": "1.1.0", + "exit": "0.1.2", + "htmlparser2": "3.8.3", + "lodash": "3.7.0", + "minimatch": "3.0.4", + "shelljs": "0.3.0", + "strip-json-comments": "1.0.4" + } + }, + "lodash": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz", + "integrity": "sha1-Nni9irmVBXwHreg27S7wh9qBHUU=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "0.0.1", + "string_decoder": "0.10.31" + } + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=", + "dev": true + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/package.json b/package.json index 9728a5a..cf4a6f0 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,39 @@ "description": "Simple cross-platform event emitter", "version": "0.7.1", "homepage": "https://github.com/ryanve/energy", - "license": "MIT", + "license": "CC0-1.0", "author": "Ryan Van Etten", - "keywords": [ - "eventemitter", - "events", - "event", - "listener", - "emitter", - "emit", - "ender", - "server", - "browser", - "simple" - ], - "main": "./energy.js", + "main": "energy.js", "ender": "noop", "repository": { "type": "git", "url": "https://github.com/ryanve/energy.git" }, + "scripts": { + "pretest": "jshint energy.js && jshint test.js", + "test": "node test" + }, "devDependencies": { "aok": "^1.9.0", - "universal": "^0.1.1", - "grunt-contrib-uglify": "^0.9.2", - "grunt-contrib-concat": "^0.5.0", - "grunt-contrib-jshint": "^0.11.0", - "deep-equal": "^1.0.1" + "deep-equal": "^1.0.1", + "jshint": "^2.9.5" }, + "keywords": [ + "event-emitter", + "eventemitter", + "events", + "event", + "emitter", + "emit", + "ender", + "listener", + "listeners", + "on", + "pubsub", + "javascript", + "observer", + "trigger" + ], "jshintConfig": { "asi": true, "boss": true, diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 8680a1d..0000000 --- a/src/index.js +++ /dev/null @@ -1,176 +0,0 @@ -!function(root, name, make) { - if (typeof module != 'undefined' && module.exports) module.exports = make() - else root[name] = make() -}(this, 'energy', function() { - - var emitter = energy.prototype = Energy.prototype - , proceed = {} - , array = [] - , slice = array.slice - , owns = proceed.hasOwnProperty - , events = '_events' - , origin = '_origin' - , emit = 'emit' - , init = 'init' - , listeners = 'listeners' - , ifArray = function(o) { - return o instanceof Array && o - } - - function defaults(ops, defs) { - for (var k in defs) if (void 0 === ops[k]) ops[k] = defs[k] - return ops - } - - /** - * @constructor - */ - function Energy() { - this[events] = {} - } - - /** - * @return {Energy} emitter instance - */ - function energy(o) { - return o instanceof Energy ? o[init]() : new Energy - } - - /** - * @this {Function} wrapper that constructs the source instance - * @param {Object|Function} target to convert into emitter - * @return {Object|Function} target converted into emitter - */ - energy['to'] = function(target) { - return defaults(target, this.call()) - } - - /** - * @this {Object|Energy|Function} source emitter or emitter-like - * @param {Object|Energy|Function} target to convert into emitter - * @return {Object|Energy|Function} source for chaining - */ - emitter['to'] = function(target) { - defaults(target, this) - return this - } - - /** - * @param {{length:number}} fns - * @param {*} scope - * @param {Array|Arguments} args - * @param {*=} stop breaker - * @return {number} fired - */ - function applies(fns, scope, args, stop) { - var l = fns && fns.length, i = 0 - stop = void 0 === stop ? proceed : stop - while (i < l) if (stop === fns[i++].apply(scope, args)) break - return i - } - - /** - * @param {Object} o - * @param {string} k - * @param {*} def - */ - function ensure(o, k, def) { - o[k] = owns.call(this, k) && this[k] || def - } - - /** - * @param {*} listener - * @param {*} fn - * @return {boolean} true if they're the same listener - */ - function is(listener, fn) { - return listener === fn || !!listener && listener[origin] === fn - } - - /** - * @param {Array} a array to mutate - * @param {*=} v value to remove - * @param {number=} quota occurrences to remove - */ - function pull(a, v, quota) { - quota >>= 0 - // Loop down so that splices don't interfere with subsequent iterations - for (var i = a.length; i--;) if (is(a[i], v) && a.splice(i, 1) && !--quota) break - } - - /** - * @this {Energy|Object} - */ - emitter[init] = function() { - ensure(this, events, {}) - return this - } - - /** - * @param {string|number} id - * @return {number} fired - */ - emitter[emit] = function(id) { - var rest = slice.call(arguments, 1), fired = applies(this[listeners](id), this, rest) - return fired - } - - /** - * @param {string|number} id - * @return {Array} - */ - emitter[listeners] = function(id) { - if (null == id) throw new TypeError('@listeners') - return this[events][id] = ifArray(this[events][id]) || [] - } - - /** - * @return {Energy} - */ - emitter['clone'] = function() { - var clone = new Energy(this) - defaults(clone[events], this[events]) - return clone - } - - /** - * @param {string|number} id - * @param {Function} fn listener to add - * @return {Energy|Object} - */ - emitter['on'] = function on(id, fn) { - if (null == id || null == fn) throw new TypeError('@on') - this[listeners](id).push(fn) - return this - } - - /** - * @param {(string|number)=} id - * @param {Function=} fn listener to remove - * @param {number=} quota occurrences to remove (the default 0 removes all) - * @return {Energy|Object} - */ - emitter['off'] = function(id, fn, quota) { - if (null != fn) pull(this[listeners](id), fn, quota) - else if (null != id) this[events][id] = void 0 - else if (!arguments.length) this[events] = {} - return this - } - - /** - * @param {string|number} id - * @param {Function} fn one-time listener to add - * @return {Energy|Object} - */ - emitter['once'] = function(id, fn) { - var that = this, handler = function() { - that['off'](id, handler) - return fn.apply(this, arguments) - } - handler[origin] = fn - return this['on'](id, handler) - } - - energy['applies'] = applies - return energy -}); diff --git a/test/index.js b/test.js similarity index 97% rename from test/index.js rename to test.js index 5bb2d1f..4f26419 100644 --- a/test/index.js +++ b/test.js @@ -1,7 +1,7 @@ !function(root) { var common = typeof module != 'undefined' && !!module.exports , aok = common ? require('aok') : root.aok - , energy = common ? require('../src') : root.energy + , energy = common ? require('./') : root.energy , emitters = [energy(), new energy] , key = 'key' , indexOf = [].indexOf diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 3e3b7ec..0000000 --- a/test/index.html +++ /dev/null @@ -1,28 +0,0 @@ - -Tests - - -

To run tests

-

Install devDependencies

-
$ npm install
-

Browser: open the console

-

CLI: run tests via grunt aok

-
$ grunt aok
-

To edit tests

-

Edit aok tests in index.js

- - - - \ No newline at end of file