23.4. Revising Registration

To see how this Responder methodology works, you are going to revise the registration feature.

First revise the UserEvent class to take in an optional IResponder parameter to be held in a new responder property.

Add the following variable to the UserEvent class:

public var responder:IResponder;

Then update the constructor to take in an optional responder parameter and assign it to the responder property:

public function UserEvent(type:String, user:UserVO = null,
responder:IResponder = null, bubbles:Boolean=false, cancelable:Boolean=false)
        {
            super(type, bubbles, cancelable);
            this.user = user;
            this.responder = responder;
        }

Now update the RegisterUserCommand. Start by adding the following property:

private var responder:IResponder;

Next, update the execute function to assign the responder passed by the event to the responder property. Additionally, remove the code that updates the registrationStatus property of the ModelLocator, as this will no longer be needed:

public function execute(event:CairngormEvent):void
        {
            var evt:UserEvent = event as UserEvent;
            this.responder = evt.responder;
            var delegate:UserDelegate = new UserDelegate(this);
            delegate.register(evt.user);
        }

Now update the result function of the RegisterUserCommand to trigger the result function of the responder passing along the event object, if one has been defined, and remove the code updating the registrationStatus property of the ModelLocator:

public function result(data:Object):void { var ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.