Question

I am learning pureMVC and trying to implement the framework into one of my application. I have follwing case:

My main application has Canvas which is used to add different kind of custom components. One of the custom component is a "Search Component" (multiple instances are created on page). My search component has a textfiled and a search button and initiate search in following steps:

1-Clicking search button dispatches a custom event, that custom event keeps reference of search component as a property.

2-My AppMediator listens the custom event and get the reference of current search component along with search text.

3-Mediator send a notification (sentNotification(AppConstants.SEARCH_CLICKED, component)).

4-I have registered a command with SEARCH_CLICKED notification.

5-Command retrieve a WebserviceProxy and invokes its Search(text) method.

6-WebserviceProxy talks to remote webservice and uses asyncToken to get results.

My Questions is: My Command has the reference to the custom search component when it start search but search webservice takes some time and get the result. How can i handle the results back to custom search component that initiated the search. Since i have multiple instances of search component. What is the best place to keep the reference of that component, should i add a variables in WebserviceProxy to keep that reference and hand the results over to it, or i have to create a Global Proxy to keep references of such components?

Thanks

Was it helpful?

Solution 2

Based on Anton's answer, i re-think and tried to separate dependencis. As a result, i tried to mediate each instance of Search Widget with "SearchMediator" separately by providing different ID to the constructor of Mediator. Now, when search widget intiates a new search, it's mediator invokes the Command, Command invokes a method of Proxy to do actual search and fetch results from DB and sends a Notification. SearchMediator takes care about that notification and hands over the results to appropriate UI.

OTHER TIPS

I have been using PureMVC for some years and I like it!

I think you have not yet understood roles and collaboration of main components.

  1. You should not have any dependencies between Commands and UI-elements. Your Mediator has to get the concrete value from your UI-component and send it through the Notification. In this case the Command and the Proxy will get only a text value and it is no matter, what is the source of it! Suppose you will change your UI after some time and you will have another components on the user side to determine the search value. In your case you would have to change the Proxy and the Command. It would be bad.

  2. Proxy may not have any information about Commands and Mediators. It can only offer its functions to let another components interact with it AND it sends Notifications with new information after getting it without knowing who is interesting in it.

Read the description of the framework once more and write your questions. I had some problems with understanding the stuff too, I see your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top