Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  PureMVC Manifold / Standard Version / Re: Linking UI element and Mediator on: August 12, 2011, 10:38:50
you have to do several things to set it up.

1) In the view component's header file, you have to define the protocol with the methods that the mediator will implement.

2) You have to define the delegate in the header's interface like
:
id<NameOfDelegate> delegate then make it a property and synthesize it.

3) You then have to have an IBAction method in the view components implementation if you are relying on a touch gesture in a NIB file. it is here that you actually call the delegate like
:
[delegate nameOfMethodInProtocol] I have found that if you are sending the name of the button being touched or other data, it has to be sent as an argument along with this method.

4)In the mediator's header file, you must set the protocol on the mediator
:
Mediator <NameOfDelegate>
5)You just mentioned having to set the delegate in the onRegister method

6)You then finally have the method(s) from 1 above put into the mediators implementation file.

It is somewhat of a pain, obviously. But then again, you do almost the same amount of work in Flash with dispatching an event. Depending on your AS3 editor, it could actually be less typing with xcode's code completion.
2  Announcements and General Discussion / Architecture / Re: Best practice for mouseEvents in Mediator on: May 07, 2011, 11:49:01
This makes a lot more sense... also produces the least code (not having to getChildAt through for loops to add listeners to all the button on a VC). Thanks!
3  Announcements and General Discussion / Architecture / Best practice for mouseEvents in Mediator on: April 29, 2011, 04:29:33
Hi, I was wondering what is the preferred way of handling mouseEvents in regard to the independence of the view component and its mediator?

For instance, I have a button which I have to have a listener for in the mediator that tracks that it has been clicked and then sent to a command in the framework. So it would make sense that I add a listener for it from the mediator. But that same button has an effect on the view component itself at the same time (toggling visibility of other elements in the view component). So I came up with the following possibilities:

1) Add only the listener in the mediator, and handle the sendNotification and view component's elements through the shortcut viewComponent getter method

2) Have an independent mouseListener in the mediator that handles only what needs to be communicated with the rest of the framework AND have an independent listener in the view component to handle its own visual elements

3) Have only one mouseEvent listener in the view component, which then dispatches an event listener (a text string) up to the mediator once it is clicked.

1 offers less code, 2 seems to be more in line with my limited understanding of the appropriate roles of mediators, and 3 seems to just be an alternate version of 2. It seems somehow wasteful to have 2 mouseEvent listeners on the same object, however.

Any ideas as to what is the best practice?
Pages: [1]