# EventEmitter

> EventEmitter jssdk

参考 NodeJs EventEmitter 的轻量化实现


## 安装

```bash
npm i @sdp.nd/event -s
```

## 使用

### 初始化

```js
import EventEmitter from '@sdp.nd/event'
const event = new EventEmitter()
```

### 监听事件
```js
import EventEmitter from '@sdp.nd/event'
const event = new EventEmitter()
// 监听名字为 ename 的事件，并且触发回调 cb
const cb = () => console.log('callback now')
event.on('ename', cb)
```

### 派发事件
```js
import EventEmitter from '@sdp.nd/event'
const event = new EventEmitter()
// 派发名字为 ename 的事件，并且将将 'arg1', 'arg2' 作为回调函数的参数
event.emmit('ename', 'arg1', 'arg2')
```

### 移除事件
```js
import EventEmitter from '@sdp.nd/event'
const event = new EventEmitter()
const cb = () => console.log('callback now')
event.on('ename', cb)
// 移除对事件名称为 ename， 回调为 cb 的监听
event.off('ename', cb)
// 移除所有对事件名称为 ename 的监听
event.off('ename')
```


## 更多

### js 迁移到 ts
官网：https://github.com/Microsoft/TypeScript-React-Conversion-Guide#typescript-react-conversion-guide
个人经验：https://www.fullstackmemo.com/2018/03/27/jsx2tsx/


### ts 学习
快速入门：https://blog.csdn.net/csdn_ds/article/details/73380716?locationNum=4&fps=1
W3Cschlool：https://www.w3cschool.cn/typescript/typescript-df-publishing.html


### .d.ts
自动生成工具：http://npm.taobao.org/package/dtsmake
发布到 @types：https://blog.csdn.net/yushulx/article/details/71450923


### 使用 EsLint
配置介绍：https://juejin.im/entry/5a156adaf265da43231aa032
现成的配置：https://github.com/AlloyTeam/eslint-config-alloy#typescript-react


### 使用 TsLint
官网：https://palantir.github.io/tslint/usage/cli/
常用配置说明：https://blog.csdn.net/lqy455949477/article/details/77769235/
常用配置说明：https://www.cnblogs.com/wyy5552/p/8796695.html
常用配置说明：https://blog.csdn.net/zw52yany/article/details/78688837
让TsLint兼容Eslint：https://www.npmjs.com/package/tslint-eslint-rules
