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 / MultiCore Version / EmployeeAdm demo for GWT. on: June 19, 2009, 01:14:32
I found the new demo at http://trac.puremvc.org/Demo_Java_MultiCore_GWT_EmployeeAdmin/browser/tags/EmployeeAdmin_1_0 and checked out the source code because I have used the last 3 weeks reading about and to create my first puremvc based GWT application following all of the best practices.

In the sample application I found that the Mediators has been combined with view components and handølign all notification, view ui and events. Also it tightly communicate with Proxies. From all I have read in the best practices documents and forums I am a little confused when I see this.

I expected the Mediator and UI code to be separated and the UI code not to directly communicate with proxies?
2  PureMVC Manifold / MultiCore Version / Changes to observerlist when notifying observers not used. on: June 06, 2009, 05:24:20
Hello PureMVC users!
Im a new user to puremvc and have been playing with PureMVC the last week to find out how its working. I ported the puremvc4gwt loginsample to this puremvc multicore version and saw a small difference in how the code notifies observers.


From the loginsample from puremvc4gwt I found out that the StartupCommand adds two subcommands (PrepView and PrepModel) which when executed with the Startup event registers the proxy and mediators.

In the official multicore version in method notifyObservers in the View class I found that (marked in bold in the code below) the code creates a private copy of the observer list and uses this to iterate.

The issue I saw when running the loginsample with the official puremvc multicore version was that any new or changes to observersMap registered during the notification of the STARTUP was ignored.

As you see in the code below, the private copy doesnt see any new observers, but actually there has been one registered by the StartupCommand that also listens to the same Startup notification (SplashScreenMediator also listens to STARTUP command). It is present in the observermap and observers_ref but not in the array copy observers.

I did a quick change to the code, to work on the "live" list of observers_ref instead of a private copy, and this worked. Any changes to the list of observers are added to the end of the list so if any new observers are registered they are executed in the end of the iteration. This is also how puremvc4gwt does it in its code.

What is the reason behind isolation the observerlist in a private copy? Is it the loginsample that is not following best practice?
 
   public void notifyObservers( INotification note )
   {
      List<IObserver> observers_ref = (List<IObserver>) this.observerMap.get(note.getName());
      if (observers_ref != null) {
           
      // Copy observers from reference array to working array,
                // since the reference array may change during the
                // notification loop

         Object[] observers = (Object[])observers_ref.toArray();
         
         // Notify Observers from the working array
         for (int i = 0; i < observers.length; i++) {
            IObserver observer = (IObserver)observers;
            observer.notifyObserver(note);
         }
      }
   }
Pages: [1]