custom-event-ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

custom-event-ts

Build Status Coverage Status MIT Licence npm version

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";

// or
var GlobalEvent = require('custom-event-ts');

// Listen event 'SAY_HELLO'
GlobalEvent.on('SAY_HELLO', (data) => {
    console.log(data.detail) // { name: 'John' }
})

// Dispatch event 'SAY_HELLO' with data
GlobalEvent.dispatch('SAY_HELLO', { name: 'John' })

// Remove event listener
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.

Readme

Keywords

none

Package Sidebar

Install

npm i custom-event-ts

Weekly Downloads

2

Version

0.1.1

License

none

Unpacked Size

25.3 kB

Total Files

11

Last publish

Collaborators

  • jscon