2017 © Pedro Peláez
 

library hacktions

Event library written in hacklang

image

hackpack/hacktions

Event library written in hacklang

  • Thursday, May 22, 2014
  • by brianium
  • Repository
  • 3 Watchers
  • 5 Stars
  • 1,207 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Hacktions

"hacktions speak louder than words", (*1)

Events for Hacklang, (*2)

Usage

Hacktions exposes two traits:, (*3)

EventEmitter

Run of the mill event emitter with hack type safety., (*4)

class MyEmitter
{
   use EventEmitter;
}

$emitter = new MyEmitter();

//listeners all use variable argument signatures
$lambda = (...) ==> print(func_get_args()[0]); 
$emitter->on('myevent', $lambda);

//trigger fires all registered events with the given name - can take variable arguments
$emitter->trigger('myevent', 'brian');

$emitter->off('myevent', $lambda); //remove a single listener
$emitter->removeListeners(); //remove all listeners
$emitter->removeListeners('myevent') //remove all 'myevent' events

Subject

Hacktions supports explicit subject/observer relationships:, (*5)

class Cook
{
    //Cook notifies Waiter objects
    use Subject<Waiter>;

    protected Vector<Burger> $cookedBurgers = {};

    public function cook(Burger $burger): void
    {
        $this->cookedBurgers->add($burger);
        $this->notifyObservers();
    }

    //implement methods to work on cooked items...
}

class Waiter implements Observer<Cook>
{
    //Waiter observes a cook
    public function update(Cook $cook, ...): void
    {
        $burger = $cook->orderUp();
        //deliver burger...
    }
}

The Subject has the following methods:, (*6)

registerObserver(T $observer): void

Registers a new observer with the subject., (*7)

removeObserver(T $observer): void

Removes the specified object from the list of observers., (*8)

notifyObservers(...): void

Notify all observers of a change and optionally pass additional data., (*9)

Running tests

Tests are written using HackUnit. They can be run with the following:, (*10)

bin/hackunit Tests/

hhi

As always, make sure to copy hhi files to the project directory if type checking is desired:, (*11)

cp -r /usr/share/hhvm/hack/hhi /path/to/hacktions

The Versions

22/05 2014

dev-master

9999999-dev

Event library written in hacklang

  Sources   Download

MIT

The Development Requires

events hack hhvm

21/05 2014

v1.1.1

1.1.1.0

Event library written in hacklang

  Sources   Download

MIT

The Development Requires

events hack hhvm

21/05 2014

v1.1.0

1.1.0.0

Event library written in hacklang

  Sources   Download

MIT

The Development Requires

events hack hhvm

20/05 2014

v1.0.0

1.0.0.0

Event library written in hacklang

  Sources   Download

MIT

The Development Requires

events hack hhvm