Skip to content

Instantly share code, notes, and snippets.

View Stray's full-sized avatar

Stray Stray

  • Innerleithen, Scotland
View GitHub Profile
public class WarnIfCurrentEditDataIsChangedCommand extends Command
{
[Inject]
public var getEditedVOSignalResponsePair:GetEditedVOSignalResponsePair;
[Inject]
public var editingModel:IEditingModel;
[Inject]
public var dataChangeEvent:AdminDataEvent;
@Stray
Stray / ICompoundInterface.as
Created October 21, 2010 12:47
I had hoped that the compiler/AVM might be able to infer that the interface is valid.
public interface ICompoundInterface extends IDrawable, IEdible
{
}
public class SomethingConcrete implements IDrawable, IEdible
{
}
// throws type conversion error
var concreteThing:ICompoundInterface = ICompoundInterface(new SomethingConcrete());
private function isACommand(commandClazz:Class):Boolean
{
if(describeType(commandClazz).factory.method.(@name == "execute").length() > 0)
{
return true;
}
return false;
}
@Stray
Stray / MediatorThatNeedsData.as
Created November 5, 2010 17:50
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);
@Stray
Stray / usingCompoundCommandMap.as
Created November 6, 2010 09:44
Map multiple events to trigger a command only when all events are received (in order if required)
// params: command, isOneShot, requireInOrder
compoundCommandMap.mapToEvents(SomeAwesomeCommand, true, true)
.addRequiredEvent(SomeEvent.SOMETHING_HAPPENED, SomeEvent);
.addRequiredEvent(SomeOtherEvent.SOMETHING_ELSE_HAPPENED, SomeOtherEvent, 'somethingElseHappened');
.addRequiredEvent(SomeOtherEvent.STUFF_HAPPENED, SomeOtherEvent, 'stuffHappened');
// in the command itself
[Inject]
public var someEvent:SomeEvent;
@Stray
Stray / ExampleUITest.as
Created November 8, 2010 16:59
Example roboteyes actual UI Test
package com.client.project.xendtoendtests {
import asunit.framework.TestCase;
import AcademyShell;
import shell.AcademyShellSkin;
import com.newloop.roboteyes.inViewOf;
import com.newloop.roboteyes.core.RobotEyes;
@Stray
Stray / NosyMediator.as
Created November 16, 2010 11:06
Nosy mediators (or mediator-mini-controllers) open the view's mail
// Good mediator behaviour:
function handleDataEvent(e:DataEvent):void
{
var userVO:UserVO = e.userVO;
view.showUsername(userVO.firstname, userVO.surname);
view.showAge(userVO.age);
view.setStatus(userVO.isSaved);
}
@Stray
Stray / GetTheFunctionOwner.as
Created November 21, 2010 20:07
Is this possible?
////////// code in a robotlegs mediator
private function someHandler(e:Event):void
{
// whatever
}
// this mediator adds the handler to the relaxedEventMap
override public function onRegister():void
@Stray
Stray / LoggingContext.as
Created November 27, 2010 18:57
Easy logging in robotlegs through events
// code required in your context startup - this uses Config::Variables to set the logger at compile time,
// but you could just swap it in/out as required and do away with the if/else etc
commandMap.mapEvent(LoggingEvent.LOG_EVENT, UpdateLogCommand, LoggingEvent);
if(CONFIG::HiddenLogging)
{
injector.mapSingletonOf(ILoggingService, TraceLoggingService);
}
else if(CONFIG::EmailLogging)
@Stray
Stray / EndToEndTestWishes.as
Created December 4, 2010 16:46
How should I go about this in asunit 4?
package strategy.xendtoendtests {
// imports removed for brevity
public class PyramidGameEndToEndTest extends TestCase {
private var robotEyes:RobotEyes;
private var config:IGameConfig;
private var endToEndTests:Vector.<Class>;
private var runningEndToEndTests:Boolean;
private var dummyDispatcher:EventDispatcher = new EventDispatcher();