GithubHelp home page GithubHelp logo

massive-oss / mmvc Goto Github PK

View Code? Open in Web Editor NEW
101.0 101.0 24.0 957 KB

A Haxe port of the ActionScript 3 RobotLegs MVC framework with signals and Haxe refinements. Supports AVM1, AVM2, JavaScript, Neko and C++.

Home Page: open.massiveinteractive.com

License: Other

Haxe 99.74% CSS 0.16% HTML 0.10%

mmvc's People

Contributors

andrewvernon avatar dpeek avatar elsassph avatar jozefchutka avatar justsee avatar martin-parshorov avatar martinmay avatar mczolko avatar mikestead avatar misprintt avatar pixelami avatar tomashubelbauer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mmvc's Issues

commands triggered by anything not just signals

We hit some major issues when using signals for triggering commands. Because signals are singletons and so its hard to maintain response in case the signal.dispatch is executed in loop, not to mention unnecessary memory footprint of having a custom signal for each command...

The solution is rather very simple. It uses TriggerMap to map any trigger (class) to any command. Each command can be dispatched with a specific instance of trigger so its much easier to handle related "response", and much more easier to obtain trigger instance/value in command:

package mmvc.impl;

import haxe.ds.StringMap;

import mmvc.api.ICommand;
import mmvc.impl.Actor;

class TriggerMap extends Actor
{
    var map:StringMap<Class<ICommand>>;

    public function new()
    {
        map = new StringMap<Class<ICommand>>();

        super();
    }

    public function dispatch(trigger:Dynamic)
    {
        var triggerClass = Type.getClass(trigger);
        var triggerClassName = Type.getClassName(triggerClass);
        if(!map.exists(triggerClassName))
            throw "Command for trigger " + triggerClassName + " is not defined.";

        injector.mapValue(triggerClass, trigger, "trigger");
        var command = injector.instantiate(map.get(triggerClassName));
        injector.unmap(triggerClass, "trigger");

        command.execute();
    }

    public function mapCommand(trigger:Class<Dynamic>, command:Class<ICommand>)
    {
        var triggerClassName = Type.getClassName(trigger);
        if(map.exists(triggerClassName))
            throw "Command for trigger " + triggerClassName + " is already defined.";

        map.set(triggerClassName, command);
    }

    public function unmapCommand(trigger:Class<Dynamic>)
    {
        var triggerClassName = Type.getClassName(trigger);
        map.remove(triggerClassName);
    }
}

The Command implementation in this case needs to be tweaked and Signal injection removed:

package mmvc.impl;

import minject.Injector;

import mmvc.api.ICommand;
import mmvc.api.ICommandMap;
import mmvc.api.IMediatorMap;
import mmvc.api.IViewContainer;

class Command implements ICommand
{
    @inject public var contextView:IViewContainer;
    @inject public var commandMap:ICommandMap;
    @inject public var injector:Injector;
    @inject public var mediatorMap:IMediatorMap;

    public function new():Void{}
    public function execute(){}
}

and finally the usage. Lets map some commands in context:

injector.mapSingleton(TriggerMap);
var triggerMap:TriggerMap = injector.getInstance(TriggerMap);

triggerMap.mapCommand(String, StringCommand);
triggerMap.mapCommand(Int, IntCommand);
triggerMap.mapCommand(MyVO, VOCommand);

triggering in mediator:

class MyMediator extends Mediator
{
    @inject public var triggerMap:TriggerMap;
    override function onRegister()
    {
        triggerMap.dispatch("hello world");
    }
}
class StringCommand extends Command
{
    @inject("trigger") public var trigger:String;

    override function execute()
    {
        trace("StringCommand executed = " + trigger);
    }
}

class IntCommand extends Command
{
    @inject("trigger") public var trigger:Int;

    override function execute()
    {
        trace("StringCommand executed = " + trigger);
    }
}

