Skip to content

Instantly share code, notes, and snippets.

@Stray
Created November 6, 2010 09:44
Show Gist options
  • Save Stray/665316 to your computer and use it in GitHub Desktop.
Save Stray/665316 to your computer and use it in GitHub Desktop.
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;
[Inject(name='somethingElseHappened')]
public var somethingElseEvent:SomeOtherEvent;
[Inject(name='stuffHappened')]
public var stuffHappenedEvent:SomeOtherEvent;
// etc - but there's a common use case where you'd only be interested in the fact that all 3 signals have fired and wouldn't need the events at all, or would only need the last one.
// params: command, isOneShot, requireInOrder
compoundSignalCommandMap.mapToSignals(SomeAwesomeCommand, true, true)
.addRequiredSignal(UserLoadedSignal);
.addRequiredSignal(AccountOptionsLoadedSignal);
.addRequiredSignal(PreferencesLoadedSignal);
// in the command itself - most likely you'd need to use VOs so you don't have multiple
// injected values of the same type
[Inject]
public var userVO:UserVO;
[Inject]
public var accountOptionsVO:AccountOptionsVO;
// etc - but there's a use case where you'd only be interested in the fact that all 3 signals have fired and wouldn't need the payloads at all.
@benoitjadinon
Copy link

good plan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment