DataBinding a Proxy to a Mediator
Written by Simon Bailey
This has been a topic I have wanted to mention for a while now, actually since my Combining the PureMVC StateMachine Utility with Slacker post as I use this particular logic in there. When I first used a MVC framework primarily PureMVC one of the concepts I toyed around with was different approaches for getting data from the Proxy to the Mediator. This decision is situation dependent so a simple one shoe fits all doesn’t apply here, but for the purposes of data getting updated in a proxy and the necessary requirement to ensure a Mediator gets informed of this change to the data you could:
- Adhering to the PureMVC logic you could fire off a notification from your Proxy and register an interest in your Mediator passing the data as the notification body.
- You could do the above but create an instance of your Proxy in the Mediator and directly access the data within a method triggered by an Event for example.
Here’s another suggested approach.
I have mentioned that I personally don’t see a major problem with a simple reference to the Proxy in the Mediator for the simple fact your just reaching in and grabbing data, no biggie but I understand that some have concerns with this approach. However I don’t have a major problem with getting the instance of a Proxy from the facade and having this reference in my Mediator. With this I can then have a much better handling for keeping data in a View updated using BindingUtils. Using my previous blog post as an example I would define a getter and setting in the Proxy as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
And then in the Mediator:
1 2 3 4 5 6 7 |
|
And that’s it! Now when ever the data in my Proxy is updated I know through DataBinding that the View will be updated with the latest data value.
If you would like a simple introduction into PureMVC then be sure to read my post showing a super simple example http://www.newtriks.com/?p=352. Also look at a real world example I build using the above logic and States http://www.newtriks.com/?p=363.