deku 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE +25 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/deku.gemspec +23 -0
- data/deps/node_modules/deku.js +2 -0
- data/deps/node_modules/deku/.editorconfig +16 -0
- data/deps/node_modules/deku/.zuul.yml +15 -0
- data/deps/node_modules/deku/History.md +290 -0
- data/deps/node_modules/deku/LICENSE.md +7 -0
- data/deps/node_modules/deku/Makefile +91 -0
- data/deps/node_modules/deku/README.md +293 -0
- data/deps/node_modules/deku/index.js +4072 -0
- data/deps/node_modules/deku/lib/application.js +85 -0
- data/deps/node_modules/deku/lib/index.js +28 -0
- data/deps/node_modules/deku/lib/render.js +1300 -0
- data/deps/node_modules/deku/lib/stringify.js +105 -0
- data/deps/node_modules/deku/lib/svg.js +107 -0
- data/deps/node_modules/deku/lib/utils.js +18 -0
- data/deps/node_modules/deku/lib/virtual.js +247 -0
- data/deps/node_modules/deku/node_modules/array-flatten/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/array-flatten/README.md +43 -0
- data/deps/node_modules/deku/node_modules/array-flatten/array-flatten.js +57 -0
- data/deps/node_modules/deku/node_modules/array-flatten/package.json +62 -0
- data/deps/node_modules/deku/node_modules/component-emitter/History.md +63 -0
- data/deps/node_modules/deku/node_modules/component-emitter/LICENSE +24 -0
- data/deps/node_modules/deku/node_modules/component-emitter/Readme.md +74 -0
- data/deps/node_modules/deku/node_modules/component-emitter/index.js +161 -0
- data/deps/node_modules/deku/node_modules/component-emitter/package.json +174 -0
- data/deps/node_modules/deku/node_modules/component-raf/.npmignore +2 -0
- data/deps/node_modules/deku/node_modules/component-raf/History.md +26 -0
- data/deps/node_modules/deku/node_modules/component-raf/Makefile +11 -0
- data/deps/node_modules/deku/node_modules/component-raf/Readme.md +46 -0
- data/deps/node_modules/deku/node_modules/component-raf/component.json +16 -0
- data/deps/node_modules/deku/node_modules/component-raf/example.html +43 -0
- data/deps/node_modules/deku/node_modules/component-raf/index.js +34 -0
- data/deps/node_modules/deku/node_modules/component-raf/package.json +164 -0
- data/deps/node_modules/deku/node_modules/component-type/.npmignore +3 -0
- data/deps/node_modules/deku/node_modules/component-type/Makefile +14 -0
- data/deps/node_modules/deku/node_modules/component-type/Readme.md +37 -0
- data/deps/node_modules/deku/node_modules/component-type/component.json +13 -0
- data/deps/node_modules/deku/node_modules/component-type/index.js +34 -0
- data/deps/node_modules/deku/node_modules/component-type/package.json +120 -0
- data/deps/node_modules/deku/node_modules/component-type/test/index.html +17 -0
- data/deps/node_modules/deku/node_modules/component-type/test/mocha.css +231 -0
- data/deps/node_modules/deku/node_modules/component-type/test/mocha.js +5340 -0
- data/deps/node_modules/deku/node_modules/component-type/test/tests.js +72 -0
- data/deps/node_modules/deku/node_modules/dom-pool/.npmignore +1 -0
- data/deps/node_modules/deku/node_modules/dom-pool/Pool.js +52 -0
- data/deps/node_modules/deku/node_modules/dom-pool/README.md +42 -0
- data/deps/node_modules/deku/node_modules/dom-pool/authors.txt +4 -0
- data/deps/node_modules/deku/node_modules/dom-pool/bower.json +26 -0
- data/deps/node_modules/deku/node_modules/dom-pool/package.json +46 -0
- data/deps/node_modules/deku/node_modules/dom-pool/tests.html +16 -0
- data/deps/node_modules/deku/node_modules/dom-pool/tests.js +102 -0
- data/deps/node_modules/deku/node_modules/dom-walk/.npmignore +3 -0
- data/deps/node_modules/deku/node_modules/dom-walk/LICENCE +19 -0
- data/deps/node_modules/deku/node_modules/dom-walk/Makefile +2 -0
- data/deps/node_modules/deku/node_modules/dom-walk/README.md +23 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/index.js +5 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/static/bundle.js +211 -0
- data/deps/node_modules/deku/node_modules/dom-walk/example/static/index.html +16 -0
- data/deps/node_modules/deku/node_modules/dom-walk/index.js +24 -0
- data/deps/node_modules/deku/node_modules/dom-walk/package.json +57 -0
- data/deps/node_modules/deku/node_modules/fast.js/.jshintignore +7 -0
- data/deps/node_modules/deku/node_modules/fast.js/.jshintrc +80 -0
- data/deps/node_modules/deku/node_modules/fast.js/.npmignore +6 -0
- data/deps/node_modules/deku/node_modules/fast.js/.travis.yml +3 -0
- data/deps/node_modules/deku/node_modules/fast.js/LICENSE.md +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/README.md +552 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/clone.js +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/concat.js +32 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/every.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/fill.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/filter.js +26 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/forEach.js +21 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/index.js +15 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/indexOf.js +33 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/lastIndexOf.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/map.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/pluck.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/reduce.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/reduceRight.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/array/some.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/bower.json +28 -0
- data/deps/node_modules/deku/node_modules/fast.js/clone.js +27 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/bench.html +15 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/bench.js +19900 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/fast.js +1450 -0
- data/deps/node_modules/deku/node_modules/fast.js/dist/fast.min.js +1 -0
- data/deps/node_modules/deku/node_modules/fast.js/filter.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/forEach.js +22 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/apply.js +19 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/applyNoContext.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/applyWithContext.js +29 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bind.js +71 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bindInternal3.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/bindInternal4.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/index.js +7 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/partial.js +42 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/partialConstructor.js +45 -0
- data/deps/node_modules/deku/node_modules/fast.js/function/try.js +35 -0
- data/deps/node_modules/deku/node_modules/fast.js/index.js +241 -0
- data/deps/node_modules/deku/node_modules/fast.js/map.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/assign.js +34 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/clone.js +25 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/filter.js +28 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/forEach.js +23 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/index.js +11 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/keys.js +17 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/map.js +26 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/reduce.js +37 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/reduceRight.js +37 -0
- data/deps/node_modules/deku/node_modules/fast.js/object/values.js +20 -0
- data/deps/node_modules/deku/node_modules/fast.js/package.json +73 -0
- data/deps/node_modules/deku/node_modules/fast.js/reduce.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/reduceRight.js +24 -0
- data/deps/node_modules/deku/node_modules/fast.js/string/index.js +3 -0
- data/deps/node_modules/deku/node_modules/fast.js/string/intern.js +56 -0
- data/deps/node_modules/deku/node_modules/get-uid/README.md +44 -0
- data/deps/node_modules/deku/node_modules/get-uid/index.js +6 -0
- data/deps/node_modules/deku/node_modules/get-uid/package.json +56 -0
- data/deps/node_modules/deku/node_modules/is-dom/HISTORY.md +2 -0
- data/deps/node_modules/deku/node_modules/is-dom/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/is-dom/README.md +32 -0
- data/deps/node_modules/deku/node_modules/is-dom/index.js +15 -0
- data/deps/node_modules/deku/node_modules/is-dom/package.json +62 -0
- data/deps/node_modules/deku/node_modules/object-path/.npmignore +7 -0
- data/deps/node_modules/deku/node_modules/object-path/.travis.yml +6 -0
- data/deps/node_modules/deku/node_modules/object-path/LICENSE +21 -0
- data/deps/node_modules/deku/node_modules/object-path/README.md +96 -0
- data/deps/node_modules/deku/node_modules/object-path/bower.json +17 -0
- data/deps/node_modules/deku/node_modules/object-path/component.json +22 -0
- data/deps/node_modules/deku/node_modules/object-path/index.js +269 -0
- data/deps/node_modules/deku/node_modules/object-path/package.json +89 -0
- data/deps/node_modules/deku/node_modules/object-path/test.js +510 -0
- data/deps/node_modules/deku/node_modules/per-frame/.npmignore +68 -0
- data/deps/node_modules/deku/node_modules/per-frame/History.md +32 -0
- data/deps/node_modules/deku/node_modules/per-frame/README.md +44 -0
- data/deps/node_modules/deku/node_modules/per-frame/component.json +13 -0
- data/deps/node_modules/deku/node_modules/per-frame/index.js +37 -0
- data/deps/node_modules/deku/node_modules/per-frame/package.json +143 -0
- data/deps/node_modules/deku/node_modules/per-frame/test/test.js +94 -0
- data/deps/node_modules/deku/node_modules/sliced/.npmignore +2 -0
- data/deps/node_modules/deku/node_modules/sliced/.travis.yml +4 -0
- data/deps/node_modules/deku/node_modules/sliced/History.md +30 -0
- data/deps/node_modules/deku/node_modules/sliced/LICENSE +22 -0
- data/deps/node_modules/deku/node_modules/sliced/Makefile +5 -0
- data/deps/node_modules/deku/node_modules/sliced/README.md +62 -0
- data/deps/node_modules/deku/node_modules/sliced/bench.js +95 -0
- data/deps/node_modules/deku/node_modules/sliced/component.json +14 -0
- data/deps/node_modules/deku/node_modules/sliced/index.js +1 -0
- data/deps/node_modules/deku/node_modules/sliced/lib/sliced.js +33 -0
- data/deps/node_modules/deku/node_modules/sliced/package.json +52 -0
- data/deps/node_modules/deku/node_modules/sliced/test/index.js +80 -0
- data/deps/node_modules/deku/package.json +67 -0
- data/lib/deku.rb +11 -0
- data/lib/deku/application.rb +16 -0
- data/lib/deku/component.rb +36 -0
- data/lib/deku/context.rb +38 -0
- data/lib/deku/element_node.rb +17 -0
- data/lib/deku/version.rb +4 -0
- metadata +278 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Array Flatten
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![NPM downloads][downloads-image]][downloads-url]
|
|
5
|
+
[![Build status][travis-image]][travis-url]
|
|
6
|
+
[![Test coverage][coveralls-image]][coveralls-url]
|
|
7
|
+
|
|
8
|
+
> Flatten an array of nested arrays into a single flat array. Accepts an optional depth.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
npm install array-flatten --save
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
var flatten = require('array-flatten')
|
|
20
|
+
|
|
21
|
+
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
|
|
22
|
+
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
23
|
+
|
|
24
|
+
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
|
|
25
|
+
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
|
|
26
|
+
|
|
27
|
+
(function () {
|
|
28
|
+
flatten(arguments) //=> [1, 2, 3]
|
|
29
|
+
})(1, [2, 3])
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
|
35
|
+
|
|
36
|
+
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
|
|
37
|
+
[npm-url]: https://npmjs.org/package/array-flatten
|
|
38
|
+
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
|
|
39
|
+
[downloads-url]: https://npmjs.org/package/array-flatten
|
|
40
|
+
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
|
|
41
|
+
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
|
|
42
|
+
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
|
|
43
|
+
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive flatten function with depth.
|
|
3
|
+
*
|
|
4
|
+
* @param {Array} array
|
|
5
|
+
* @param {Array} result
|
|
6
|
+
* @param {Number} depth
|
|
7
|
+
* @return {Array}
|
|
8
|
+
*/
|
|
9
|
+
function flattenDepth (array, result, depth) {
|
|
10
|
+
for (var i = 0; i < array.length; i++) {
|
|
11
|
+
var value = array[i]
|
|
12
|
+
|
|
13
|
+
if (depth > 0 && Array.isArray(value)) {
|
|
14
|
+
flattenDepth(value, result, depth - 1)
|
|
15
|
+
} else {
|
|
16
|
+
result.push(value)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Recursive flatten function. Omitting depth is slightly faster.
|
|
25
|
+
*
|
|
26
|
+
* @param {Array} array
|
|
27
|
+
* @param {Array} result
|
|
28
|
+
* @return {Array}
|
|
29
|
+
*/
|
|
30
|
+
function flattenForever (array, result) {
|
|
31
|
+
for (var i = 0; i < array.length; i++) {
|
|
32
|
+
var value = array[i]
|
|
33
|
+
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
flattenForever(value, result)
|
|
36
|
+
} else {
|
|
37
|
+
result.push(value)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Flatten an array, with the ability to define a depth.
|
|
46
|
+
*
|
|
47
|
+
* @param {Array} array
|
|
48
|
+
* @param {Number} depth
|
|
49
|
+
* @return {Array}
|
|
50
|
+
*/
|
|
51
|
+
module.exports = function (array, depth) {
|
|
52
|
+
if (depth == null) {
|
|
53
|
+
return flattenForever(array, [])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return flattenDepth(array, [], depth)
|
|
57
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "array-flatten",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Flatten an array of nested arrays into a single flat array",
|
|
5
|
+
"main": "array-flatten.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"array-flatten.js",
|
|
8
|
+
"LICENSE"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "istanbul cover _mocha -- -R spec"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/blakeembrey/array-flatten.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"array",
|
|
19
|
+
"flatten",
|
|
20
|
+
"arguments",
|
|
21
|
+
"depth"
|
|
22
|
+
],
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Blake Embrey",
|
|
25
|
+
"email": "hello@blakeembrey.com",
|
|
26
|
+
"url": "http://blakeembrey.me"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/blakeembrey/array-flatten/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/blakeembrey/array-flatten",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"istanbul": "^0.3.13",
|
|
35
|
+
"mocha": "^2.2.4",
|
|
36
|
+
"pre-commit": "^1.0.7",
|
|
37
|
+
"standard": "^3.7.3"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "73c57136fb4210569e585555988cc8c39c3468df",
|
|
40
|
+
"_id": "array-flatten@1.1.0",
|
|
41
|
+
"_shasum": "ac3efac717b0e7bbdc778ce0bde7381ac6604393",
|
|
42
|
+
"_from": "array-flatten@>=1.0.2 <2.0.0",
|
|
43
|
+
"_npmVersion": "2.8.3",
|
|
44
|
+
"_nodeVersion": "1.8.1",
|
|
45
|
+
"_npmUser": {
|
|
46
|
+
"name": "blakeembrey",
|
|
47
|
+
"email": "hello@blakeembrey.com"
|
|
48
|
+
},
|
|
49
|
+
"maintainers": [
|
|
50
|
+
{
|
|
51
|
+
"name": "blakeembrey",
|
|
52
|
+
"email": "hello@blakeembrey.com"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"dist": {
|
|
56
|
+
"shasum": "ac3efac717b0e7bbdc778ce0bde7381ac6604393",
|
|
57
|
+
"tarball": "http://registry.npmjs.org/array-flatten/-/array-flatten-1.1.0.tgz"
|
|
58
|
+
},
|
|
59
|
+
"directories": {},
|
|
60
|
+
"_resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.0.tgz",
|
|
61
|
+
"readme": "ERROR: No README data found!"
|
|
62
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
1.2.0 / 2014-02-12
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* prefix events with `$` to support object prototype method names
|
|
6
|
+
|
|
7
|
+
1.1.3 / 2014-06-20
|
|
8
|
+
==================
|
|
9
|
+
|
|
10
|
+
* republish for npm
|
|
11
|
+
* add LICENSE file
|
|
12
|
+
|
|
13
|
+
1.1.2 / 2014-02-10
|
|
14
|
+
==================
|
|
15
|
+
|
|
16
|
+
* package: rename to "component-emitter"
|
|
17
|
+
* package: update "main" and "component" fields
|
|
18
|
+
* Add license to Readme (same format as the other components)
|
|
19
|
+
* created .npmignore
|
|
20
|
+
* travis stuff
|
|
21
|
+
|
|
22
|
+
1.1.1 / 2013-12-01
|
|
23
|
+
==================
|
|
24
|
+
|
|
25
|
+
* fix .once adding .on to the listener
|
|
26
|
+
* docs: Emitter#off()
|
|
27
|
+
* component: add `.repo` prop
|
|
28
|
+
|
|
29
|
+
1.1.0 / 2013-10-20
|
|
30
|
+
==================
|
|
31
|
+
|
|
32
|
+
* add `.addEventListener()` and `.removeEventListener()` aliases
|
|
33
|
+
|
|
34
|
+
1.0.1 / 2013-06-27
|
|
35
|
+
==================
|
|
36
|
+
|
|
37
|
+
* add support for legacy ie
|
|
38
|
+
|
|
39
|
+
1.0.0 / 2013-02-26
|
|
40
|
+
==================
|
|
41
|
+
|
|
42
|
+
* add `.off()` support for removing all listeners
|
|
43
|
+
|
|
44
|
+
0.0.6 / 2012-10-08
|
|
45
|
+
==================
|
|
46
|
+
|
|
47
|
+
* add `this._callbacks` initialization to prevent funky gotcha
|
|
48
|
+
|
|
49
|
+
0.0.5 / 2012-09-07
|
|
50
|
+
==================
|
|
51
|
+
|
|
52
|
+
* fix `Emitter.call(this)` usage
|
|
53
|
+
|
|
54
|
+
0.0.3 / 2012-07-11
|
|
55
|
+
==================
|
|
56
|
+
|
|
57
|
+
* add `.listeners()`
|
|
58
|
+
* rename `.has()` to `.hasListeners()`
|
|
59
|
+
|
|
60
|
+
0.0.2 / 2012-06-28
|
|
61
|
+
==================
|
|
62
|
+
|
|
63
|
+
* fix `.off()` with `.once()`-registered callbacks
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Component contributors <dev@component.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Emitter [](https://travis-ci.org/component/emitter)
|
|
2
|
+
|
|
3
|
+
Event emitter component.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
$ component install component/emitter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### Emitter(obj)
|
|
14
|
+
|
|
15
|
+
The `Emitter` may also be used as a mixin. For example
|
|
16
|
+
a "plain" object may become an emitter, or you may
|
|
17
|
+
extend an existing prototype.
|
|
18
|
+
|
|
19
|
+
As an `Emitter` instance:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
var Emitter = require('emitter');
|
|
23
|
+
var emitter = new Emitter;
|
|
24
|
+
emitter.emit('something');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
As a mixin:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
var Emitter = require('emitter');
|
|
31
|
+
var user = { name: 'tobi' };
|
|
32
|
+
Emitter(user);
|
|
33
|
+
|
|
34
|
+
user.emit('im a user');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
As a prototype mixin:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
var Emitter = require('emitter');
|
|
41
|
+
Emitter(User.prototype);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Emitter#on(event, fn)
|
|
45
|
+
|
|
46
|
+
Register an `event` handler `fn`.
|
|
47
|
+
|
|
48
|
+
### Emitter#once(event, fn)
|
|
49
|
+
|
|
50
|
+
Register a single-shot `event` handler `fn`,
|
|
51
|
+
removed immediately after it is invoked the
|
|
52
|
+
first time.
|
|
53
|
+
|
|
54
|
+
### Emitter#off(event, fn)
|
|
55
|
+
|
|
56
|
+
* Pass `event` and `fn` to remove a listener.
|
|
57
|
+
* Pass `event` to remove all listeners on that event.
|
|
58
|
+
* Pass nothing to remove all listeners on all events.
|
|
59
|
+
|
|
60
|
+
### Emitter#emit(event, ...)
|
|
61
|
+
|
|
62
|
+
Emit an `event` with variable option args.
|
|
63
|
+
|
|
64
|
+
### Emitter#listeners(event)
|
|
65
|
+
|
|
66
|
+
Return an array of callbacks, or an empty array.
|
|
67
|
+
|
|
68
|
+
### Emitter#hasListeners(event)
|
|
69
|
+
|
|
70
|
+
Check if this emitter has `event` handlers.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Expose `Emitter`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = Emitter;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Initialize a new `Emitter`.
|
|
10
|
+
*
|
|
11
|
+
* @api public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function Emitter(obj) {
|
|
15
|
+
if (obj) return mixin(obj);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mixin the emitter properties.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} obj
|
|
22
|
+
* @return {Object}
|
|
23
|
+
* @api private
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
function mixin(obj) {
|
|
27
|
+
for (var key in Emitter.prototype) {
|
|
28
|
+
obj[key] = Emitter.prototype[key];
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Listen on the given `event` with `fn`.
|
|
35
|
+
*
|
|
36
|
+
* @param {String} event
|
|
37
|
+
* @param {Function} fn
|
|
38
|
+
* @return {Emitter}
|
|
39
|
+
* @api public
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
Emitter.prototype.on =
|
|
43
|
+
Emitter.prototype.addEventListener = function(event, fn){
|
|
44
|
+
this._callbacks = this._callbacks || {};
|
|
45
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
|
46
|
+
.push(fn);
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Adds an `event` listener that will be invoked a single
|
|
52
|
+
* time then automatically removed.
|
|
53
|
+
*
|
|
54
|
+
* @param {String} event
|
|
55
|
+
* @param {Function} fn
|
|
56
|
+
* @return {Emitter}
|
|
57
|
+
* @api public
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
Emitter.prototype.once = function(event, fn){
|
|
61
|
+
function on() {
|
|
62
|
+
this.off(event, on);
|
|
63
|
+
fn.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
on.fn = fn;
|
|
67
|
+
this.on(event, on);
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Remove the given callback for `event` or all
|
|
73
|
+
* registered callbacks.
|
|
74
|
+
*
|
|
75
|
+
* @param {String} event
|
|
76
|
+
* @param {Function} fn
|
|
77
|
+
* @return {Emitter}
|
|
78
|
+
* @api public
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
Emitter.prototype.off =
|
|
82
|
+
Emitter.prototype.removeListener =
|
|
83
|
+
Emitter.prototype.removeAllListeners =
|
|
84
|
+
Emitter.prototype.removeEventListener = function(event, fn){
|
|
85
|
+
this._callbacks = this._callbacks || {};
|
|
86
|
+
|
|
87
|
+
// all
|
|
88
|
+
if (0 == arguments.length) {
|
|
89
|
+
this._callbacks = {};
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// specific event
|
|
94
|
+
var callbacks = this._callbacks['$' + event];
|
|
95
|
+
if (!callbacks) return this;
|
|
96
|
+
|
|
97
|
+
// remove all handlers
|
|
98
|
+
if (1 == arguments.length) {
|
|
99
|
+
delete this._callbacks['$' + event];
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// remove specific handler
|
|
104
|
+
var cb;
|
|
105
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
106
|
+
cb = callbacks[i];
|
|
107
|
+
if (cb === fn || cb.fn === fn) {
|
|
108
|
+
callbacks.splice(i, 1);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Emit `event` with the given args.
|
|
117
|
+
*
|
|
118
|
+
* @param {String} event
|
|
119
|
+
* @param {Mixed} ...
|
|
120
|
+
* @return {Emitter}
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
Emitter.prototype.emit = function(event){
|
|
124
|
+
this._callbacks = this._callbacks || {};
|
|
125
|
+
var args = [].slice.call(arguments, 1)
|
|
126
|
+
, callbacks = this._callbacks['$' + event];
|
|
127
|
+
|
|
128
|
+
if (callbacks) {
|
|
129
|
+
callbacks = callbacks.slice(0);
|
|
130
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
131
|
+
callbacks[i].apply(this, args);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return this;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Return array of callbacks for `event`.
|
|
140
|
+
*
|
|
141
|
+
* @param {String} event
|
|
142
|
+
* @return {Array}
|
|
143
|
+
* @api public
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
Emitter.prototype.listeners = function(event){
|
|
147
|
+
this._callbacks = this._callbacks || {};
|
|
148
|
+
return this._callbacks['$' + event] || [];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check if this emitter has `event` handlers.
|
|
153
|
+
*
|
|
154
|
+
* @param {String} event
|
|
155
|
+
* @return {Boolean}
|
|
156
|
+
* @api public
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
Emitter.prototype.hasListeners = function(event){
|
|
160
|
+
return !! this.listeners(event).length;
|
|
161
|
+
};
|