Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Workaround for timing issues with onRegister / data providing events
[Inject]
public function set requestScreenDataSyncSignalPair(signal:RequestScreenDataSyncSignalPair):void
{
_requestScreenDataSyncSignalPair = signal;
}
override public function onRegister():void
{
eventMap.mapListener(eventDispatcher, UserDataSetEvent.DATA_SET_UPDATED, dataSetUpdatedHandler);
view.reportRequestedSignal.add(reportRequestedHandler);
requestData(Vector.<UserDataVO> as Class, UserDataSetEvent, dataSetUpdatedHandler);
}
protected function requestData(dataType:Class, dataEventType:Class, responseHandler:Function):void
{
var responseSignal:Signal = new Signal(dataEventType);
responseSignal.add(responseHandler);
requestScreenDataSyncSignalPair.dispatch(dataType, responseSignal);
}
//--------------------------------------------------------------------------
//
// Event Handlers
//
//--------------------------------------------------------------------------
private function dataSetUpdatedHandler(e:UserDataSetEvent):void
{
view.populateWithUserData(e.dataSetVector);
}
public class RequestScreenDataSyncSignalPair extends Signal
{
public function RequestScreenDataSyncSignalPair()
{
super(Class, Signal);
}
}
[Inject]
public function set requestScreenDataSyncSignalPair(signal:RequestScreenDataSyncSignalPair):void
{
_requestScreenDataSyncSignalPair = signal;
}
private function initSyncSignal():void
{
_requestScreenDataSyncSignalPair.add(respondToScreenDataRequestSignal);
}
private function respondToScreenDataRequestSignal(dataTypeRequired:Class, responseSignal:Signal):void
{
if(_dataDeliveredByClassDictionary[dataTypeRequired] == null)
{
throw(new IllegalOperationError('I was not expecting data of this type to be requested'));
return;
}
if(_dataDeliveredByClassDictionary[dataTypeRequired] == NULL_ENTRY)
{
throw(new IllegalOperationError('Data of this type has not been received yet'));
return;
}
responseSignal.dispatch(_dataEventsByDataClassDictionary[dataTypeRequired]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.