Skip to content

Instantly share code, notes, and snippets.

@Stray
Created January 29, 2013 13:24
Show Gist options
  • Save Stray/4664190 to your computer and use it in GitHub Desktop.
Save Stray/4664190 to your computer and use it in GitHub Desktop.
// in the context
injector.map(AssetRequestSignal).asSingleton();
// in the model/service
[Inject]
public var assetRequestSignal:AssetRequestSignal;
function setUp():void
{
assetRequestSignal.add( handleRequest );
}
function handleRequest(assetID:String, responseSignal:OnceSignal):void
{
if(_cachedAssetsByID[assetID])
responseSignal.dispatch(_cachedAssetsByID[assetID]);
else
loadAsset(assetID, responseSignal);
}
function loadAsset(assetID:String, responseSignal:OnceSignal):void
{
// load the assets and then respond when loaded
}
// in the view:
[Inject]
public var assetRequestSignal:AssetRequestSignal;
private var assetResponseSignal:OnceSignal;
function init():void
{
assetResponseSignal = new OnceSignal(DisplayObject);
assetResponseSignal.addOnce( handleAssets );
assetRequestSignal.dispatch( someSortOfAssetID, assetResponseSignal );
}
function handleAssets(asset:DisplayObject):void
{
if(!asset)
// oh shit...
else
// do stuff as required
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment