Comparing version 0.5.2 to 0.5.3
@@ -5,3 +5,3 @@ { | ||
"description": "Custom Events", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"keywords": ["events"], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
23
eve.js
@@ -15,3 +15,3 @@ // Copyright (c) 2017 Adobe Systems Incorporated. All rights reserved. | ||
// ┌────────────────────────────────────────────────────────────┐ \\ | ||
// │ Eve 0.5.2 - JavaScript Events Library │ \\ | ||
// │ Eve 0.5.3 - JavaScript Events Library │ \\ | ||
// ├────────────────────────────────────────────────────────────┤ \\ | ||
@@ -22,3 +22,3 @@ // │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ | ||
(function (glob) { | ||
var version = "0.5.2", | ||
var version = "0.5.3", | ||
has = "hasOwnProperty", | ||
@@ -61,4 +61,2 @@ separator = /[\.\/]/, | ||
> Arguments | ||
- name (string) name of the *event*, dot (`.`) or slash (`/`) separated | ||
@@ -140,4 +138,2 @@ - scope (object) context for the event handlers | ||
> Arguments | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated | ||
@@ -226,3 +222,3 @@ | ||
} | ||
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator); | ||
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator); | ||
for (var i = 0, ii = names.length; i < ii; i++) { | ||
@@ -262,3 +258,2 @@ (function (name) { | ||
| }); | ||
> Arguments | ||
- event (string) event name | ||
@@ -289,4 +284,2 @@ - varargs (…) and any other arguments | ||
** | ||
> Arguments | ||
** | ||
- subname (string) #optional subname of the event | ||
@@ -324,4 +317,2 @@ ** | ||
** | ||
> Arguments | ||
** | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
@@ -341,3 +332,3 @@ - f (function) event handler function | ||
} | ||
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator); | ||
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator); | ||
if (names.length > 1) { | ||
@@ -433,4 +424,2 @@ for (var i = 0, ii = names.length; i < ii; i++) { | ||
** | ||
> Arguments | ||
** | ||
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
@@ -459,3 +448,3 @@ - f (function) event handler function | ||
glob.eve = eve; | ||
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); | ||
})(window || this); | ||
typeof module != "undefined" && module.exports ? module.exports = eve : typeof define === "function" && define.amd ? define("eve", [], function() { return eve; }) : glob.eve = eve; | ||
})(typeof window != "undefined" ? window : this); |
@@ -10,10 +10,56 @@ { | ||
"description" : "Simple custom events", | ||
"version" : "0.5.2", | ||
"license": "Apache-2.0", | ||
"version" : "0.5.3", | ||
"main" : "./eve.js", | ||
"devDependencies": { | ||
"mocha": "*", | ||
"expect.js": "*", | ||
"eslint": "*", | ||
"dr.js": "~0.1.0" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/eslint/bin/eslint.js eve.js", | ||
"build": "node node_modules/dr.js/dr dr.json" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:adobe-webplatform/eve.git" | ||
}, | ||
"eslintConfig": { | ||
"globals": { | ||
"window": true, | ||
"console": true | ||
}, | ||
"rules": { | ||
"block-scoped-var": 0, | ||
"comma-dangle": 0, | ||
"no-extra-parens": 1, | ||
"no-shadow": 0, | ||
"consistent-return": 0, | ||
"eqeqeq": 0, | ||
"no-new-wrappers": 0, | ||
"no-sequences": 1, | ||
"radix": 2, | ||
"new-parens": 0, | ||
"no-underscore-dangle": 0, | ||
"no-path-concat": 0, | ||
"strict": 0, | ||
"camelcase": 0, | ||
"no-extend-native": 0, | ||
"no-loop-func": 0, | ||
"new-cap": 0, | ||
"no-unused-expressions": 0, | ||
"no-mixed-requires": 0, | ||
"quotes": [ | ||
1, | ||
"double", | ||
"avoid-escape" | ||
] | ||
} | ||
} | ||
} |
143
README.md
@@ -5,2 +5,143 @@ # Eve | ||
For use case look at e.html | ||
## eve(name, scope, varargs) | ||
Fires event with given `name`, given scope and other parameters. | ||
### Parameters | ||
- _name_ **string** | ||
name of the _event_, dot (`.`) or slash (`/`) separated | ||
- _scope_ **object** | ||
context for the event handlers | ||
- _varargs_ **...** | ||
the rest of arguments will be sent to event handlers | ||
**Returns:** **object** array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value. | ||
## eve.listeners(name) | ||
Internal method which gives you array of all event handlers that will be triggered by the given `name`. | ||
### Parameters | ||
- _name_ **string** | ||
name of the event, dot (`.`) or slash (`/`) separated | ||
**Returns:** **array** array of event handlers | ||
## eve.separator(separator) | ||
If for some reasons you don’t like default separators (`.` or `/`) you can specify yours | ||
here. Be aware that if you pass a string longer than one character it will be treated as | ||
a list of characters. | ||
### Parameters | ||
- _separator_ **string** | ||
new separator. Empty string resets to default: `.` or `/`. | ||
## eve.on(name, f, name, f) | ||
Binds given event handler with a given name. You can use wildcards “`*`” for the names: | ||
```js | ||
eve.on("*.under.*", f); | ||
eve("mouse.under.floor"); // triggers f | ||
``` | ||
Use <a href="#eve" class="dr-link">eve</a> to trigger the listener. | ||
### Parameters | ||
- _name_ **string** | ||
name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
- _f_ **function** | ||
event handler function | ||
- _name_ **array** | ||
if you don’t want to use separators, you can use array of strings | ||
- _f_ **function** | ||
event handler function | ||
**Returns:** **function** returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment. | ||
### Example: | ||
```js | ||
eve.on("mouse", eatIt)(2); | ||
eve.on("mouse", scream); | ||
eve.on("mouse", catchIt)(1); | ||
``` | ||
This will ensure that `catchIt` function will be called before `eatIt`. | ||
If you want to put your handler before non-indexed handlers, specify a negative value. | ||
Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”. | ||
## eve.f(event, varargs) | ||
Returns function that will fire given event with optional arguments. | ||
Arguments that will be passed to the result function will be also | ||
concated to the list of final arguments. | ||
```js | ||
el.onclick = eve.f("click", 1, 2); | ||
eve.on("click", function (a, b, c) { | ||
console.log(a, b, c); // 1, 2, [event object] | ||
}); | ||
``` | ||
### Parameters | ||
- _event_ **string** | ||
event name | ||
- _varargs_ **…** | ||
and any other arguments | ||
**Returns:** **function** possible event handler function | ||
## eve.stop() | ||
Is used inside an event handler to stop the event, preventing any subsequent listeners from firing. | ||
## eve.nt([subname]) | ||
Could be used inside event handler to figure out actual name of the event. | ||
### Parameters | ||
- _subname_ **string** | ||
subname of the event | ||
**Returns:** **string** name of the event, if `subname` is not specified | ||
or | ||
**Returns:** **boolean** `true`, if current event’s name contains `subname` | ||
## eve.nts() | ||
Could be used inside event handler to figure out actual name of the event. | ||
**Returns:** **array** names of the event | ||
## eve.off(name, f) | ||
Removes given function from the list of event listeners assigned to given name. | ||
If no arguments specified all the events will be cleared. | ||
### Parameters | ||
- _name_ **string** | ||
name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
- _f_ **function** | ||
event handler function | ||
## eve.unbind() | ||
See <a href="#eve.off" class="dr-link">eve.off</a> | ||
## eve.once(name, f) | ||
Binds given event handler with a given name to only run once then unbind itself. | ||
```js | ||
eve.once("login", f); | ||
eve("login"); // triggers f | ||
eve("login"); // no listeners | ||
``` | ||
Use <a href="#eve" class="dr-link">eve</a> to trigger the listener. | ||
### Parameters | ||
- _name_ **string** | ||
name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards | ||
- _f_ **function** | ||
event handler function | ||
**Returns:** **function** same return function as <a href="#eve.on" class="dr-link">eve.on</a> | ||
## eve.version() | ||
Current version of the library. | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36036
9
453
147
4