Skip to content

Latest commit

 

History

History
76 lines (49 loc) · 2.42 KB

File metadata and controls

76 lines (49 loc) · 2.42 KB

Relaxed Event Map

Overview

An extension for Robotlegs v2.

The Relaxed Event Map allows to register listeners with the shared event dispatcher for events that already have been dispatched. It facilitates in dealing with racing conditions, where e.g. a model has already sent an update event before a mediator that listens for that event has been instantiated.

Notes:

Basic Usage

It is necessary to tell the Relaxed Event Map to remember an event and store the last dispatched instance.

relaxedEventMap.rememberEvent(FooEvent.Foo, FooEvent);

If you register a listener for this event it will be called even if the event has already been dispatched.

eventDispatcher.dispatchEvent(new FooEvent(FooEvent.FOO));
relaxedEventMap.mapRelaxedListener(FooEvent.Foo, listener, FooEvent); //handler will be called immediately, i.e. synchronously

Unmapping specific listeners

relaxedEventMap.unmapRelaxedListener(FooEvent.Foo, listener, FooEvent);

Unmapping all listeners for a key

You can pass a key as a fourth parameter to the mapping method and unmap all listeners at once with unmapListenersFor.

relaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_UPDATED, updatedHandler, SomeDataEvent, this); //'this' used as key
relaxedEventMap.mapRelaxedListener(SomeDataEvent.DATA_SET_DELETED, deletedHandler, SomeDataEvent, this); //'this' used as key
	
relaxedEventMap.unmapListenersFor(this); //'this' used as key

Relaxed Event Map Extension

Requirements

This extension requires the following extensions:

  • EventDispatcherExtension

Extension Installation

_context = new Context().install(
    EventDispatcherExtension,
    RelaxedEventMapExtension);

Or, assuming that the EventDispatcherExtension has already been installed:

_context.install(RelaxedEventMapExtension);

Extension Usage

An instance of IRelaxedEventMap is mapped into the context during extension installation. This instance can be injected into clients and used as below.

[Inject]
public var relaxedEventMap:IRelaxedEventMap;