class VOCommand extends Command
{
    @inject("trigger") public var trigger:MyVO;

    override function execute()
    {
        trace("StringCommand executed = " + Std.string(trigger));
    }
}

this approach lets you implement triggerMap on project level but if we decide to implement it on mmvc level that would be even more awesome

Trying to compile sample with Haxe 3, failing

โžœ example git:(master) haxe build.hxml
/usr/lib/haxe/lib/minject/1,2,3/mcore/exception/Exception.hx:130: characters 9-15 : Identifier 'Lambda' is not part of enum haxe.StackItem
/usr/lib/haxe/lib/minject/1,2,3/mcore/exception/Exception.hx:130: characters 9-18 : Expected constructor for enum haxe.StackItem

Any ideas?

View mappings fail on Context.startup if IContextView mapped before other views

By default, the MediatorMap auto instantiates the IContextView mediator (ApplicationView) during startup.

Any viewMaps defined after the ApplicationView will not be available until after the ApplicationViewMediator is instantiated. This causes problems if sub views are instantiated during the ApplicationViewMediator.onRegister lifecycle. Their mappings will not be defined yet

Solution may require an explicit initialization call at the end of the startup method to check/trigger any IContextView mappings

E.g.

class ApplicationContext extends mmvc.impl.Context
{
    public function new(?contextView:IViewContainer=null)
    {
        super(contextView);
    }

    override public function startup():Void
    {
        injector.mapSingleton(example.Model);
        mediatorMap.mapView(ApplicationView, ApplicationViewMediator);

        //mappings below are currently not available until after ApplicationViewMediator.onRegister is executed
        mediatorMap.mapView(bexample.SomeView, example.SomeViewMediator);

        initialize();//new method to explicitly trigger IContextView mappings
    }
}

Signal2 injecting fails when same type

Hello,
I noticed signal2 injection in commands are failing when payloads are the same type.

Var echo Signal2<String,String>
echo.dispatch("pip","pop");

in command

Class MyCommand extends Command{

@Inject public var echoarg1:String;
@Inject public var echoarg2:String;

Public function execute(){
trace ("command activated" +echoarg1 +"__"+echoarg2);

}

}

And using typedefs in order to differanciate types doesn't do the trick
is it a normal behaviour ?
Thx

Error compiling Example

Hello,

Got this error when trying to compile supplied example :
src/example/todo/command/LoadTodoListCommand.hx:46: characters 8-32 : Redefinition of variable signal in subclass is not allowed
src/example/todo/command/LoadTodoListCommand.hx:95: characters 2-24 : msignal.AnySignal has no field failed
src/example/todo/command/LoadTodoListCommand.hx:85: characters 2-27 : msignal.AnySignal has no field completed

I have Haxe2.1 installed, and a fresh "haxelib install mmvc", and i'm on windows7 commandline

Signal2 Command Mapping Problem

Hello,

Not quite the place to commend you on a fantastic framework, but: what a fantastic framework! Thank you.

Okay, the issue I have is with Haxe 3 targetting a JavaScript target, and manifests itself as follows:

I'm having problems mapping a Signal2 to a Command, which I think might be a bug.

The Signal2 is declared as follows:

public static var showImageViewer = new Signal2(Bool, Int);

This is mapped to a command in the context as follows:

    commandMap.mapSignal(CommandSignals.showImageViewer,
        ShowImageViewerCommand);

The command declares two field for the incoming signal parameters as follows:

@inject public var currentImageIndex:Int;
@inject public var show:Bool;

However, at runtime, triggering the signal as follows:

    CommandSignals.showImageViewer.dispatch(true, imageIndex);

...causes JavaScript to be created that results in the following browser error:

Uncaught TypeError: Cannot call method 'join' of undefined

The error appears to be occurring in JavaScript which looks as follows:

Type.getClassName = function(c) {
var a = c.name;
return a.join(".");
}

