Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

events-ex

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-ex - npm Package Compare versions

Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.1

2

ability.js

@@ -1,1 +0,1 @@

module.exports = require('./eventable')
module.exports = require('./lib/eventable')

@@ -5,2 +5,13 @@ # Changelog

## [2.0.0-alpha.1](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.0...v2.0.0-alpha.1) (2023-06-13)
### ⚠ BREAKING CHANGES
* remove deprecated files
### Refactor
* remove deprecated files ([d733a5c](https://github.com/snowyu/events-ex.js/commit/d733a5c6a6c554739ecbcb653996f1e546579fa4))
## [2.0.0-alpha.0](https://github.com/snowyu/events-ex.js/compare/v1.1.7...v2.0.0-alpha.0) (2023-05-25)

@@ -7,0 +18,0 @@

@@ -44,3 +44,3 @@ [events-ex](../README.md) / [Exports](../modules.md) / [event](../modules/event.md) / Event

[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L8)
[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L8)

@@ -57,3 +57,3 @@ ## Properties

[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L38)
[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L38)

@@ -70,3 +70,3 @@ ___

[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L32)
[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L32)

@@ -83,3 +83,3 @@ ___

[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L26)
[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L26)

@@ -102,3 +102,3 @@ ## Methods

[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L45)
[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L45)

@@ -125,2 +125,2 @@ ___

[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event.js#L20)
[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event.js#L20)

@@ -25,2 +25,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / [index](../modules/index-1.md) / EventEmitter

[src/index.js:17](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.js#L17)
[src/index.js:17](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.js#L17)

@@ -46,3 +46,3 @@ [events-ex](../README.md) / [Exports](../modules.md) / [index](../modules/index.md) / EventEmitter

[src/index.d.ts:16](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L16)
[src/index.d.ts:16](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L16)

@@ -72,3 +72,3 @@ ## Methods

[src/index.d.ts:47](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L47)
[src/index.d.ts:47](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L47)

@@ -98,3 +98,3 @@ ___

[src/index.d.ts:53](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L53)
[src/index.d.ts:53](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L53)

@@ -123,3 +123,3 @@ ___

[src/index.d.ts:75](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L75)
[src/index.d.ts:75](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L75)

@@ -148,3 +148,3 @@ ___

[src/index.d.ts:68](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L68)
[src/index.d.ts:68](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L68)

@@ -178,3 +178,3 @@ ___

[src/index.d.ts:41](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L41)
[src/index.d.ts:41](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L41)

@@ -208,3 +208,3 @@ ___

[src/index.d.ts:25](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L25)
[src/index.d.ts:25](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L25)

@@ -238,3 +238,3 @@ ___

[src/index.d.ts:33](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L33)
[src/index.d.ts:33](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L33)

@@ -263,3 +263,3 @@ ___

[src/index.d.ts:60](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L60)
[src/index.d.ts:60](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L60)

@@ -284,3 +284,3 @@ ___

[src/index.d.ts:61](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L61)
[src/index.d.ts:61](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L61)

@@ -306,2 +306,2 @@ ___

[src/index.d.ts:76](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/index.d.ts#L76)
[src/index.d.ts:76](https://github.com/snowyu/events-ex.js/blob/892d26d/src/index.d.ts#L76)

@@ -44,2 +44,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / all-off

[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/all-off.js#L12)
[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/892d26d/src/all-off.js#L12)

@@ -27,2 +27,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / consts

[src/consts.js:5](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/consts.js#L5)
[src/consts.js:5](https://github.com/snowyu/events-ex.js/blob/892d26d/src/consts.js#L5)

@@ -51,2 +51,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / default-methods

[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/default-methods.js#L8)
[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/default-methods.js#L8)

@@ -33,3 +33,3 @@ [events-ex](../README.md) / [Exports](../modules.md) / event-emitter

[src/event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event-emitter.js#L6)
[src/event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event-emitter.js#L6)

@@ -58,2 +58,2 @@ ## Functions

[src/event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/event-emitter.js#L33)
[src/event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/892d26d/src/event-emitter.js#L33)

@@ -29,2 +29,4 @@ [events-ex](../README.md) / [Exports](../modules.md) / eventable

Note: Maybe the ability will be injected into the inheritance class.
#### Parameters

@@ -46,2 +48,2 @@

node_modules/custom-ability/lib/custom-ability.d.ts:30
node_modules/custom-ability/lib/custom-ability.d.ts:103

@@ -40,2 +40,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / has-listeners

[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/has-listeners.js#L10)
[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/892d26d/src/has-listeners.js#L10)

@@ -49,2 +49,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / pipe-async

[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/pipe-async.js#L21)
[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/892d26d/src/pipe-async.js#L21)

@@ -49,2 +49,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / pipe

[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/pipe.js#L21)
[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/892d26d/src/pipe.js#L21)

@@ -46,2 +46,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / unify

[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/unify.js#L17)
[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/892d26d/src/unify.js#L17)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/array-remove

[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/array-remove.js#L5)
[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/array-remove.js#L5)

@@ -41,2 +41,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/object-for-each

[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/object-for-each.js#L6)
[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/object-for-each.js#L6)

@@ -40,2 +40,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/string-pad

[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/string-pad.js#L8)
[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/string-pad.js#L8)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/to-int

[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/to-int.js#L2)
[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/to-int.js#L2)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/valid-callable

[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/valid-callable.js#L1)
[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/valid-callable.js#L1)

@@ -39,2 +39,2 @@ [events-ex](../README.md) / [Exports](../modules.md) / util/valid-object

[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/b4aaa97/src/util/valid-object.js#L3)
[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/892d26d/src/util/valid-object.js#L3)

@@ -5,3 +5,3 @@ events-ex / [Exports](modules.md)

Browser-friendly enhanced events most compatible with standard node.js and coffee-script. It's modified from [event-emitter](https://github.com/medikoo/event-emitter) mainly. It can add event-able to your class directly.
Browser-friendly enhanced event emitter [ability][Ability] and class. It's modified from [event-emitter][event-emitter] mainly. It can add/inject the event-able [ability][Ability] to your any class.

@@ -11,5 +11,5 @@ ### Features

* Rewrite of the core architecture for improved performance and more powerful event-able ability
* keep most compatible with [node events](nodejs.org/api/events.html) and [event-emitter](https://github.com/medikoo/event-emitter)
* keep most compatible with [node events](nodejs.org/api/events.html) and [event-emitter][event-emitter]
* Hookable event system for more control over event handling
* Supports async event emitting
* Supports async event emitting via `emitAsync` method.

@@ -19,11 +19,13 @@ ### Differences

* Difference with [node events](https://nodejs.org/api/events.html)
+ **`broken change`**: The event object supports bubbling
+ the event object as listener's "this" object.
+ return the result property of event object to the emitter.
+ prevent the rest of listener from be executed if the stopped property of the event object is set to true
+ **`broken change`**: The event supports bubbling and interruption
+ the `event object` as listener's "this" object:
* `result`: If set, the result is returned to the `Event Emitter`.
* `stopped`: If set to `true`, it prevents the remaining listeners from being executed.
* `target`: The `Event Emitter` object, which was originally the `this` object.
* **`broken change`**: The `emit` return the result of listeners's callback function instead of the successful state.
* **`broken change`**: The `this` object of listeners' callback function is the `Event` Object instead of the emitter object.
* The emitter object is put into the `target` property of the `Event` Object.
* Adds async event emitting via `emitAsync` method.
* Difference with [event-emitter](https://github.com/medikoo/event-emitter)
+ **`broken change`**: The event object supports bubbling(see above)
+ **`broken change`**: The event supports bubbling and interruption(see above)
+ Adds the defaultMaxListeners class property to keep compatibility with node events.

@@ -34,2 +36,3 @@ + Adds the setMaxListeners method to keep compatible with node events.

+ Adds listenerCount() class method to keep compatibility with node events.
* Adds async event emitting via `emitAsync` method.

@@ -44,3 +47,3 @@ ### Installation

Extends from `EventEmitter`:
Extends from `EventEmitter` class:

@@ -53,3 +56,3 @@ ```js

Add the event-able feature to your class directly:
Add/Inject the event-able [ability][Ability] to your class directly:

@@ -59,3 +62,3 @@ ```js

class MyClass {}
class MyClass extends MyRoot {}

@@ -66,6 +69,6 @@ // inject the eventable ability to MyClass

Now uses it:
Now, you can use events in your class:
```js
var my = new MyClass;
const my = new MyClass;

@@ -241,1 +244,4 @@ my.on('event', function() {

```
[event-emitter]: https://github.com/medikoo/event-emitter
[Ability]: https://github.com/snowyu/custom-ability.js
{
"name": "events-ex",
"version": "2.0.0-alpha.0",
"version": "2.0.0-alpha.1",
"description": "Browser-friendly enhanced events most compatible with standard node.js, it's powerful eventable ability.",

@@ -41,3 +41,3 @@ "contributors": [

"dependencies": {
"custom-ability": "^2.0.0-alpha.3",
"custom-ability": "^2.0.0-alpha.4",
"util-ex": "^2.0.0-alpha.8"

@@ -44,0 +44,0 @@ },

### events-ex [![Build Status](https://img.shields.io/travis/snowyu/events-ex.js/master.png)](http://travis-ci.org/snowyu/events-ex.js) [![npm](https://img.shields.io/npm/v/events-ex.svg)](https://npmjs.org/package/events-ex) [![downloads](https://img.shields.io/npm/dm/events-ex.svg)](https://npmjs.org/package/events-ex) [![license](https://img.shields.io/npm/l/events-ex.svg)](https://npmjs.org/package/events-ex)
Browser-friendly enhanced events most compatible with standard node.js and coffee-script. It's modified from [event-emitter](https://github.com/medikoo/event-emitter) mainly. It can add event-able to your class directly.
浏览器友好的增强的**事件**[能力][Ability]和类。 它主要是从 [event-emitter][event-emitter] 修改而来的。 本库可以为你的任何类添加(注入)**事件**[能力][Ability]。
TODO: 支持异步事件,添加`emitAsync`方法. 没这么简单,因为要支持bubbling,所以必须顺序执行事件.
干脆,将`bubbling`作为功能选项.如果没有启用,就可以乱发了.
TODO: 异步事件,添加`emitAsync`方法. 没这么简单,因为要支持bubbling,所以必须顺序执行事件.
将`bubbling`作为功能选项.如果没有启用,就可以乱发了.
当关闭`bubbling`的时候,那么是否还需要用`event`对象传递.
首先完成异步支持.
首先完成异步支持.已经完成.`emitAsync`方法已经加上.
### Features
* rewrite the core architecture
* keep most compatible with [node events](nodejs.org/api/events.html) and [event-emitter](https://github.com/medikoo/event-emitter)
+ more powerful event-able ability
* hookable event system
* 重写核心架构
* 尽最大可能性与[node events][Node Events] and [event-emitter][event-emitter]保持兼容
* 更强大的 event-able [能力][Ability]
* 可挂载的事件系统, 用于更好地控制事件处理
* 支持异步事件通过 `emitAsync` 方法.
### Differences
### 区别
* Difference with [node events](https://nodejs.org/api/events.html)
+ **`broken change`**: The event object bubbling Supports
+ the event object as listener's "this" object.
+ return the result property of event object to emitter.
+ prevent the rest of listener from be excuted if set the stopped property of event object to true
* **`broken change`**: the `emit` return the result of listeners's callback function instead of the successful state.
* **`broken change`**: the `this` object of listeners' callback function is the `Event` Object instead of the emitter object.
* the emitter object is put into the `target` property of the `Event` Object.
* Difference with [event-emitter](https://github.com/medikoo/event-emitter)
+ **`broken change`**: The event object bubbling Supports(see above)
+ add the defaultMaxListeners class property to keep compatible with node events.
+ add the setMaxListeners method to keep compatible with node events.
+ add `error`, `newListener` and `removeListener` events to keep compatible with node events.
+ add listeners() method to keep compatible with node events.
+ add listenerCount() class method to keep compatible with node events.
* 与 [Node 事件模块](https://nodejs.org/api/events.html) 的区别
* **`改变`**: 事件支持冒泡机制与中断
* 事件对象(`Event Object`)作为监听器的 "this" 对象。
* `result` 属性: 可选, 如果设置,则将该结果返回到事件发射器(`Event Emitter`)。
* `stopped` 属性: 可选, 如果设置为 `true`,则会阻止剩余的监听器被执行。
* `target`属性: 事件发射器对象,原本的`this`
* **`改变`**: `emit` 方法返回监听器回调函数的结果而不是成功状态。
* **`改变`**: 监听器回调函数的 `this` 对象是 `Event Object` 事件对象而不是事件发射器对象。
* 事件发射器对象被放入 `Event` 对象的 `target` 属性中。
* 添加了`emitAsync`方法,支持异步事件
* 与 [event-emitter](https://github.com/medikoo/event-emitter) 的区别
* **`改变`**: 事件支持冒泡机制(如上所述)
* 添加了默认最大监听器数量的类属性,以保持与 Node 事件模块的兼容性。
* 添加了 `setMaxListeners` 方法,以保持与 Node 事件模块的兼容性。
* 添加了 `error`、`newListener` 和 `removeListener` 事件,以保持与 Node 事件模块的兼容性。
* 添加了 `listeners()` 方法,以保持与 Node 事件模块的兼容性。
* 添加了 `listenerCount()` 类方法,以保持与 Node 事件模块的兼容性。
* 添加了`emitAsync`方法,支持异步事件
### Installation
### 安装
$ npm install events-ex
```
npm install events-ex@alpha
```
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
### Usage
### 用法
直接继承使用 `EventEmitter` 类
Add the event-able feature to your class directly:
```js
import {EventEmitter} from 'events-ex';
```coffee
class MyClass extends EventEmitter {}
```
eventable = require('events-ex/eventable')
直接添加/注入事件(event-able)[能力][Ability] 到你的类:
class MyClass
# advanced usage see API topic.
eventable MyClass
```js
import {eventable} from 'events-ex';
my = new MyClass
class MyClass extends MyRoot {}
my.on 'event', ->
console.log 'event occur'
# be care: @(this) is the event object. not the `my` instance.
# the my instance is @target.
my.emit 'event'
// inject the eventable ability to MyClass
eventable(MyClass);
```
the following is javascript:
现在,可以在你的类中使用事件了:
```js
var eventable = require('events-ex/eventable');
const my = new MyClass;
function MyClass() {}
eventable(MyClass);
var my = new MyClass;
my.on('event', function() {

@@ -87,41 +84,7 @@ console.log('event occur');

Node JS events Usage:
事件冒泡机制的使用:
```coffee
## Coffee-script demo bubbling usage:
EventEmitter = require('events-ex')
inherits = require('inherits-ex')
ABORT = -1
DONE = 0
class MyDb
inherits MyDb, EventEmitter
get: (key)->
# Demo the event object bubbling usage:
result = @emit 'getting', key
if isObject result
return if result.state is ABORT
return result.result if result.state is DONE
_get(key)
db = new MyDb
db.on 'getting', (key)->
result = myGet(key);
if result?
# get the key succ
this.result =
state: DONE
result: result
else if result is null
# abort default get key.
this.result = state: ABORT;
# this.stopped = true # it will skip other listeners if true
```
```js
// js demo bubbling usage:
let EventEmitter = require('events-ex')
let isObject = require('util-ex/lib/is/type/object')
const ABORT = -1
const DONE = 0
import {EventEmitter, states} from 'events-ex';
import {isObject} from 'util-ex';

@@ -133,4 +96,4 @@ class MyDb extends EventEmitter {

if(isObject(result)) {
if (result.state === ABORT) return
if (result.state === DONE) return result.result
if (result.state === states.ABORT) return
if (result.state === states.DONE) return result.result
}

@@ -147,3 +110,3 @@ return _get(key)

this.result = {
state: DONE,
state: states.DONE,
result: result,

@@ -153,3 +116,3 @@ }

// abort default get key.
this.result = {state: ABORT};
this.result = {state: states.ABORT};
// this.stopped = true // it will skip other listeners if true

@@ -164,8 +127,9 @@ }

var ee = require('event-ex/event-emitter');
import {wrapEventEmitter as ee} from 'events-ex';
var MyClass = function () { /* .. */ };
class MyClass { /* .. */ };
ee(MyClass.prototype); // All instances of MyClass will expose event-emitter interface
var emitter = new MyClass(), listener;
const emitter = new MyClass();
let listener;

@@ -194,8 +158,8 @@ emitter.on('test', listener = function (args) {

* `class`: the class to be injected the ability.
* `options` *(object)*: optional options
* `include` *(string[]|string)*: only these emitter methods will be added to the class
* `options` _(object)_: optional options
* `include` _(string[]|string)_: only these emitter methods will be added to the class
* **NOTE:** static method should use the prefix '@' with name.
* `exclude` *(string[]|string)*: theses emitter methods would not be added to the class
* `exclude` _(string[]|string)_: theses emitter methods would not be added to the class
* **NOTE:** static method should use the prefix '@' with name.
* `methods` *(object)*: hooked methods to the class
* `methods` _(object)_: hooked methods to the class
* key: the method name to hook.

@@ -205,3 +169,3 @@ * value: the new method function

* `this.self` is the original `this` object.
* `classMethods` *(object)*: hooked class methods to the class
* `classMethods` _(object)_: hooked class methods to the class

@@ -224,2 +188,3 @@ ```coffee

```
#### allOff(obj) _(events-ex/all-off)_

@@ -288,2 +253,5 @@

[events]: https://github.com/nodejs/node/blob/main/lib/events.js
[event-emitter]: https://github.com/medikoo/event-emitter
[Node Events]: https://nodejs.org/api/events.html
[Ability]: https://github.com/snowyu/custom-ability.js
### events-ex [![Build Status](https://img.shields.io/travis/snowyu/events-ex.js/master.png)](http://travis-ci.org/snowyu/events-ex.js) [![npm](https://img.shields.io/npm/v/events-ex.svg)](https://npmjs.org/package/events-ex) [![downloads](https://img.shields.io/npm/dm/events-ex.svg)](https://npmjs.org/package/events-ex) [![license](https://img.shields.io/npm/l/events-ex.svg)](https://npmjs.org/package/events-ex)
Browser-friendly enhanced events most compatible with standard node.js and coffee-script. It's modified from [event-emitter](https://github.com/medikoo/event-emitter) mainly. It can add event-able to your class directly.
Browser-friendly enhanced event emitter [ability][Ability] and class. It's modified from [event-emitter][event-emitter] mainly. It can add/inject the event-able [ability][Ability] to your any class.

@@ -9,5 +9,5 @@ ### Features

* Rewrite of the core architecture for improved performance and more powerful event-able ability
* keep most compatible with [node events](nodejs.org/api/events.html) and [event-emitter](https://github.com/medikoo/event-emitter)
* keep most compatible with [node events](nodejs.org/api/events.html) and [event-emitter][event-emitter]
* Hookable event system for more control over event handling
* Supports async event emitting
* Supports async event emitting via `emitAsync` method.

@@ -17,11 +17,13 @@ ### Differences

* Difference with [node events](https://nodejs.org/api/events.html)
+ **`broken change`**: The event object supports bubbling
+ the event object as listener's "this" object.
+ return the result property of event object to the emitter.
+ prevent the rest of listener from be executed if the stopped property of the event object is set to true
+ **`broken change`**: The event supports bubbling and interruption
+ the `event object` as listener's "this" object:
* `result`: If set, the result is returned to the `Event Emitter`.
* `stopped`: If set to `true`, it prevents the remaining listeners from being executed.
* `target`: The `Event Emitter` object, which was originally the `this` object.
* **`broken change`**: The `emit` return the result of listeners's callback function instead of the successful state.
* **`broken change`**: The `this` object of listeners' callback function is the `Event` Object instead of the emitter object.
* The emitter object is put into the `target` property of the `Event` Object.
* Adds async event emitting via `emitAsync` method.
* Difference with [event-emitter](https://github.com/medikoo/event-emitter)
+ **`broken change`**: The event object supports bubbling(see above)
+ **`broken change`**: The event supports bubbling and interruption(see above)
+ Adds the defaultMaxListeners class property to keep compatibility with node events.

@@ -32,2 +34,3 @@ + Adds the setMaxListeners method to keep compatible with node events.

+ Adds listenerCount() class method to keep compatibility with node events.
* Adds async event emitting via `emitAsync` method.

@@ -43,3 +46,3 @@

Extends from `EventEmitter`:
Extends from `EventEmitter` class:

@@ -52,3 +55,3 @@ ```js

Add the event-able feature to your class directly:
Add/Inject the event-able [ability][Ability] to your class directly:

@@ -58,3 +61,3 @@ ```js

class MyClass {}
class MyClass extends MyRoot {}

@@ -65,6 +68,6 @@ // inject the eventable ability to MyClass

Now uses it:
Now, you can use events in your class:
```js
var my = new MyClass;
const my = new MyClass;

@@ -242,1 +245,3 @@ my.on('event', function() {

[event-emitter]: https://github.com/medikoo/event-emitter
[Ability]: https://github.com/snowyu/custom-ability.js
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc