当前位置:网站首页>tiny-emitter.js:一个小型的事件订阅发布库
tiny-emitter.js:一个小型的事件订阅发布库
2022-07-25 04:05:00 【彭世瑜】
A tiny (less than 1k) event emitter library
文档
安装
npm install tiny-emitter --save
使用示例
import Emitter from 'tiny-emitter'
const emitter = new Emitter()
function handler(data) {
console.log(data);
}
const TOPIC = 'topic'
// 订阅
emitter.on(TOPIC, handler)
// 仅订阅一次
emitter.once(TOPIC, handler)
// 发布事件1
emitter.emit(TOPIC, {
a: '1' })
// 取消订阅
emitter.off(TOPIC, handler)
// 发布事件2
emitter.emit(TOPIC, {
a: '2' })
边栏推荐
- Apipost signs up with Chinatelecom! Work together to accelerate the digital transformation of enterprises
- DNS domain name resolution
- Jenkins continues to integrate entry to mastery
- Understand Huawei's 2018 financial report with one picture
- Maker concept design to adapt to popular education
- The latest Matlab download and installation tutorial (with files)
- Student thinking vs workplace thinking
- Method of setting document comments in idea (graphic version)
- Server status code
- Network engineering case: integrated network design of CII company
猜你喜欢

Swagger simple quick start tutorial

Traditional architecture of enterprise digital transformation to medium platform micro service architecture

Preparation for Android development in big companies

Construction of data center (I): background of the emergence of data center

暗黑王者|ZEGO 低照度图像增强技术解析

运筹学基础【一】 之 导论

ECCV 2022 | rethinking image blending for data enhancement in vision transformers

Unity3d learning note 9 - loading textures

How to test cookies

2019 telecast retest test questions
随机推荐
LVGL 8.2 Tabview & Window
When the development of the meta universe begins to show more and more the style of the Internet, we need to be vigilant
Wechat applet experiment case: simple idiom dictionary
Introduction to computing system hardware (common servers)
Tiktok live broadcast brings goods to help the industry go to sea, and Fastdata observation industry boutique salon helps the ecological development
PCBA scheme design -- Bluetooth intelligent nutrition scale scheme
What tools are available to connect and manage polardb for PostgreSQL databases?
Sudden! Britain accuses Huawei of major defects in its equipment (with report)
DNS domain name resolution service
Behind Senma's LP, "Wenzhou Department" is running into the venture capital circle
Hbuilderx eslint configuration
Permanently solve Matplotlib Chinese garbled code
Math. Random, switch selection structure
Geely and Daimler set up a joint venture to produce pure electric smart in China!
DNS domain name resolution
Chapter 3 business function development (modify the remarks of market activities)
Serial adder / subtracter
Debezium series: when there are a large number of DML operations in the record source database, the debezium consumption data time lags behind the data generation time by several hours
The application could not be installed: INSTALL_ FAILED_ USER_ RESTRICTED
Visual studio 2019 installation and uninstallation problems