I think the mapping mechanism might be having problems with this combination of types for the signal parameters. It's solved if I replace this combo with a wrapper type. All the other signal mappings I've created work - they are Signal0s and Signal1s though.

Any ideas?

Many thanks,

Nick

Mapping mediator by qualified class name (string) fails

API indicates that mediatorMap can be set up with a qualified class name String instead of class reference, indeed it is allowed in the context definition:

mediatorMap.mapView('example.todo.view.TodoListView', TodoListViewMediator);

However it fails at runtime because the mediatorMap attempts to temporarily add the register the view class in the injector.

Example code is not haxe 3 ready

Hi
The example is not compiling with haxe 3.
Those files need to be updated: ApplicationView.hx, View.hx, TodoStatsView.hx, TodoView.hx, HTTPLoader.hx

Updates needed:

  • implements comma removal
  • js.Dom => js.html.Element
  • js.Lib => js.Browser
  • js.Event => js.html.Event
  • HtmlDom => Element
  • Hash => Map

Thanks
Regards,
Seb

Inject Components into each other

Injecting components into each other causes the app to crash.

e.g.

class Test1
{
@Inject public var testCom : Test2;
public function new()
{

}

}

class Test2
{
@Inject public var testCom : Test1;
public function new()
{

}

}

class testApp extends CoreContext
{
@Inject public var testCom : Test1;

public function new() 
{
    super();
            mapSingleton( Test1 );
    mapSingleton( Test2 );
            coreInjector.injectInto(this);
}

}

Example does not run in release mod for flash target

Hi,
The example is not running in release mod for flash target. I get only grey screen.
At least with haxe 3 updates, dont know about current version.

I found out that its because of Console initialization that sets the scale mod that is not done in release.

Solution i used is to add this line in initialize function of ApplicationView.hx
flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;

Thanks
Regards,
Seb

injectViewAs not working on CPP

Line 85 of the MediatorMap class (in v1.6.1) is:
if (injectViewAs)

To work in CPP it needs to be:
if (injectViewAs!=null)

I'm assuming this problem will exist in other mapping methods that take an alias class/interface.

dce break

i have this runtime error in js wwhen using dce full

Uncaught TypeError: Cannot read property 'nonEmpty' of undefined Signal.hx:150
msignal.Signal.registrationPossible Signal.hx:150
msignal.Signal.registerListener Signal.hx:135
msignal.Signal.add Signal.hx:65
mmvc.base.CommandMap.mapSignal CommandMap.hx:78
mmvc.base.CommandMap.mapSignalClass CommandMap.hx:50
amibe.app.AppContext.$extend.startup AppContext.hx:34
mmvc.impl.Context.checkAutoStartup Context.hx:220
mmvc.impl.Context.set_contextView Context.hx:128
mmvc.impl.Context Context.hx:104
amibe.app.AppContext AppContext.hx:15
(anonymous function)

i tried to mark all my classes with @:keep .. but no luck .. i know msignal works well usually with dce.
the problem occurs with commandmapping in Appcontext

Which version of mmvc is compatible with minject 2.0?

I am having trouble compiling my project due to missing classes in minject which mmvc depends on.

/usr/local/lib/haxe/lib/mmvc/1,6,3/mmvc/base/CommandMap.hx:27: characters 8-24 : Type not found : minject.ClassMap

enum & typedef in signals

hello ..
i use mmvc a lot these times.
i love it but i i'd really like to be able to pass typedefs and enums in signals.
i do understand that thoses types cannot be instanciated ( by minject i guess ).
but having to make wrappers for typedefs and converting enums to string is not very elegant nor practical.

is it a limitation of signals , minject ? or mmvc .
thx

Type not found : minject.ClassMap

I tried to build my app, and I get this error:

/usr/local/lib/haxe/lib/mmvc/1,6,3/mmvc/base/CommandMap.hx:27: characters 8-24 : Type not found : minject.ClassMap

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.