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

f-event

v1.0.4

Published

a simple but powerful bus

Downloads

8

Readme

F-event

为什么要做这个呢,是因为在兼职写一个没有很好工程结构的项目的时候,需要用到这样一个模型,于是就诞生了这么一个项目,功能简单,目标明确~

have fun~

安装

browser

clone本项目,引入f-bus.es5.browser.js

npm

npm install f-event

API

目前共有两种创建事件的方法

第一种(单例) 推荐用于解决全局事件,单例模式,全局引用相同

const { Fbus } = require('F-event');
let bus_1 = Fbus;

第二种(多个) 可以用于创建多个eventBus

const { F_bus } = require('F-event');
let bus_3 = new F_bus();

订阅事件 监听事件,如果启动命名空间,默认为default

bus.on('${eventName}', () => {
  //callback
})

单次订阅事件 当事件发生时,销毁该监听

bus.once('${eventName}', () => {
  //callback
})

获取选定事件的所有回调函数

bus.getListener('${eventName}')

触发事件 在arguments里写入要发送的消息或者为要给监听事件传入的参数

bus.emit('${eventName}', arguments)

删除事件 如果不加type,默认全部删除

bus.remove('${eventName}', function, type)  //  function指代要删除的function type指定所要删除的事件类型once代表一次监听normal代表普通

历史事件 返回历史触发事件,带时间

bus.history();

历史事件返回值

{
    type:once/normal,   //  once代表单次监听,normal正常
    function:fun,   //  fun所调用的函数
    time:time   //  触发时间
}

命名空间 用于解决单命名空间变量冲突冗余问题

bus.enablens(); //启动命名空间功能,必须! 此时原事件命名空间为'default'
bus.ns('${namespaceName}'); //此处返回了bus本身,并且已经切换命名空间,若不存在当前命名空间,则创建

命名空间eg:

bus.enablens();
bus.ns('ns1').on('ns1Test', () => {});
bus.emit('ns1Test');

待完成API

  • 在想