Socket
Book a DemoInstallSign in
Socket

ebus-light

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ebus-light

轻量级的 Event Bus

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
41
-28.07%
Maintainers
1
Weekly downloads
 
Created
Source

事件总线

轻量级的 Event Bus。

1. 如何使用

安装:

pnpm add ebus-light

使用方式有以下几种。

  • 直接引入

bus 是全局唯一的实例。

import { bus } from 'ebus-light';

bus.emit('foo', { name: 'yang' });


function onFoo(e) {
  console.log(e.name);
}

bus.on('foo', onFoo)
bus.off('foo', onFoo)
  • Vue 插件

也可当作 Vue 插件,先在 main.ts 中注册:

import { eventBus } from 'ebus-light';

app.use(eventBus);

在页面中使用:

// options API
export default {
  mounted() {
    this.$eventBus.emit('foo')
  }
}

通过 inject 访问:

import `inject` from 'vue';

export default {
  setup() {
    const bus = inject('$eventBus');
    bus.emit('foo');
  }
}

2. 类型

通过插件方式使用时传递的参数:

export interface Options {
  // 是否挂载在全局
  global?: boolean;
  // 是否 provide
  inject?: boolean;
  // 实例上挂载的名称
  globalPropertyName?: string;
  // 通过 inject 引入的名称
  injectName?: string;
}

参数默认值:

const DEFAULT_OPTIONS = {
  global: false,
  inject: false,
  globalPropertyName: '$eventBus',
  injectName: '$eventBus',
};

3. 更新日志

点此查看

Keywords

plugin-light

FAQs

Package last updated on 09 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.