Using Robotlegs App as Component
Hi,
I am created a DatePicker component using Robotlegs, using MVC to allow re-skinning of the component easily. My problem is I am unsure the best practice to set properties on the component from inside another application that is using the component. Example I would like to set the initial date of the DatePicker component. I had a few ideas on different approaches, but none of them seemed correct.
Example my Robotlegs application (component) is DatePickerComponent:
var datePicker:DatePickerComponent = new
DatePickerComponent;
datePicker.date = new Date(1975, 0, 1);
Would I use a Service class to allow other applications to set initial states of the component?
datePicker.myService.date = new Date(1975, 0, 1);
Thanks for any insight,
Paul
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Ondina D.F. on 23 Nov, 2011 06:22 PM
Hi Paul,
This discussion is marked as private. Was this your intention?
2 Posted by truthreveller on 23 Nov, 2011 08:41 PM
Opps don't know how it was published as private, thanks.
Paul
Support Staff 3 Posted by Ondina D.F. on 24 Nov, 2011 11:40 AM
Hi Paul,
In the following code snippets I’ll show you an oversimplified scenario:
CalendarView (DateChooser)
CalendarMediator
CalendarModel
CalendarEvent
CalendarCommand
The flow:
1. CalenderView.datechooser_changeHandler() ->CalenderEvent-> CalendarMediator-> CalenderEvent-> CalendarCommand->CalendarModel-> CalenderEvent->rest of the application
2. rest of the application-> CalenderEvent->CalendarMediator-> CalenderView. initilizeCalendarDate()
The CalendarMediator would be the bridge between your CalendarView and the rest of your application.
If you need to set the date on your DateChooser, you can let CalendarMediator access a public method in your CalendarView: initilizeCalendarDate()
CalendarMediator
CalendarView.mxml
If you need to send a chosen date to another component in your application, you can let CalendarView dispatch an event(CalendarEvent.CALENDAR_SET_DATE) with the selectedDate as a payload and CalendarMediator, who has registered an event listener for it, would re-dispatch it.
CalendarCommand previously mapped like this: commandMap.mapEvent(CalendarEvent.CALENDAR_SET_DATE, CalendarCommand, CalendarEvent, true);
would do this:
CalendarModel
Other parts in your application would register a listener for CalendarEvent.CALENDAR_DATE_CHANGED and could use the date.
CalendarEvent
I hope this gives an idea of how to make a DateChooser reusable.
Let me know what you think:)
Ondina
4 Posted by truthreveller on 24 Nov, 2011 07:17 PM
Wow really great response, your code is really well structured.
If the Robotlegs Calendar application is inside another non-Robotlegs application, is there anyway to dispatch events to the application such as the "CalendarEvent.INITIALIZE_CALENDAR_DATE" event?
Support Staff 5 Posted by Ondina D.F. on 25 Nov, 2011 12:20 PM
Hi Paul,
Since you want to communicate between a Non-Robotlegs-Application and a Robotlegs-Application loaded as a Module, the best way, in my opinion, is to use an interface, as you’d do with any other modules.
But if you want to communicate via events, you can use a sharedEventDispatcher and a DynamicEvent.
NonRobotlegsApplication
RobotlegsAsModule
Note that the event listeners have a weak reference!
A strong reference to the sharedEventDispatcher would prevent the module from being garbage collected.
I hope this helps.
Maybe somebody else will chime in with a better solution, in case there is one :)
Ondina
6 Posted by truthreveller on 25 Nov, 2011 06:48 PM
I like both your ideas. Thanks Ondina. :)
truthreveller closed this discussion on 25 Nov, 2011 06:48 PM.