(This tag must be placed inside an <EventMap> tag)
An Injectors tag defined in the Event Map is a container for InjectorPropertys that will inject properties coming from a source to a target, but they can also be used for other purposes.
<Injectors target="{MyTargetClass}">
...
</Injectors>
The Injectors tag are similar to the EventHandlers, and when executed, they will run all inner tags in order. EventHandlers are executed when an event of the matching type is dispatched. Injectors, on the other hand, are executed when an object of the class defined in the target attribute is created. In order for the Injectors to run, the object of that class needs to be created within the display list, or be instantiated by the ObjectBuilder or MethodInvoker tags.
Attributes
target
Class
required
The class that, when instantiated, should trigger the inner tags to run. This target must be supplied using bindings, but this binding is only executed once, when the event map is created.
includeDerivatives
Boolean
If true, then subclasses of specified class will also trigger injection. If specified class is an interface, then classes implementing interface will trigger injection. If false, only instances of the specific class will trigger inner tags to run. Default is false.
debug
Boolean
Whether to show debugging information for this Injectors block. If true, Console output will show debugging information as the injectors are applied.
start
Event handler
In the start attribute you can supply an event handler for the event of
type ActionListEvent.START. This event is dispatched right before the actions (normally PropertyInjector items)
are called, when the list starts execution.
Example:
<Injectors target="{MyTargetClass}" start="trace('Execution of injectors list started!')">
...
</Injectors>
end
Event handler
In the end attribute you can supply an event handler for the event of type ActionListEvent.END.
This event is dispatched right after all the items in the list have been executed.
Example:
<Injectors target="{MyTargetClass}" end="trace('Execution of injectors list ended!')">
...
</Injectors>
Inner tags
PropertyInjector
PropertyInjector s defined in the Injectors tag will apply or bind properties specified in the source to the target specified in the parent Injectors target. See more information in the PropertyInjector documentation.
ListenerInjector
A ListenerInjector tag will add an event listener for a specific event type and call the specified method on the target specified in the parent Injectors target. See more information in the ListenerInjector documentation.
Other tags
All other tags allowed inside EventHandlers and MessageHandlers are allowed inside the Injectors. This allows you to inject other properties to the target, such as data coming from a server call (one-time only).
I understand needing an explicit getter and setter when you're doing more than just moving properties from the business logic to the view, but most of the time that's all I'm doing. Having to define code like this:
[Bindable (event="heightChange")]
public function get main_image_height():Number
{
return _main_image_height;
}
public function set main_image_height(h:Number):void
{
_main_image_height = h;
dispatchEvent( new Event('heightChange'))
}
instead of just something like this:
public [Bindable] main_image_height (need that event communication though...)
is really painful.
I need to dig in your code and see if I can contribute a solution to my problem, but I figured I would see if I'm just missing something here (I only started playing with Mate yesterday).
Keep up the great work. Mate looks to be shaping up to be my framework of choice.
setters and getter are the equivalent to a property. Nowhere here it says that you have to use getters and setters. The targetKey for PropertyInjectors needs just to be a public property, which doesn't even need to be bindable. How you expose that property (via a public property or via setters) is up to you.
You can see an example of that here: http://mate.asfusion.com/assets/content/examples/stockQuoteExample/srcview/
I know this section of the docs is a little thin, so that is probably why you are missing that piece. I am working on writing more for this.
If you have more questions, please refer to the forums.
Thanks!
You documentation is difficult to understand. Do you mean
start="handlerMyEventHandler"
or
start="ActionListEvent.START"
start="yourFunction()" or start="yourFunction(event)" or start="yourFunction('some value')"
It is true that the whole event map is defined once, all the objects are created in the beginning and that's it. But those objects are registered to listen to events. If you take the example of the EventHandlers, each EventHandlers in the EventMap gets created in the beginning, but when an event is dispatched that matches the type attribute, those EventHandlers "run", in the sense that they "execute" the steps defined by their inner tags (which also were only defined once). So in this sense, EventHandlers and Injectors contain a recipe with steps that they will "execute" any time needed. For the EventHandlers, that time is when an event is dispatched, for the Injectors is when an object is created (an object that matches the class specified in the target). Does that clarifies it?
i'm currently working on a project with three views.
on the first view, you have a list of person,
when you select a person (person1), a view pop and show informations.
if you select another person (person2), you'll get a new view with the second person informations. the two views (person1 & person2) are display at the same time on the screen.
at this moment, all is ok,
so, let's complicate it : the information view is a viewStack, with two views : viewA and viewB, on viewB, i have a list.
how can i populate the list in viewB on person1 without making change to the list in viewB on person2 ? is it possible with Injectors ?
<Injectors target="{MyTargetClass}">
You reference the Class and not an instance of the class. What if I'm using multiple instances and need to inject into a specific one?
I just started using Mate and I think it's great!
I have a question and would appreciate it if you could shed some light on the matter.
The last sentence of the second paragraph reads:
"In order for the Injectors to run, the object of that class needs to be created within the display list, or be instantiated by the ObjectBuilder tag with attribute registerTarget="true"."
However, the registerTarget property doesn't seem to be documented in ObjectBuilder page. Am I missing something?
I also come across another probable discrepancy. In the MethodInvoker page http://mate.asfusion.com/page/documentation/tags/methodinvoker, it is explained that the cache attribute can take either of the values "global", "inherit", "local" or "none". But an example, a few paragraphs down, suggests that the cache attribute is of Boolean type:
<MethodInvoker generator="{MyWorker}" method="doWork" cache="false" />
Could you please shed some light on this one too?
Cheers,
Naso.
class FooBase
and
class FooSub1 extends FooBase
class FooSub2 extends FooBase
...I want to inject any instances of FooBase, FooSub1, and FooSub2 using a single Injectors block.
Is it possible to do this without explicitly listing every subclass in the 'targets' attribute of the Injectors? Simply listing FooBase doesn't seem to do the trick.
(The end user can create custom subclasses of FooBase, and it's a bit inconvenient to update the Injectors definition with these custom classes.)
Cheers,
Aron
You can set the target to be the super class, and use the includeDerivatives attributes as true and then subclasses will also be injected.
Cheers,
Aron
I have question about parameter target.
My code MyEventMap
<Injectors target="{MyView}">
<PropertyInjector targetKey="model" source="{MyViewModel}"/>
</Injectors>
When instance of class MyViewModel is injecting in property model of MyView?
1. Only when MyEventMap is created. And if at this moment i don't create yet MyView - injecting don't work.
2. When MyView is added to display list?
May be event of creation view in some reasons don't dispatch
I think I understand how to populate the class properties correctly, but I'm not sure how to pull them into my views for later use. I have researched Injectors/Setters/Getters and I'm not sure which is the correct way to handle this sort of information.
Any advice or examples from anyone would be much appreciated!
Thanks to everyone and the asFusion team for sharing their knowledge!
Is it possible, with injectors, to applicate a skin on each Button that are instantiate.. ? Here I say Button, but it could be any other component.
I would like that because i have a lot of component with skins and it would be great.
Thank for the answer
It depends on wich view i put my component.
the problem is if inject the data will go to my 2 views
any solution ? ^^
With the injector how do i do this if i don't have access to the view.
model doesn't know about the view? so can't add a component, it can use dependency injection to know about the change in data in the view but can't add an element to itself or can it?