Minimalistic mmvc learning example - problem registering view/mediator

291 views
Skip to first unread message

Cambiata

unread,
Jan 30, 2013, 7:06:56 AM1/30/13
to haxe...@googlegroups.com
Hi!

I've set up a very simple example for my own learning mmvc:
https://github.com/cambiata/mmvc-simple-clock

I'm trying to follow the principles of my own old Robotlegs tutorial here:
https://cambiatablog.wordpress.com/2010/08/07/robotlegs-clock-example-walkthrough-1-views-mediators-and-context/
Don't expect any mmvc best practices here - I'm just experimenting and learning!

Two issues here:

1. The AppMediator is registered as expected, its onRegister method is invoked. But how to register and kick off another View/Mediator pair?
I've created a DisplayView and a DisplayMediator, mapped them in the AppContext using
this.mediatorMap.mapView(DisplayView, DisplayMediator);
but nothing happens (the DisplayMediator.onRegister method is never called.)
Clue?

2. In the examples that I've found, the views are implementing IViewContainer.
Is there a way to keep the views clean from this mmvc framework IViewContainer dependency?
I would prefer the view being as simple gui blocks as possible...

/ Jonas



Postite

unread,
Jan 30, 2013, 10:52:12 AM1/30/13
to haxe...@googlegroups.com
You have to trigger  viewAdded(view); somewhere after your view has been added on the display list. Check the example.
I.m currently moving a little project to MMvc.
It.s quite disturbing but i could help ! If you need
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Postite

unread,
Jan 30, 2013, 10:54:13 AM1/30/13
to haxe...@googlegroups.com
For question 2 
I didn't personnaly implemented IViewcontiner for every views . Just the Appview.
And it works fine.



Le 30 janv. 2013 à 13:06, Cambiata <jona...@gmail.com> a écrit :

Cambiata

unread,
Jan 30, 2013, 12:46:59 PM1/30/13
to haxe...@googlegroups.com, da...@postite.com
Thank you, Postite!

Aha, IViewContainer not needed for views - sounds fine!

This is how views are injected in mediators in Robotlegs:

	public class ClockViewMediator extends Mediator {

		[Inject] // Injection using [Inject] metatag
		private var clockView:ClockView;

		public function ClockViewMediator() {
			super();
		}
	}

Can the same be done in mmvc?
If so, how is then the mediator kicked off so it becomes registered?

Postite

unread,
Jan 31, 2013, 6:30:58 AM1/31/13
to haxe...@googlegroups.com


Le 30 janv. 2013 à 18:46, Cambiata <jona...@gmail.com> a écrit :

This is how views are injected in mediators in Robotlegs:

This is not what i have understood about how Mmvc is wiring up views and mediator.
Be aware that i am not a robotleg user. I am just discovering like you do.
But in my case, i am wiring up views and mediator in the Context


     //AppContext
   mediatorMap.mapView(MyView, MyViewMediator);

Once you have added your view on the display list. 
Trigger 
      //AppView
      viewAdded(myView) // this sits in the main application view after an addedtostage event for example 

And then in your mediator:

     Class MyViewMediator
  
        override function onRegister //this function is called after view added 
        trace(this.view)

See the view is automatically injected as var view.


Voilà.
As i m coding myself an Mmvc app, i feel there is so much imports needed ,you have to write a lot ,even for a simple application.
You have to be very specific in the namming of your signals and command.
I wish i had import package with 
import my.package.signals.*
Like haxe 3 will permit. But for now it is not supported.

Good luck 
























Cambiata

unread,
Jan 31, 2013, 7:31:34 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
Thank you, Postitie, but unfortunately I still don't get it...


//AppView
viewAdded(myView) // this sits in the main application view after an addedtostage event for example

