Mate is an amazing flex framework, but people come from Cairngom world would be curious how can one ‘Manager’ talk to another ‘Manager’? such as AuthorizationManager has a User object which is a login user, AccessManager wants to use the AuthorizationManager.user.Unlike Cairngorm, you can not access the object by the singleton method,i.e. AuthorizationManager.getInstance().user. Mate promotes depency injection and loose couple coding style, so there are different ways to do it under different use case:
- Property Injector
Using this when a manager needs an object from another manager, and should be updated automatically when it changes.
Set the registerTarget attribute to true when creating the receiving manager (by default it is true so this is not necessary), and create a Injectors that sets up a binding. The receiving manager will be updated just like a view or presentation model object would.
<EventHandlers type="{FlexEvent.PREINITIALIZE}"> <ObjectBuilder generator="{ApplicationManager}" registerTarget="true"/> </EventHandlers> <Injectors target="{ApplicationManager}"> <PropertyInjector targetKey="saveNeeded" source="{DocumentManager}" sourceKey="documentDirty"/> </Injectors> - Events
When a manager must be able to notify the application of something.Inject a dispatcher into the manager when it is created. The manager can use this dispatcher to dispatch events that can be heard in the event map.
<EventHandlers type="{FlexEvent.PREINITIALIZE}"> <ObjectBuilder generator="{ApplicationManager}"> <Properties dispatcher="{scope.dispatcher}"/> </ObjectBuilder> </EventHandlers> <EventHandlers type="{ApplicationEvent.EXIT}"> <MethodInvoker generator="{NavigationManager}" method="navigate" arguments="{[NavigationManager.EXIT]}"/> </EventHandlers>In ApplicationManager:
dispatcher.dispatchEvent(new ApplicationEvent(ApplicationEvent.EXIT - DataCopierWhen a property on a manager is needed as an argument in a method call.Use a DataCopier to place the object temporarily on the data object, for easy access in the arguments attribute of a MethodInvoker tag.
<DataCopier destination="data" destinationKey="user" source="{UserManager}" sourceKey="user"/> <MethodInvoker generator="{NavigationManager}" method="navigate" arguments="{[NavigationManager.USER_PAGE, data.user]}"/>