@21epub/rxjs-event-bus 中文文档教程

发布于 3年前 浏览 22 项目主页 更新于 3年前

@21epub/rxjs-event-bus

使用 create-storybook-react-library

NPMJavaScript 风格指南构建状态Codecov

Intro

这是一个事件管理模块。

Feature

  • [x] Easy-to-use
  • [x] Typescript Support
  • [x] Rxjs
  • [ ] Hooks support

Install

npm install --save @21epub/rxjs-event-bus

Usage

import RxBus from '@21epub/rxjs-event-bus'

// create instance
const rxBus = new RxBus()

// register events
rxBus.register<string>('event1')

// or register batch of events
rxBus.register<string>(['event1', 'event2'])

// subscribe to a event just like using rxjs subject
rxBus.subject('event1').subscribe((result) => console.log(result))

// tigger event
rxBus.subject('event1').next('ok')

// support Sync Event
rxBus.register('syncEvent', 'SyncSubject')
rxBus.syncSubject('syncEvent').subscribe((result) => console.log(result)) // something
rxBus.syncSubject('syncEvent').next('something')

Developing and running on localhost

首先安装依赖项,然后为 storybook dev 安装 peerDeps:

npm install

在热模块重新加载模式下运行示例:

npm start   # or npm run storybook

创建捆绑库模块构建:

npm run build

Testing

运行单元测试:

npm test

License

MIT © 21epub

@21epub/rxjs-event-bus

Made with create-storybook-react-library

NPMJavaScript Style GuideBuild StatusCodecov

Intro

This is a module for event management.

Feature

  • [x] Easy-to-use
  • [x] Typescript Support
  • [x] Rxjs
  • [ ] Hooks support

Install

npm install --save @21epub/rxjs-event-bus

Usage

import RxBus from '@21epub/rxjs-event-bus'

// create instance
const rxBus = new RxBus()

// register events
rxBus.register<string>('event1')

// or register batch of events
rxBus.register<string>(['event1', 'event2'])

// subscribe to a event just like using rxjs subject
rxBus.subject('event1').subscribe((result) => console.log(result))

// tigger event
rxBus.subject('event1').next('ok')

// support Sync Event
rxBus.register('syncEvent', 'SyncSubject')
rxBus.syncSubject('syncEvent').subscribe((result) => console.log(result)) // something
rxBus.syncSubject('syncEvent').next('something')

Developing and running on localhost

First install dependencies and then install peerDeps for storybook dev:

npm install

To run Example in hot module reloading mode:

npm start   # or npm run storybook

To create a bundle library module build:

npm run build

Testing

To run unit tests:

npm test

License

MIT © 21epub

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文