How is the AppView supposed to recognize an instance of another view? (I guess it's somehow handled by the framework...)
If you could wire up a super-simple working example of this, I would be happy!

/ Jonas

david quertelet

unread,
Jan 31, 2013, 7:47:17 AM1/31/13
to haxe...@googlegroups.com

How is the AppView supposed to recognize an instance of another view? (I guess it's somehow handled by the framework...)
If you could wire up a super-simple working example of this, I would be happy!

HA ha ! 
good question !
do you mean an instance of another view or an other instance of the same view ?

Cambiata

unread,
Jan 31, 2013, 8:20:34 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
How is the AppView supposed to recognize an instance of another view?
(Quoting myself...)

Robin Burrer

unread,
Jan 31, 2013, 9:39:14 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
Hi Jonas,
I’m not really sure what your problem is. Views can be nested. Parent views obviously know about their children (regardless if their child views are bound to mediators or not).
That has nothing to do with the framework. The framework handles the communication within your app – how you organize/compose your views is up to you.

Regards

Robin

Cambiata

unread,
Jan 31, 2013, 9:53:54 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
Thank you, Robin!

I'm not talking about nested views here. On the contrary, I would like to instantiate a super-simple view (preferrably not implementing IViewContainer, if possible) and its mediator.

The DisplayView (still implementing IViewContainer) and the DisplayViewMediator can be seen here:
https://github.com/cambiata/mmvc-simple-clock/tree/master/src/clock/view

They are mapped in the AppContext as you can see here:
https://github.com/cambiata/mmvc-simple-clock/blob/master/src/clock/AppContext.hx#L26

Cambiata

unread,
Jan 31, 2013, 9:56:19 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
(Sorry, posted unfinished by accident)

I'm adding the DisplayView to the stage in the Main like this:
https://github.com/cambiata/mmvc-simple-clock/blob/master/src/Main.hx#L36

So, obviously this isn't enough to get the DisplayView/DisplayViewMediator going...
Sorry for being slow, but I'm just trying to follow the principles from Robotlegs, as far as I know them.




david quertelet

unread,
Jan 31, 2013, 10:08:40 AM1/31/13
to haxe...@googlegroups.com
i do like this :



package ;
import flash.display.Sprite;
import flash.events.Event;
import msignal.Signal;
////Boot
class APP 
{
function new()
{
trace("yo");
var view=new APPView();
var appcontext= new APPContext(view);
}

static public function main()
{
var app = new APP();
}
}

//---------------application-----------------


class APPContext extends mmvc.impl.Context
{
public function new(?view:mmvc.api.IViewContainer)
{
super(view);
}
override public function startup(){
mediatorMap.mapView(CompContainerView,APP.CompContainerViewMediator);
mediatorMap.mapView(APPView,APPViewMediator);
}
}
class APPView extends Sprite , implements mmvc.api.IViewContainer
{
public static var REGISTER:Signal1<Dynamic>= new Signal1();
//required by interface
public var viewAdded:Dynamic -> Void;
public var viewRemoved:Dynamic -> Void;
public function new()
{
super();
REGISTER.add(activeMediators);
}
function activeMediators(view) 
{
viewAdded(view);
}
public function isAdded(view):Bool{
return true;
}

}

class APPViewMediator extends mmvc.impl.Mediator<APPView>
{
function new()
{
super();
}
override function onRegister() 
{
trace(Std.format('i am the mediator of $view and i am registered'));
view.addChild(new CompContainerView());
}
}

///----------------------model----------------------

class MonoModel 
{
public var data:List<Int>;
function new()
{
data=new List();
for (a in 0 ... 10)data.add(a); 
}
}

//-----------------------views----------------------


class CompContainerView extends Sprite
{
public function new()
{
trace("new");
super();
this.addEventListener(Event.ADDED,onAdded);
}
function onAdded(e) 
{
trace("onAdded"+e.target);
APPView.REGISTER.dispatch(this);
this.removeEventListener(Event.ADDED,onAdded);
}
}
class CompContainerViewMediator extends mmvc.impl.Mediator<CompContainerView>
{
function new() 
{
super();
}
override function onRegister() 
{
trace(Std.format('i am the mediator of $view and i am registerd'));
}
}

david quertelet

unread,
Jan 31, 2013, 10:19:19 AM1/31/13
to haxe...@googlegroups.com
from the MMVC doc 

Mediating Views

Mediator instances are created automatically when the IViewContainer (generally an ApplicationView) calls the added handler.

Generally a base view class will handle bubbling of added and removed events from the target platform's display heirachy.

See the examples for a reference implementation.

To manually do this call the handler directly

applicationView.added(viewInstance);

Cambiata

unread,
Jan 31, 2013, 10:26:24 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com
Thanks a lot, David!
That seems to be exactly what I needed!

Cheers!

Jonas


Robin Burrer

unread,
Jan 31, 2013, 10:31:46 AM1/31/13
to haxe...@googlegroups.com, da...@postite.com

> So, obviously this isn't enough to get the DisplayView/DisplayViewMediator going...

That actually should be enough. Once the view is added to the stage/DOM the view-mediator binding should be established. The “on register” method in your mediator should be triggered then….. Your problem must lie somewhere else. I have not tried using MMVC with flash yet….

Axel Huizinga

unread,
Jan 31, 2013, 11:29:25 AM1/31/13
to haxe...@googlegroups.com
Hi,
attempt to build your very welcome example but failed with:

C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:108: characters 18-24 : Warning : This variable is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:138: characters 20-26 : Warning : This variable is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:132: characters 20-23 : Warning : This variable is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:102: lines 102-156 : This pattern is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:104: characters 13-17 : Warning : This variable is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/RTTI.hx:129: characters 16-17 : Warning : This variable is unused
C:\Motion-Twin\Haxe\lib\minject/1,1,0/minject/Injector.hx:43: characters 2-7 : Build failure

is it supposed to work only with -D haxe3? (no success anyway)

Cordially,
Axel

Le jeudi 31 janvier 2013 à 15:56, Cambiata a écrit :

(Sorry, posted unfinished by accident)

I'm adding the DisplayView to the stage in the Main like this:
https://github.com/cambiata/mmvc-simple-clock/blob/master/src/Main.hx#L36

So, obviously this isn't enough to get the DisplayView/DisplayViewMediator going...
Sorry for being slow, but I'm just trying to follow the principles from Robotlegs, as far as I know them.




--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

E-Mail ist virenfrei.
Von AVG überprüft - www.avg.de
Version: 2013.0.2890 / Virendatenbank: 2638/6026 - Ausgabedatum: 11.01.2013
Die Virendatenbank sind veraltet.


Cambiata

unread,
Jan 31, 2013, 11:34:08 AM1/31/13
to haxe...@googlegroups.com
Hi Axel!

I don't think that mmvc supports Haxe 3 yet.
Take a look here: https://groups.google.com/d/msg/haxelang/ZMZhXKjTD0w/09KaADQ_C6AJ

J

Cambiata

unread,
Jan 31, 2013, 4:26:23 PM1/31/13
to haxe...@googlegroups.com
The mmvc-simple-clock example is completely rebuilt and repo is updated.
Added a nice analogue view - have a look if intersted:
https://github.com/cambiata/mmvc-simple-clock

Thank you, Postite, David and Robin!

Cheers!

david quertelet

unread,
Jan 31, 2013, 4:45:10 PM1/31/13
to haxe...@googlegroups.com
glad you have come to your goal !
BTW i'am postite

david
--

Cambiata

unread,
Jan 31, 2013, 4:47:36 PM1/31/13
to haxe...@googlegroups.com, da...@postite.com
BTW i'am postite

Well, you deserve double cred anyway..! :-)
 

david quertelet

unread,
Jan 31, 2013, 4:48:37 PM1/31/13
to haxe...@googlegroups.com
i'm surprised you didn't use external signals and Command 

Cambiata

unread,
Jan 31, 2013, 5:01:40 PM1/31/13
to haxe...@googlegroups.com, da...@postite.com
Thank you for pointing it out!
I realize that the direct addressing of the model isn't very mvc-ish.
I'll have a look at that!

/ J

david quertelet

unread,
Feb 1, 2013, 4:45:02 AM2/1/13
to haxe...@googlegroups.com
hey jonas !
As you seem to try every Haxe mvc Framework on the planet.. ( which is a good initiative )
did you try this port of backbone ? 
--

Cambiata

unread,
Feb 1, 2013, 4:53:37 AM2/1/13
to haxe...@googlegroups.com, da...@postite.com
As you seem to try every Haxe mvc Framework on the planet.. ( which is a good initiative )

Yes, isn't it? Why settle with less? ;-)
 
did you try this port of backbone ? 

No, I haven't. Thank you for pointing it out.


Eric Priou

unread,
Feb 1, 2013, 7:23:49 AM2/1/13
to haxe...@googlegroups.com
Unfortunatly, I didn't found this one before…
haxe lib are really sparsed across multiple sources !

Too bad.
---
Eric Priou aka erixtekila

Axel Huizinga

unread,
Feb 1, 2013, 11:29:59 AM2/1/13
to haxe...@googlegroups.com
Hi,
did anybody build the mmvc-simple-clock example for the html5 target?
On my setup the result looks not really like the swf version
http://paradiseprojects.de/devel/mmvc-simple-clock.jpg

would be glad to get some hints where to fix this.

Cordially,
Axel

Cambiata

unread,
Feb 1, 2013, 2:23:27 PM2/1/13
to haxe...@googlegroups.com
The figures are moved to the right, right?
It's the same when compiling to neko, windows and android.
I guess that it has something to do with text alignment not implemented correctly in nme targets (other than flash).

/ J

Cambiata

unread,
Feb 1, 2013, 2:30:13 PM2/1/13
to haxe...@googlegroups.com
Sorry, moved to the *left*, I can see on the screendump...
Well, it's the same problem.
If you want to address it, check the AnalogClock.createNumbers() and try changing the
align, size and x-position settings...

Axel Huizinga

unread,
Feb 1, 2013, 2:30:35 PM2/1/13
to haxe...@googlegroups.com
yes - and also the circle appears to be clipped.

/ J
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

E-Mail ist virenfrei.


Von AVG überprüft - www.avg.de

Version: 2013.0.2897 / Virendatenbank: 2639/6072 - Ausgabedatum: 31.01.2013


Axel Huizinga

unread,
Feb 1, 2013, 3:03:49 PM2/1/13
to haxe...@googlegroups.com
Since it works well on flash I guess it should be an NME issue on the browser branch.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxelang+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

E-Mail ist virenfrei.


Von AVG überprüft - www.avg.de

Cambiata

unread,
Feb 1, 2013, 3:09:34 PM2/1/13
to haxe...@googlegroups.com
I guess that the clipping stems from a not fully fine-tuned bounds calculation in the nme jeash engine...
To hack around that, add this line in the beginning of the .createClock() method:

        this.clockFace.graphics.drawRect( -this.radius - 4, -this.radius - 4, 10, 10);

It will draw a small rectangle just above the top and just to the left of the circle, thus expanding the bounds so that the circle won't be clipped...


Axel Huizinga

unread,
Feb 1, 2013, 3:24:32 PM2/1/13
to haxe...@googlegroups.com

Am 01.02.2013 21:09, schrieb Cambiata:
I guess that the clipping stems from a not fully fine-tuned bounds calculation in the nme jeash engine...
To hack around that, add this line in the beginning of the .createClock() method:

        this.clockFace.graphics.drawRect( -this.radius - 4, -this.radius - 4, 10, 10);
good inspiration though I hope on the long term someone might solve this or teach me how to do so inside of nme
since there is a general need for fixing the bounding differences between the flash and html5 textfield implementation too.
but for now I will try the same workaround.

It will draw a small rectangle just above the top and just to the left of the circle, thus expanding the bounds so that the circle won't be clipped...


Reply all
Reply to author
Forward
0 new messages