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

@itharbors/event

v1.0.0

Published

[![NPM](https://img.shields.io/npm/v/@itharbors/event)](https://www.npmjs.com/package/@itharbors/event) [![CI Status](https://github.com/itharbors/event/actions/workflows/ci.yaml/badge.svg)](https://github.com/itharbors/event/actions/workflows/ci.yaml)

Downloads

54

Readme

Event

NPM CI Status

目标与范围

简单的事件发送功能,支持 TS 定义,在使用前定义好事件的类型以及监听函数的参数和返回值类型

需求分析

功能需求

  • 基础的事件功能
  • 支持定义事件名称和监听函数类型

非功能需求

  • 暂无

整体结构

图例

基本结构

classDiagram
    class EventEmitter {
        + addListener(action: string, handle: Function) void
        + addOnceListener(action: string, handle: Function) void
        + removeListener(action: string, handle: Function) void
        + clear(action?: string) void
        + emit(...args: any[]) HandleResult[]
    }

    class HandleResult {
        + result: any
        + error: any
    }

代码范例

基础用法

import { EventEmitter } from '@itharbors/event';

const emitter = new EventEmitter<{
    test: {
        params: [number, number];
        result: number;
    };
}>();

emitter.addListener('test', (a, b) => {
    console.log(a, b);
    return a + b;
});

emitter.emit('test-a', 1, 2);

关键决策

  • emit 只处理同步逻辑
    • 有可能需要处理异步,但是也有可能触发异步函数后,不需要处理,所以这里留给调用者处理

异常处理设计

  • 某个处理函数执行失败
    • 描述
      • 执行 handle 队列的时候,某个函数报错
    • 处理
      • 记录当前报错的 error
      • 继续后续函数执行

性能优化

  • 暂无

附件与参考文档

  • 暂无