Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 08 16:03
    davidgiven opened #312
  • Feb 26 08:49
    desca595 removed as member
  • Jan 15 09:58
    CrazyFlasher synchronize #80
  • Jan 15 09:23
    CrazyFlasher commented #311
  • Jan 15 09:17
    CrazyFlasher opened #80
  • Jan 15 08:43
    CrazyFlasher commented #311
  • Jan 15 08:43
    CrazyFlasher commented #311
  • Jan 15 08:26
    CrazyFlasher commented #311
  • Jan 14 08:30
    CrazyFlasher edited #311
  • Jan 14 08:30
    CrazyFlasher opened #311
  • Oct 23 2019 16:33
    CrazyFlasher commented #310
  • Oct 23 2019 16:31
    CrazyFlasher commented #310
  • Oct 23 2019 16:30
    CrazyFlasher commented #310
  • Oct 23 2019 16:30
    CrazyFlasher commented #310
  • Oct 23 2019 13:15
    st3veV commented #310
  • Oct 23 2019 13:00
    CrazyFlasher opened #310
  • Oct 21 2019 20:08
    CrazyFlasher edited #309
  • Oct 21 2019 20:07
    CrazyFlasher opened #309
  • Oct 21 2019 10:42
    back2dos reopened #308
  • Oct 21 2019 10:42
    back2dos commented #308
Laurent Deketelaere
@aliokan
the both are possible, but I prefer the first one.
Laurent Deketelaere
@aliokan
You have a lot of XML examples in UnitTest : https://github.com/DoclerLabs/hexIoC/tree/master/test/context
Laurent Deketelaere
@aliokan
Be carefull, hexMachina has 2 engines to compile XML : hex.compiler.parser.xml.XmlCompiler (original) and the new one hex.compiler.parser.xml.StaticXmlCompiler
MIchael Solomon
@mikicho
hm.. Thanks... I'll look on those references...
My goal now is to create reusable login/signup module... just to get dirty with hexMachine and let the questions to float.
from my understanding I should have view, that sends signup/login to the model via controller(mvc), then the module should use a service (the service call to google/facebook/github etc) and send the response back to the view.
MIchael Solomon
@mikicho

Hey guys,
I started with my Multiple Login module with hexMachina (simple buttons that use google/facebook/githubt/etc js api for quick login).
From my understanding I should have service for each login method that use the native js API via externs, I'm little confuse if I need services here, because I'm using in the native js library. for example this is "all" code needed for google login:

GoogleAPI.load("auth2", function() {
            var googleAuth:GoogleAuth = GoogleAPI.auth2.init({
                client_id: "336663289135-huvf4gfmgj7sqf6knb1i13iuam5le8fq.apps.googleusercontent.com"
            });

            googleAuth.attachClickHandler("js-google-login", {}, 
                function(googleUser:GoogleUser) {
                    trace(googleUser);
                    js.Browser.document.getElementById("js-sign-in").textContent = googleUser.getBasicProfile().getName() + " signed in with Google";
                    js.Browser.document.getElementById("js-disconnect").onclick = googleAuth.disconnect;
                },
                function(error:Error) {
                    trace(error);
                    js.Browser.document.getElementById("js-error").textContent = "Error: " + error.error;
                });
});

And in general... How do you think I should build this module?

Laurent Deketelaere
@aliokan
Hello :)
Service is a good way to manage that. HexMachina services are like wrappers to manage exchange with outside, like native js API calls. In your case, hex.service.stateless.AsyncStatelessService should be the best choice. But you can also directly use hex.control.async .AsynCommand, as a light-way solution. ;)
MIchael Solomon
@mikicho

@aliokan Thanks! this is a project to learn hexMachina.. so I chose the "hard" way, I'm not fully understanding how my service come to action. this is how I see it:

  1. in view I should assign attachClickHandler function(above) to my button(js-google-login)
  2. user click on "Google login" button and redirct to google for authentication.
  3. the data return to the view to the succes/error function (look code above) and send(how??) the data to the AsyncStatelessService for parsing and further opreations.

