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 🙏

© 2025 – Pkg Stats / Ryan Hefner

signal-slot-js

v1.0.2

Published

Signal-Slot à la Qt

Downloads

117

Readme

Signal-Slot library "à la" Qt

Signal/Slot pattern implemented in TypeScript.

  • No dependency, small (only 4ko in mignified mode) and efficient library.

  • We try to follow the Qt syntax for the connection, i.e., connect(sender, signal, receiver, slot).

  • Slot can be any method from a class, a setter, an arrow function or any function with any number of arguments.

  • Allows to connect/disconnect and lock/unlock connections

Installation

npm i signal-slot-js

or from the sources

git checkout [email protected]:xaliphostes/signal-slot-js.git
npm install
npm run build

Testing

Require node version > 11

npm run test

Running examples

All examples are in the examples directory. Run them using ts-node

Usage

The following example shows how to implement the combineLatest from RxJS.

It will create the following:

  task1 ---\
            ---> CombineLatest --> task3
  rask2 ---/

task3 is launched only when task1 AND task2 are done.

import {create, emit, connect} from 'signal-slot'

// ----------------------------------------------

class Task {
    constructor(public name: string, public ms: number) {
        // Create a signal for this class
        create(this, 'finished')
    }
    
    run() {
        console.log(`Task ${this.name} is running for ${this.ms}ms...`)
        // Emit a signal
        setTimeout( () => emit(this, 'finished'), this.ms)
    }
}

// ----------------------------------------------

// Will be executed when task1 AND task2 are done
class CombineLatest {
    private doneTask1 = false
    private doneTask2 = false

    constructor(private task1: Task, private task2: Task) {
        // Create a signal for this class
        create(this, 'done')
        // Perform two connections
        connect({sender: task1, signal: 'finished', receiver: () => this.doneTask(1)})
        connect({sender: task2, signal: 'finished', receiver: () => this.doneTask(2)})
    }

    private doneTask(n: number) {
        console.log('done doing task', n)
        switch(n) {
            case 1: this.doneTask1 = true; break
            case 2: this.doneTask2 = true; break
        }
        if (this.doneTask1 && this.doneTask2) {
            console.log('doing task combine')
            this.doneTask1 = false
            this.doneTask2 = false
            // Emit a signal
            emit(this, 'done')
        }
    }
}

// ----------------------------------------------

const task1   = new Task('task 1', 500)
const task2   = new Task('task 2', 3000)
const combine = new CombineLatest(task1, task2)

// Perform a connection
connect({
    sender: combine, 
    signal: 'done', 
    receiver: () => console.log('All done!')
})

// Run the 2 tasks in parallel and trigger combine
// when both are done
task1.run()
task2.run()

License

MIT License