Code Monkey home page Code Monkey logo

robotlegs-utilities-signalmediator's Introduction

A Signal equivalent for the EventMap

The robotlegs Mediator makes use of the EventMap to help with automatic clean-up when the mediator is removed.

Without clean up, memory leaks and duplication of listeners can occur as your views come and go from the stage and your mediators are created and destroyed.

The SignalMediator provides a SignalMap to handle this unmapping for you when the mediator is removed.

Usage

Where your mediator makes use of a Signal - whether injected or on the view - extend SignalMediator.

Instead of registering a listener with a signal directly, make use of the addToSignal and addOnceToSignal methods.

override public function onRegister():void
{
	// add normally
	addToSignal(someInjectedSignal, someHandler);       
	
	// add once
	addOnceToSignal(view.submit, submitHandler);
}   

The SignalMediator will then make use of the SignalMap to add the handlers to these signals, and when the mediator is destroyed the handlers will all be unmapped. (Via the preRemove() method which is called by the MediatorMap automatically when views leave the stage).

To manually unmap a signal-listener

The sugar methods addToSignal and addOnceToSignal are provided for convenience. You can also access the SignalMap property of the SignalMediator directly, and you should use this approach to manually remove a signal (for example in response to another signal or a normal event listener):

signalMap.removeFromSignal(someInjectedSignal, someHandler);

You can also use the SignalMap outside of SignalMediator

SignalMap itself has no dependencies and can be used within a complex view, a service or any other place it might be useful to you. Even a controller if you're into that kind of thing.

Compatibility

This should be compatible with any 1.x robotlegs release, and at least 0.7 and 0.8 releases of signals. The SignalMap makes use of the Vector class - available only in Flash Player 10+. It should be trivial to switch out the Vector for an array if you required FP 9 usage.

robotlegs-utilities-signalmediator's People

Contributors

stray avatar

Watchers

 avatar  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.