Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: commands not executed when mapped through options object #43

Closed
creynders opened this issue Aug 7, 2014 · 1 comment
Closed

BUG: commands not executed when mapped through options object #43

creynders opened this issue Aug 7, 2014 · 1 comment

Comments

@creynders
Copy link
Contributor

Hi there, it's me again :)

I have the following context class:

module.exports = Backbone.Geppetto.Context.extend( {
    wiring : {
        commands : {
            "app:startup.requested": require('./commands/RegisterHelpers.js')
        }
    },
    initialize : function(){
        this.dispatch('app:startup.requested');
    }
} );

This unfortunately won't run, since a contexts initialize method is run (https://github.com/ModelN/backbone.geppetto/blob/master/backbone.geppetto.js#L190) before the parsing of the wiring object (https://github.com/ModelN/backbone.geppetto/blob/master/backbone.geppetto.js#L198).

It seems we could move the initialize method invocation to the last line, but I'm not entirely sure?

BTW there's quite a few mistakes in the documentation: e.g. 'commands' > 'option2: using the commands map' shows

return Geppetto.Context.extend( {
    commands: {
        "appEventFoo":          FooCommand,
        "appEventBar":          BarCommand,
        "appEventBaz":          BazCommand,
        "appEventFooBarBaz":    [
            FooCommand,
            BarCommand,
            BazCommand
        ]
    }
});

but the commands object should be wrapped in a wiring object.

Also in 'Setting up wiring in the context' the example is:

return Geppetto.Context.extend( {
    initialize: function () {
        wiring: {
            singletons: {
                "userModel": Backbone.Model,
                "productModel": ProductModel,
                "loggingSvc": LoggingSvc
            },
            views: {
                "UserView": UserView,
                "ProductView": ProductView
            }
        }
    }
});

but the wiring object should be moved to outside the initialize function.

Sorry if I am to blame, my memory's so terrible I can't remember whether this is stuff I wrote or not?

@geekdave
Copy link
Contributor

geekdave commented Aug 8, 2014

Ah yeah, I never hit this myself because I always use "pseudo-constants" for my event names, which don't work in object maps. So I always wire my commands programmatically using wireCommand() in the initialize method.

At first glance, I think it would be totally fine to move initialize to run before _configureWirings... but I haven't tested it. I'd be open to a PR if it would solve your problem, and you can verify that it works.

As for the docs, yeah they're still in bad shape. Feel free to sneak in any doc fixes into unrelated PRs.

creynders added a commit to creynders/backbone.geppetto that referenced this issue Aug 12, 2014
mmikeyy pushed a commit to mmikeyy/backbone.geppetto that referenced this issue Sep 25, 2014
mmikeyy pushed a commit to mmikeyy/backbone.geppetto that referenced this issue Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants