Dispatching Strictly-Typed Values with AS3Signals

I was cleaning some code of mine yesterday, when I came across a solution for a common AS3Signal problem which I hadn’t even registering at the time.

The problem:

One of the great things about Signals is the way you can declare the value types that will be dispatched, the example below shows a strictly-typed signal, and its implementation.

This has the advantage of throwing errors if the types dispatched do not match, but the disadvantages of having no code-hinting on the generic dispatch method. I spend quite a lot of time having to navigate back to the original strictly-typed Signal to check its value-classes.

A solution

By simply adding a method that wraps the generic dispatch method, you can strictly-type the dispatch call, and thus get code-hinting:

As you can see, this means loosing the interface and casting to type. However if you (like me) are using DI, you will probably be injecting strictly anyway.

2 thoughts on “Dispatching Strictly-Typed Values with AS3Signals

Leave a Reply

Your email address will not be published. Required fields are marked *