Mate Framework - data validation before remote call
Until recently, I used cairngorm as the basis for flex. However, on this last project, I switched to Mate. This is still a little confusing for me as I am used to leaving data in the model. I have a couple of components that rely on the same dataset (collection). In the component, the generated full handler dispatches a "GiveMeMyDataEvent" which is captured by one of the eventmaps. Now in cairngorm in my command class, I would quickly peek into the model to decide if I need to fetch data from the server or not, and then either return data from the model or call db. How do I do this in Mate? Or is there a better way to do this, I am trying to use the data that has already been received from the server, but at the same time I am not sure if I downloaded the data or not. If a component that uses the same datawas created, then the answer is yes, otherwise no. Any help / hints are greatly appreciated.
a source to share
Most of the things in Mate are indirect. You have managers who manage your data and you set up injectors (which are bindings) between the managers and your views. Injectors make sure your views are in sync with your managers. This way, views are always up to date. The views are not updated as a direct consequence of the dispatch of the event, but as an indirect consequence.
When you want to load new data, you send an event that hits the event map, which in turn calls some service that downloads the data and returns it to the event map, and the event map inserts it into the appropriate manager.
When the manager is updated, the injectors check if the views are updated.
When using injectors, you will always have the most recent data in your views, so if there is data in the views, the data is loaded - unless you need to periodically refresh the data, in which case it is up to you to expire and dispatch the event that triggers the service call. which triggers an update that triggers injectors to re-inject new data into and around the views.
So, in short, the answer to your question is that you need to make sure you are using injectors correctly. If this is too high an answer for you, I know you can get more help in the Mate forums .
a source to share
I ran into a similar situation with an application I'm currently working on and found it easily implemented in Mate when you start thinking about two events.
The first event looks like DataEvent.REFRESH_MY_DATA
. This event is handled by some DataManager, which can decide to either ignore it (since the data is already present on the client and is considered updated), or the manager can dispatch an event like this DataEvent.FETCH_MY_DATA
.
The event FETCH_MY_DATA
triggers a service call in the event map that updates the value in the manager. This update is being inserted into the view, happy days :)
a source to share