signals.hx

A simple signals library for Haxe.
https://github.com/Paopun20/signals.hx

To install, run:

haxelib install signals.hx 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

signals.hx - A simple lightweight signal implementation

Type-safe lightweight signal/event library for Haxe using compile-time macros.

Usage

import paopao.signals.Signal;
// Define a signal with a function type
var onClick:Signal<(x:Int, y:Int) -> Void> = new Signal();
// Add listener
onClick.add((x, y) -> trace('Clicked at $x, $y'));
// Dispatch event
onClick.dispatch(10, 20);
// Remove listener
onClick.remove(listener);
// Check if listener exists
onClick.has(listener);
// Remove all listeners
onClick.removeAll();

API

MethodDescription
add(listener)Add a listener function
remove(listener)Remove a listener function
removeAll()Remove all listeners
dispatch(...args)Call all listeners with args
has(listener)Check if listener is registered

Features

  • Type-safe: Signal type is enforced at compile-time
  • Zero runtime overhead: Types generated at compile-time
  • Safe dispatch: Copies listener array before iteration
  • JavaScript compatible: Exposed as Signal

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Contributors
paopaodev
Version
1.0.0
Published
7 months ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