Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
/ QuickEvent Public archive

Because every object should have the ability to fire an event.

License

Notifications You must be signed in to change notification settings

roman-16/QuickEvent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Because every object should have the ability to fire an event.

Usage

Typescript

class Car
{
    public onStart: QuickEvent = new QuickEvent();

    public start(): void
    {
        this.onStart.fire(this);
    }
}

let car: Car = new Car();

car.onStart.listen(carStarted);
car.start();

function carStarted(args: Object): void
{
    (<Car>args).onStart.unlisten(carStarted);

    console.log("args: " + args.constructor); //Car
}

Javascript

var Car = (function ()
{
    function Car()
    {
        this.onStart = new QuickEvent();
    }

    Car.prototype.start = function ()
    {
        this.onStart.fire(this);
    };

    return Car;
}());

var car = new Car();

car.onStart.listen(carStarted);
car.start();

function carStarted(args)
{
    args.onStart.unlisten(carStarted);

    console.log("args: " + args.constructor); //Car
}