Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chimeejs/chimee-helper-events
base events binder for chimee
https://github.com/chimeejs/chimee-helper-events
Last synced: 9 days ago
JSON representation
base events binder for chimee
- Host: GitHub
- URL: https://github.com/chimeejs/chimee-helper-events
- Owner: Chimeejs
- License: mit
- Created: 2017-07-06T08:38:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-31T17:22:30.000Z (over 5 years ago)
- Last Synced: 2024-04-28T01:45:51.880Z (7 months ago)
- Language: JavaScript
- Size: 88.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chimee-helper-events
[![Build Status](https://img.shields.io/travis/Chimeejs/chimee-helper-events/master.svg?style=flat-square)](https://travis-ci.org/Chimeejs/chimee-helper-events.svg?branch=master)
[![Coverage Status](https://img.shields.io/coveralls/Chimeejs/chimee-helper-events/master.svg?style=flat-square)](https://coveralls.io/github/Chimeejs/chimee-helper-events?branch=master)
[![npm](https://img.shields.io/npm/v/chimee-helper-events.svg?colorB=brightgreen&style=flat-square)](https://www.npmjs.com/package/chimee-helper-events)
[![dependency Status](https://david-dm.org/Chimeejs/chimee-helper-events.svg)](https://david-dm.org/Chimeejs/chimee-helper-events)
[![devDependency Status](https://david-dm.org/Chimeejs/chimee-helper-events/dev-status.svg)](https://david-dm.org/Chimeejs/chimee-helper-events?type=dev) [![Greenkeeper badge](https://badges.greenkeeper.io/Chimeejs/chimee-helper-events.svg)](https://greenkeeper.io/)events handler of chimee
## get started
```shell
npm install chimee-helper-events --save
```## doc
### event
[src/index.js:16-16](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L16-L16 "Source code on GitHub")
自定义事件基础类
**Meta**
- **author**: huzunjie
### getEvtTypeCache
[src/index.js:25-48](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L25-L48 "Source code on GitHub")
得到某对象的某事件类型对应的监听队列数组
**Parameters**
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 发生事件的对象
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型(这里的时间类型不只是名称,还是缓存标识,可以通过添加后缀来区分)Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)**
### emitEventCache
[src/index.js:57-67](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L57-L67 "Source code on GitHub")
触发事件监听方法
**Parameters**
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 发生事件的对象
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `eventObj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 触发事件时要传回的event对象Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
### addEventCache
[src/index.js:78-94](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L78-L94 "Source code on GitHub")
添加事件监听到缓存
**Parameters**
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 发生事件的对象
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** 监听函数
- `isOnce` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 是否单次执行 (optional, default `false`)
- `handlerWrap` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
### removeEventCache
[src/index.js:103-126](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L103-L126 "Source code on GitHub")
移除事件监听
**Parameters**
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 发生事件的对象
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** 监听函数
- `isOnce` (optional, default `false`)Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
### CustEvent
[src/index.js:139-208](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L139-L208 "Source code on GitHub")
Event 自定义事件类
1\. 可以使用不传参得到的实例作为eventBus使用
2\. 可以通过指定target,用多个实例操作同一target对象的事件管理
3\. 当设定target时,可以通过设置assign为true,来给target实现"on\\once\\off\\emit"方法**Parameters**
- `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 发生事件的对象(空则默认为event实例)
- `assign` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 是否将"on\\once\\off\\emit"方法实现到target对象上Returns **[event](#event)**
#### on
[src/index.js:172-175](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L172-L175 "Source code on GitHub")
添加事件监听
**Parameters**
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** 监听函数
- `isOnce` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 单次监听类型 (optional, default `false`)Returns **[event](#event)**
#### once
[src/index.js:183-185](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L183-L185 "Source code on GitHub")
添加事件监听,并且只执行一次
**Parameters**
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** 监听函数Returns **[event](#event)**
#### off
[src/index.js:194-197](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L194-L197 "Source code on GitHub")
移除事件监听
**Parameters**
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** 监听函数(不指定handler则清除type对应的所有事件监听)
- `isOnce` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 单次监听类型 (optional, default `false`)Returns **[event](#event)**
#### emit
[src/index.js:204-207](https://github.com/Chimeejs/chimee-helper-events/blob/43f39c489f1d638cb6ba1e7e634889f42b2ef810/src/index.js#L204-L207 "Source code on GitHub")
触发事件监听函数
**Parameters**
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 事件类型
- `data`Returns **[event](#event)**