I’ve never understood why many MATE developers don’t use proper getter/setter properties within Managers. I’ve just assumed it is because MethodInvoker is the preferred means to communicate with Managers. Setting an individual property on a Manager hasn’t been an easy thing to do, until now, so I wonder if that will change?
Having read through similar discussions on the forums however, I’m not convinced MATE purists will like/agree with this post, but I feel most confortable with property getter/setter properties and it has always been a common method in ActionScript.
Mate 0.8.6 included a new tag called PropertySetter and my eyes lit-up as soon as I read it on the change log. The PropertySetter tag (there’s no documentation for this tag yet) allows you to communicate with Managers by directly assigning values to a property, and using getter/setter property functions to check, manipulate and fire off other events as necessary.
Before the PropertySetter tag my EventMap used to communicate with Managers like this:
<EventHandlers type="{PreferencesEvent.BREAK_LENGTH}" debug="false"> <MethodInvoker generator="{ApplicationManager}" method="setBreakLength" arguments="{event.value}" /></pre> </EventHandlers>
and the related methods within my Managers used to look like this:
private var _breakLength : int = 0; [Bindable(event="breakLengthChanged")] public function get breakLength () : int { return _breakLength; } public function setBreakLength (value : int) : void { breakLength = value; }
notice the use of a proper property getter function, but no proper property setter function – that has always felt so awkward to me. With the PropertySetter tag, I can now set a property in my Manager from my EventMap like this:
<EventHandlers type="{PreferencesEvent.BREAK_LENGTH}" debug="false"> <PropertySetter generator="{ApplicationManager}" targetKey="breakLength" source="{event.value}" /></pre> </EventHandlers>
and use proper property getter/setter functions in my Manger like this:
private var _breakLength : int = 0; [Bindable(event="breakLengthChanged")] public function get breakLength () : int { return _breakLength; } public function set breakLength (value : int) : void { _breakLength = value; dispatchEvent(new Event('breakLengthChanged')); }
I’m not sure what the general community at large thinks? I’ve started a thread over on the mate forums to discuss it, but it would be great to hear other peoples opinions on what should be best practice.
Filed under: ActionScript, flex, frameworks, mate