https://github.com/afeiship/we-mitt
Global(window) event emitter.
https://github.com/afeiship/we-mitt
emit emitter event global window
Last synced: 26 days ago
JSON representation
Global(window) event emitter.
- Host: GitHub
- URL: https://github.com/afeiship/we-mitt
- Owner: afeiship
- License: mit
- Created: 2018-07-24T13:36:02.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-06T15:26:34.000Z (11 months ago)
- Last Synced: 2025-02-07T17:17:27.380Z (3 months ago)
- Topics: emit, emitter, event, global, window
- Language: TypeScript
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# we-mitt
> Global(window) event emitter.[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]## installation
```shell
npm install @jswork/we-mitt
```## usage
```js
import WeEmitt from '@jswork/we-mitt';const wemiter = new WeEmitt();
// on
const res = wemiter.on('abc', (data)=>{
console.log('attach abc event', data);
});// do something...
wemiter.emit('abc', { id: 1, name: 'xx' });// detatch
res.destory();
```## apis
| name | params | description |
| ---- | ------------ | ------------------------------------ |
| on | name,handler | register an event |
| off | name,handler | unregister an event |
| emit | name,obj | fire an event |
| one | name,obj | fire an event,only can register once |## license
Code released under [the MIT license](https://github.com/afeiship/we-mitt/blob/master/LICENSE.txt).[version-image]: https://img.shields.io/npm/v/@jswork/we-mitt
[version-url]: https://npmjs.org/package/@jswork/we-mitt[license-image]: https://img.shields.io/npm/l/@jswork/we-mitt
[license-url]: https://github.com/afeiship/we-mitt/blob/master/LICENSE.txt[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/we-mitt
[size-url]: https://github.com/afeiship/we-mitt/blob/master/dist/we-mitt.min.js[download-image]: https://img.shields.io/npm/dm/@jswork/we-mitt
[download-url]: https://www.npmjs.com/package/@jswork/we-mitt