Git Product home page Git Product logo

tob-mitt's Introduction

tob-mitt

vue3 中,mitt 是一个推荐的 eventBus 库。这是一个 uni_modules 的完美迁移版本。



原仓库 📦

👉 mitt



Usage 🦖

import mitt from "@/uni_modules/tob-mitt/index.js"

const bus = mitt()

// 注册两个指定类型的事件函数
bus.on('foo', () => console.log('我是foo1'))
bus.on('foo', () => console.log('我是foo2'))

// 触发该类型的事件函数
bus.emit('foo') // 将打印 我是foo1,我是foo2

// 注册一个带形参的事件函数
bus.on('bar', (msg) => console.log(msg))

// 触发事件函数的同时设置实参
bus.emit('bar', '你好') // 将打印 你好

bus.off('bar') // 卸载所有 bar 事件函数

const bar = () => console.log('我好')
bus.on('bar', bar)
bus.off('bar', bar) // 单独卸载该事件函数

bus.emit('bar') // 因为被卸载了,所以什么都不会触发

// 注册所有类型的事件函数
bus.on('*', () => {
    console.log("不论什么时候都会触发")
})

// 触发 * 类型的事件函数
bus.emit() // 打印 不论什么时候都会触发

bus.emit('foo') // 打印 我是foo1,我是foo2 不论什么时候都会触发

bus.all // 保存事件函数的 map


组织 🦔

欢迎关注 帝莎编程



License

Made with markthree

Published under MIT License.

tob-mitt's People

Contributors

markthree avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.