here I'm stuck... I didn't exectue any command here (because I'm using the native API). little confuseing

MIchael Solomon
@mikicho

hey,
I want thats onclick the module will dispatch an event. how I should to that? tried this but get loginModule is undefined
View:

@:Inject
    var loginModule:LoginModule;

    public function new( layout : Element ) 
    {
        super();
        trace(loginModule);
        layout.onclick = function (e:js.html.MouseEvent) {
            loginModule.dispatchPublicMessage(LoginModuleMessages.GOOGLE_LOGIN);
        };
        //js.Browser.document.getElementById("js-error").textContent = "Error: " + error.error;
    }

LoginModule:

public function new( serviceConfig : IStatefulConfig, view : ILoginView ) 
    {
        super();

        this.getLogger().info( "LoginModule initialized" );

        this._addStatefulConfigs( [ serviceConfig ] );
        this._addStatelessConfigClasses( [ LoginCommandConfig, LoginModelConfig ] );
        this.buildViewHelper( LoginViewHelper, view);

        this._injector.mapToValue(ILoginView, view);
        this._injector.injectInto(view);
    }
MIchael Solomon
@mikicho
What I'm asking is how the view should talk with the rest oh the application?
MIchael Solomon
@mikicho

I saw this in the end of article:

  1. The user triggers with his mouse a native HTMLEvent.CLICK on the image UI (in our case let’s assume he clicks on the image).
  2. We catch this natvie event in our GalleryView and forward this information as an abstract ImageViewMessage.CLICK (that we implemented, so it’s independent from the platform that we use).
  3. The GalleryViewHelper catch this message and forward as a business request GalleryMessage.LOAD_IMAGE to the privateDispatcher.

How I should to send ImageViewMessage.CLICK? and how catch it in my ViewHelper?

io:r//us
@oxitech239
hi People, new to Haxe and HexMachina, is HM suitable to write simple websites and webservices of is it overkill to that matter ?
MIchael Solomon
@mikicho
Anyone can help me with my last question? (How I should to send ImageViewMessage.CLICK? and how catch it in my ViewHelper) please
MIchael Solomon
@mikicho
hex.di.mapping.MappingConfiguration isn't should be MappingStatefulConfiguration
MIchael Solomon
@mikicho
2 views can have same ViewHelper?
In module:
this.buildViewHelper(LoginViewHelper, favebookView);
this.buildViewHelper(LoginViewHelper, googleView);
St3veV
@st3veV
hey... sorry for coming back so late
MIchael Solomon
@mikicho
First, thanks! and it's ok... in first it was frustrating that no one help. but it's makes me to go deeply into the lib :)
St3veV
@st3veV
so first to your first question about the events and listeners... basically you can deal with events in multiple different ways and hexMachina supports a couple of them... first there is the dispatchPublicMessage which is a native to a Module class but you can just use a dispatcher in your view and let a view helper (or mediator in Robotlegs terminology) listen to it... there are many people who love this idea but I prefer another way and that's "triggers"... the advantege of using triggers is that they are strongly typed, super lightweight, extremely simple to use and HM generates all the boilerplate for you so you don't have to worry about anything... also they're part of the core so they're always available... you can look at some examples of use in this test: https://github.com/DoclerLabs/hexCore/blob/master/test/hex/event/TriggerTest.hx
I'm pretty sure now you're quite confused about why the hell I'm bringing up triggers when the article talks about events
In the end they're pretty much the same thing - a way to observe a behavior of an object which is exactly what you want to do - your view can expos a trigger as a part of its interface and your view helper (or sometimes directly a controller) can just connect to it and act based on what and how things are happening
St3veV
@st3veV
and that brings me to the other question... yes, two views can have same view helper class if they implement same interface (or dispatch same events if you want to use them)
MIchael Solomon
@mikicho
I'm feeling like a man in a desert that just get a bottle of water 0_0
Until I grasp the triggers, this is also valid? (in module)
how I want that one view will lead to google login and one to facebook, but they override each other
this._map(ILoginService, services.google.Login);
this._map(ILoginService, services.facebook.Login);
St3veV
@st3veV
yeah, as you said, these are going to override each other because mappings are only 1:1... for those cases there are "named mappings" - it's the last parameter which is optional... so you can do:
this._map(ILoginService, services.google.Login, "google");
this._map(ILoginService, services.facebook.Login, "facebook");
MIchael Solomon
@mikicho
Yeah, I saw that, but than I got weird error at runtime
uncaught exception: Error: hex.module.dependency.RuntimeDependencyException at hex.module.dependency.RuntimeDependencyChecker#check line:30 in file 'RuntimeDependencyChecker.hx' | '{
type : {
name : [modules,login,services,ILoginService]
}
}' dependency is not available during 'modules.login.LoginModule' initialisation.
St3veV
@st3veV
yes, that's quite expected because you have to define your dependency with the name as well
MIchael Solomon
@mikicho

what I'm missing?

var rd = new RuntimeDependencies();
rd.addMappedDependencies([{type: ILoginService}]);

I saw that is hex.di.mapping.Mapping object and tried to add names too but get other weird error :O

