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

hxsignal

v0.0.2

Published

Simple Haxe Signal API implementation

Downloads

4

Readme

HxSignal: Simple Haxe Signal

My motivation was to create a simple API for callback functions, I thought that Haxe must have a signals and slots toolkit generic, type safe, flexible and efficient. There are already fantastic signal toolkits for Haxe, but I wanted to give to signal this touch or tweak I think were missing. I like the implementation of msignal, so my first try was to give it my touch but soon I realized it will be different taking C++ Boost and Qt signals as base.

Basic usage

// initialisation
var voidSignal  = new Signal<Void -> Void>();
var eventSignal = new Signal<AnyObject -> String -> Void>();
var signal1     = new Signal<Int -> Void>();

// connecting, adding or binding slot
voidSignal.connect(function() {});

// connecting once (disconnected the first time it is called)
eventSignal.connect(function(origin, type) {}, Once);

// disconnecting slot
function slot1(num : Int) : Void { }

signal1.disconnect(slot1);

// emitting
voidSignal.emit();
eventSignal.emit(this, "clicked");
signal1.emit(123);

Advanced usage

// connecting n times (disconnected the nth time it is called)
eventSignal.connect(function(origin, type) {}, Times(n));

// Add slots to groups
signal1.connect(slot1, 1); // slot1 added to group 1
signal1.connect(slot1bis, 2); // slot added to group 2

// disconnect all slots in group 1
signal1.disconnectGroup(1);

// priority
signal1.connect(slot1, 1, AtBack);
signal1.connect(slot1bis, 1, AtFront); // slot1bis is called first then slot1

Responding a signal

// slot that adds 1 to emitted value
function add1(value : Int) : Int {
	return value + 1;
}

// slot that add 2 to emitted value
function add2(value : Int) : Int {
	return value + 2;
}

var signalWithResponse = new Signal<Int->Int>();
signalWithResponse.connect(add1);
signalWithResponse.connect(add2);

var result = signalWithResponse.emit(3); // result == 5

Why is result 5? Because signal always return the last result as default behavior, in this case add2(3) has returned 3 + 2 = 5

Handling the signal responses

Let's add a results processor...

// responses == [add1(x), add2(x)] where x is the emitted integer
signalWithResponse.resultsProcessor = function (responses:Array<Int>) {
	var result = 0;
	for (i in responses)
		result += i;
	return result;
}
  
var processedResult = signalWithResponse.emit(3); // result == 9

This time emit function returns the processed value and it is 9 because resultsProcessor has added the responses of call add1(3) and add2(3) (4 and 5 respectively).

Also

  • disconnectAll() // disconects all the slots
  • block(slot, true) // block slot (not called) until block(slot, false) is called
  • isBlock(slot)
  • numSlots // amount of slot connected
  • and more features are coming