Coder Social home page Coder Social logo

signals's Introduction

Overview

A simple and light weight event system replacement.

Performance

performance

API

The API is based off massiveinteractive's msignal and Robert Penner’s AS3 Signals, however is greatly simplified.

Basic Signal

The following example demonstrates how to create a signal, add a listener and dispatch it.

import signals.Signal;

var signal = new Signal();
signal.add(() -> { /* do something */ });
signal.dispatch();

Single Property Signal

var signal = new Signal1<Int>();
signal.add((value:Int) -> { /* do something */ });
signal.dispatch(5);

Double Property Signal

var signal = new Signal2<Int, String>();
signal.add((value1:Int, value2:String) -> { /* do something */ });
signal.dispatch(5, "example");

Add Once

var signal = new Signal();
signal.add(() -> { trace('fire'); }).repeat(0);
signal.dispatch();
signal.dispatch();

// output 
'fire'

Priority

var signal = new Signal();
signal.add(() -> { trace('Priority 100'); }).priority(100);
signal.add(() -> { trace('Priority 500'); }).priority(500);
signal.dispatch();

// output 
'Priority 500'
'Priority 100'

Add Once with Priority

var signal = new Signal();
signal.add(() -> { trace('Priority 100'); }).repeat(0).priority(100);
signal.add(() -> { trace('Priority 500'); }).repeat(0).priority(500);
signal.dispatch();
signal.dispatch();

Fire Callback when registering

var signal = new Signal();
signal.add(() -> { trace('Priority 100'); }).priority(100).fireOnAdd();
// output 'Priority 100'
signal.add(() -> { trace('Priority 500'); }).priority(500);
signal.dispatch();
// output 'Priority 500'

Remove Listener

var signal = new Signal();
signal.add(example);
signal.dispatch();
signal.remove(example);
signal.dispatch();

function example()
{
	trace('example');
}


// output 
'example'

Remove All

To remove all listeners on a signal simple call the remove function with true as the argument

var signal = new Signal();
signal.add(example);
signal.dispatch();
signal.remove(true);
signal.dispatch();

function example()
{
	trace('example');
}


// output 
'example'

Deprecated package

Due to incompatibilities with the CPP Mac target the "signal" package has been deprecated in favour of "signals".

Warning: The "signal" package will be removed in a future release, it is recommended to switch to the "signals" package to avoid future incompatibility issues.

signals's People

Contributors

6j7kzg2f avatar slouffka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.