rd.addMappedDependencies([
    {type: ILoginService, name:"google"},
    {type: ILoginService, name:"facebook"}
]);
uncaught exception: Error: hex.di.error.MissingMappingException at hex.di.reflect.InjectionUtil#applyPropertyInjection line:60 in file 'InjectionUtil.hx' | 'hex.di.Injector' is missing a mapping to inject into property named 'loginService' with type 'modules.login.services.ILoginService' inside instance of 'modules.login.controllers.LoginCommand'. Target dependency: 'modules.login.services.ILoginService|'
St3veV
@st3veV
basically once you define a mapping with a name you'll always have to specify it because otherwise the injector doesn't know what exactly you need... in the end injector is just a glorified map which contains names of mappings and instances (well it's a bit more complicated than that but in a nutshell that's what it is)... the name of the mapping is my.pack.Foo|[name] where name is whatever name you specify (if you don't specify nothing it defaults to empty string)... so for the injector there is a big difference when you ask for ILoginService| and ILoginService|facebook
so in your command you have to inject it with the name as well:
@Inject("facebook")
public var loginService:ILoginService;
St3veV
@st3veV
OR because the injector is dealing with runtime instances, you can actually remap things during runtime so you can have a command that takes a facebook service and maps it to the generic/noname/emptystring (not sure how to call that but I hope you get the idea) name and your command can then inject it without caring what service it's communicating with and when youre done with macro execution you can then unmap your service from the generic name
MIchael Solomon
@mikicho

Hmm.. interesting! but than it means I have different vars for each login method in my command...
I tried to "cheat" on it with typedef:

typedef IGoogleLoginService = ILoginService;
typedef IFacebookLoginService = ILoginService;

and then:

this._map(IGoogleLoginService, services.google.Login); 
this._map(IFacebookLoginService, services.facebook.Login);

But with no success

oh... didn't see your second msg...
MIchael Solomon
@mikicho
I think I understand! also your help put lot of light on the "mapping" thing.
gonna try it :)
Thank you soooo much!
St3veV
@st3veV
well of course ideally you have just one variable and only one login service... basically the best way would be to have two login modules... because that's what you're trying to do... I assume the implementation differs only in the service and a view... so you can have a general purpose login module with all the wiring which depends on two things - ILoginSevice and ILoginView... everything within the module doesn't know what it's dealing with and you construct those two things outside of the module and pass them in (for example in the constructor of the module)... when you'll have two modules living side by side and dealing with login and one of them will fire event/trigger that user has logged in... this way you can easily scale the whole thing horizontally just by adding views and services and the whole login problematic would be encapsulated inside one isolated general purpose module
no problem at all :)
St3veV
@st3veV
injector really isn't that complicated thing but for some reason many people think about it as some kind of magic... really, think about it as a map of names and instances... but generally I'd discourage remapping things at runtime because you can very easily shoot yourself in the leg if you're not carefully keeping track on what's mapped to what... that's why I'd suggest the second thing I wrote... single responsibility module which communicates only through interfaces and the dependencies are not instantiated within the module but outside of it
MIchael Solomon
@mikicho
Read twice to fully understand and I see what you mean...
Just to be sure you recommend one module that contains the command, viewHelper and the model and one module (or more) that contains the service and view?
Sounds better, but where I should "pass them in"?
Anyway I going try to do that...
St3veV
@st3veV
well you construct your module somewhere, don't you? I guess you're not using DSL configuration yet so somewhere you're doing new LoginModule()... and at that place you construct your view and service and do new LoginModule(facebookView, facebookService); and the same thing with google... so you'll end up with two instances of login module which work independently on each other... and eventually one of them will dispatch/trigger and event which will say that user is logged in and at that point you have what you need (the logged in user details) and you can safely destroy both of the modules as you don't need them anymore... the main point is that your login module will never know what login method it's actually using (and it doesn't really care)... so later if you then want to add for example twitter login, you just implement your twitter service and view, make another instance of your module and you're all set up... you can have this whole thing encapsulated in another module or it can be just part of your configuration - eventually you have to somewhere specify what login methods are going to be used
MIchael Solomon
@mikicho
Thank you! I think I understand, I'm trying now to implement this :) (and switch/give a chance to triggers too)
Laurent Deketelaere
@aliokan
You have an example of trigger usage in https://github.com/doclerlabs/hexTodoMVC
MIchael Solomon
@mikicho
Thanks! so this project before, didn't notice it using triggers
MIchael Solomon
@mikicho
Hey,
I moved to Triggers and after you get the point it's really more continence than events...
Now I'm not sure how I should to forward the click event from the view(UI) to my service, previously I used command but in the todoMVC example I see using in simple controller...
what the different between command and controller? when I should using command?
MIchael Solomon
@mikicho
@st3veV What I don't understand in your method (of two modules, one "controller" module and one module for the services and views) is why I need modules for services and views(without model)? they live outside the modules isn't? (inside the modules you have only the Interfaces)
and I'm using DSL because all the guides/examples are with it. maybe this is the reason I have some difficult to see the whole picture...