sub-mitt

0.1.1 • Public • Published

sub-mitt 是一个可跨技术栈通讯的js包

安装

pnpm add sub-mitt

npm install sub-mitt

yarn add sub-mitt

使用

es

import SubMitt from 'sub-mitt';
const subMitt = new SubMitt();
const client = subMitt.createClient();
//订阅消息
client.sub("TP_1", (res) => {
    console.log(res, 'res');
})
//发送消息
subMitt.pub("TP_1", 'send...', {
    persistent: true,
    type: 0
});

cjs

const SubMitt require('sub-mitt');
const subMitt = new SubMitt();
const client = subMitt.createClient();
//订阅消息
client.sub("TP_1", (res) => {
    console.log(res, 'res');
})
//发送消息
subMitt.pub("TP_1", 'send...', {
    persistent: true,
    type: 0
});

浏览器引入

<script src="https://unpkg.com/sub-mitt"></script>
const subMitt = new window.SubMitt();
const client = subMitt.createClient();
//订阅消息
client.sub("TP_1", (res) => {
    console.log(res, 'res');
})
//发送消息
subMitt.pub("TP_1", 'send...', {
    persistent: true,
    type: 0
});

Readme

Keywords

Package Sidebar

Install

npm i sub-mitt

Weekly Downloads

2

Version

0.1.1

License

ISC

Unpacked Size

245 kB

Total Files

12

Last publish

Collaborators

  • linxx5599