17. Contexts in robotlegs circa v1
public class Context
{
protected var _injector:IInjector;
protected var _reflector:IReflector;
protected var _contextView:DisplayObjectContainer;
protected var _commandMap:ICommandMap;
protected var _mediatorMap:IMediatorMap;
protected var _viewMap:IViewMap;
}
18.
19. public class Container
{
private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing;
protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe;
}
20. public class Container
{
private var youCantSeeMe:SoLetsHopeIKnowWhatImDoing;
protected var sureYouCanOverrideMe:ButYouAintGettingRidOfMe;
}
in version one,
features were bound to the context.
21. RL2 contexts are created with what you need
not extended with what you don’t
27. .withExtension
public interface IContextExtension
{
function initialize(context:IContext):void;
function install(context:IContext):void;
function uninstall(context:IContext):void;
}
extensions add functionality at any time.
44. Definion
public class TypeMatcher
{
function anyOf(... params):TypeMatcher;
function noneOf(... params):TypeMatcher;
function allOf(... params):TypeMatcher;
}
Usage
new TypeMatcher()
.allOf(ISpaceShip, IEnemy)
.noneOf(DeathStar)
flexible and fluent type matching syntax
49. viewManager.addContainer(contextView);
viewManager.addHandler(mediatorMap);
viewManager.addWatcher(stageWatcher);
viewManager.addContainer(myPopUp);
wire view handlers to view watchers
viewManager.addContainer(myPopUp);
viewManager.addContainer(myAIRWindow);
native support for flex popups and air windows.
54. mediatorMap.map(UserDetailsMediator).toView(IUserDetailsAware);
map mediators to interfaces rather than
concrete classes.
mediatorMap
.map(SomeMenuMediator)
.toMatcher()
.anyOf(TopLevelMenu, AdminMenu, FootMenu);
use type-matching to refine your mapping
59. possible use-cases for a guard:
• prevent mediation when ...
• prevent command execution when ...
60. possible use-cases for a guard:
• prevent mediation when ...
• prevent command execution when ...
mediatorMap
.map(UserDetailsMediator)
.toView(IUserDetailsAware)
.withGuard(UserIsAdminGuard);
a guard represents conditional logic for an
action to occur.
64. scenarios for using a hook:
• customised logging
• view skinning
• view localisation
65. scenarios for using a hook:
• customised logging
• view skinning
• view localisation
• instance configuration prior to command execution
66. scenarios for using a hook:
• customised logging
• view skinning
• view localisation
• instance configuration prior to command execution
commandMap
.map(UserLoginCommand)
.toEvent(UserLoginEvent.LOGIN, UserLoginEvent)
.withHook(ConfigureUserDetails)
67. scenarios for using a hook:
• customised logging
• view skinning
• view localisation
• instance configuration prior to command execution
commandMap
.map(UserLoginCommand)
.toEvent(UserLoginEvent.LOGIN, UserLoginEvent)
.withHook(ConfigureUserDetails)
a hook enables pre-processing on an action.
80. //creates a new instance per injection
injector.map(SomeType); //or injector.map(SomeType, ‘named’);
//create new instance per injection and map to
injector.map(IService).toType(SomeService); //or value .toValue(someInstance)
//map as singleton instance
injector.map(SomeService).asSingleton(); //or .toSingleton(SomeService);
//allows to easily specify custom providers to use for a mapping
injector.map(IService).toProvider(new CustomProvider());
//prevents sharing the mapping with child injectors;
injector.map(SomeService).local(); // .shared() reverts it
//allow child injector to map if none exists
injector.map(SomeService).soft(); // .strong() maps regardless
//prevents changes to the mapping; returns a unique key object
injector.map(SomeService).seal(); //can revert with key and .unseal()
full integration with swift suspenders 2
leverages the entire toolkit.
85. integrated module automation:
• context wired up by parent once added to stage
• view events are collated in the one view manager
86. integrated module automation:
• context wired up by parent once added to stage
• view events are collated in the one view manager
• child injectors created and wired to the parent
87. integrated module automation:
• context wired up by parent once added to stage
• view events are collated in the one view manager
• child injectors created and wired to the parent
• default injections to ensure modules work both
standalone and when integrated.
88. integrated module automation:
• context wired up by parent once added to stage
• view events are collated in the one view manager
• child injectors created and wired to the parent
• default injections to ensure modules work both
standalone and when integrated.
in robotlegs 2, modules just work.
111. covariant mediation (via interfaces)
View
Mediator A
IBehaviour A
IBehaviour B
IBehaviour C Mediator B
Mediator C
112. covariant mediation (via interfaces)
View
Mediator A
IBehaviour A
IBehaviour B
IBehaviour C Mediator B
Mediator C
113. covariant mediation (via interfaces)
e v e n t s
View
Mediator A
e v e n t s
IBehaviour A
IBehaviour B
e v e n t s
IBehaviour C Mediator B
Mediator C
114. covariant mediation (via interfaces)
e v e n t s
View
Mediator A
e v e n t s
IBehaviour A
IBehaviour B
e v e n t s
IBehaviour C Mediator B
Mediator C
n mediators per view.
116. what is wrong with this contract?
import flash.events.IEventDispatcher;
[Event(name="doAsync", type="...ControlEvent")]
public interface IServiceStarter extends IEventDispatcher
{
function serviceReturned():void;
}
we have to extend IEventDispatcher and there’s no
enforcement of contract.
120. with signals, we define the contract
import org.osflash.signals.ISignal;
public interface IServiceStarter
{
function serviceReturned():void;
function get start():ISignal;
}
and force the view to comply
import org.osflash.signals.ISignal;
private var startSignal:ISignal = new Signal();
public function serviceReturned():void
{
Alert.show("The service returned.","Guess what?");
}
public function get start():ISignal { return startSignal; }
...
<s:Button label=”Start” click=”start.dispatch” />
134. Stay updated.
Add you name to the RL2 beta list by commenting on:
j.mp/robotlegs2
Join the robotlegs google group
Follow @robotlegs_as3 on Twitter.