Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
July 26, 2017, 05:35:18 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Mediator: How to get rid of the flash.events.Event dependency?  (Read 2091 times)
openoli
Full Member
***
Posts: 44


View Profile
« on: March 22, 2016, 12:44:24 AM »

Hi,
I've doing some tests using PureMVC with FlexJS and it seems that it works fine.
(If it makes sense I'll publish a PureMVC FlexJS version as soon as I'm able to create a swc of it)

What I'm currently trying to achive is to outsource the complete business logic to a pure AS3 lib using PureMVC.
My goal is to be able to switch between the "Flex standard SDK" and "FlexJS" without changing any line of the business logic. So the business logic has to be free of any flash or flex dependencies.

Cause the mediators main purpose is to handle view events it has a depenency to flash.events.Event (or org.apache.flex.events.Event for FlexJS).
To resolve the dependency to the view itself I'm using interfaces and that works fine.
But the interface itself also has currently a dependency to IEventDispatcher.

So I'm searching for a solution that makes the business logic flash/flex free while putting as much code as possible to it. In best case the app that uses the "business logic lib" tells the lib which kind of Event implementation it has to use respectively pass the 'right' Event implementation to it... some kind of a switch.

One solution that comes in my mind is to extend the concrete mediator, overwrite all methods that depends on Event and make it part of the app that uses the lib. But this would mean additional code.

Any ideas how to achive this much more elegant?

Thanks,
Olaf


Code:

// How to get rid of it?
import flash.events.Event;
//import org.apache.flex.events.Event;

public class MyMediator extends Mediator implements IMediator
{
    public static const NAME:String = 'ApplicationMediator';
    
    public function ApplicationMediator(component:IViewMyView) {
        super(NAME, component);
    }

    override public function onRegister():void {
super.onRegister();

         view.addEventListener(ApplicationEvents.DO_SOMETHING, onDoSomething);
    }

    // How to get rid of Event?
    private function onDoSomething(event:Event):void {
    }

    public function get view():IViewMyView {
        return viewComponent;
    }
}

Code:

// How to get rid of IEventDispatcher?
import flash.events.IEventDispatcher;
//import org.apache.flex.events.IEventDispatcher;

public interface IViewMyView extends IEventDispatcher
{
    function setData(data:String):void;
}
« Last Edit: March 22, 2016, 01:46:48 AM by openoli » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #1 on: March 23, 2016, 07:36:38 AM »

The Mediator class doesn't depend on the Event class. It is merely an idiom for it to add event listeners to its component. So there's no need to rewrite Mediator.

The component could just as well use a PureMVC Notifier instance (or extend notifier). and the Mediator would receive notifications from the components just like it receives them from other parts of the PureMVC system: Notifications.

This is usually not done, because A) we already have events in Flex/Flash, and B) to keep the component unaware of the PureMVC apparatus. However, in your case you're trying to make it so that the code is implemented the same way for JS as for Flash, and in that case you're going to have to make some compromises, and I'd say using the Notifier class which is common to both apps using PureMVC would be a reasonable way to do it.

Cheers,
-=Cliff>
Logged
openoli
Full Member
***
Posts: 44


View Profile
« Reply #2 on: April 04, 2016, 12:46:39 AM »

Quote
I'd say using the Notifier class which is common to both apps using PureMVC would be a reasonable way to do it

I think I'll try it this way.
Many thanks for your continued support, I appreciate it!

Olaf
Logged
Pages: [1]
Print
Jump to: