npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

message-center.js

v3.0.0

Published

MessageCenter

Downloads

4

Readme

MessageCenter 一个简易的消息中心

Install and test

# install
npm install message-center.js

Example


const messageCenter = new MessageCenter()

messageCenter.on("aaa|bbb|ccc", (a,b,c) => {
  //...
})

messageCenter.emit('aaa', 0, 1, 2)

messageCenter.un('aaa')

API

on(eventName, handler, context?, weight?)

为指定事件注册一个监听器,接受一个字符串 eventName 和一个 回调函数。


messageCenter.on('aaa|bbb|ccc', () => {
  //do something
});

// 等价于
     messageCenter.on('aaa', () => {
       //do something
     });
     
     messageCenter.on('bbb', () => {
       //do something
     });
     
     messageCenter.on('ccc', () => {
       //do something
     });

once(eventName, handler, context?, weight?)

为指定事件注册一个单次监听器,监听器最多只会触发一次,触发后立刻解除该监听器。

emit(eventName, ...args)

按参数的顺序执行每个监听器

un(eventName, handler?)

解除监听器 如没有传入handler,将会解除eventName名下所有监听器

clear()

重置 messageCenter

listenersLength(eventName)

计算监听器的数量

watch(eventName, handler, ...args)

与invoke方法一起使用, 能够返回watch方法的handler可以收到invoke方法的计算结果 同时invoke也能够收到watch方法的返回结果

invoke(eventName, ...args)

    const messageCenter = new MessageCenter()
    
    messageCenter.watch("aaa", (a,b,c) => {
      // a === 0
      // b === 1
      // c === 2
      return { a: 2, b: 3, c: 4}
    })
    
    messageCenter.invoke('aaa', 0, 1, 2).then(data => {
      // data === { a: 2, b: 3, c: 4}
    })