custom-event-ts
A polyfill for CustomEvents on IE8+ written in Typescript
- written in Typescript
- fully tested
- auto polyfill
CustomEvent
when using - offer
GlobalEvent
for easy use
一旦引用该组件,就会自动对 CustomEvent
进行 polyfill,同时提供组件 GlobalEvent
对象(默认导出)方便在全局进行自定义事件的订阅
参考文档
实现
教程
Installation
Node.js / Browserify
npm install custom-event-ts --save
import GlobalEvent from "custom-event-ts";
var GlobalEvent = require('custom-event-ts');
GlobalEvent.on('SAY_HELLO', (data) => {
console.log(data.detail)
})
GlobalEvent.dispatch('SAY_HELLO', { name: 'John' })
GlobalEvent.off('SAY_HELLO')
Global object
在页面中可以直接使用打包好的文件:
<script src="./dist/index.umd.min.js"></script>
通过 window.GlobaEvent
获取功能对象。
Build & test
npm run build
npm test
npm run doc
then open the generated out/index.html
file in your browser.
License
MIT.