marionettejs / backbone.marionette

The Backbone Framework
https://marionettejs.com
Other
7.06k stars 1.26k forks source link

Making me feel stupid here... #201

Closed jfrux closed 12 years ago

jfrux commented 12 years ago

What the hell happened form 0.9.3 to 0.9.5... lol... I updated my marionette and my entire app won't run... it seems like everything about Modules changed?

I'm just having a lot of trouble understanding things now :-\

I'm a pretty big nub so I'm sure I wasn't doing something quite right to begin with but still...

mxriverlynn commented 12 years ago

Hi Josh,

Sorry about the troubles. This release went out the door under some very odd circumstances, and a lot of people are having problems like this.

Can you provide a small example of the code you're running, and let me know what's happening or not happening with it? That will help me debug the problem and get a fix out ASAP (hopefully tonight, if you can get the info to me soon).

jfrux commented 12 years ago

Hey, no need to apologize... Yesterday was rough on my head, haha.

Anyway, here is my problems directly after upgrading to 0.9.5 from 0.9.3.

Trying to addRegion from the "dialog" example you had on your blog gives me an error now... https://github.com/JoshuaIRL/uc-ccpd/blob/master/javascripts/app/ui/dialog.js

Uncaught TypeError: undefined is not a function /javascripts/vendor/backbone/backbone.marionette.js:863
_.extend.addRegions /javascripts/vendor/backbone/backbone.marionette.js:863
(anonymous function) dialog.js:29

and I'm getting these: https://github.com/JoshuaIRL/uc-ccpd/blob/master/javascripts/app/activity/credit_requests.js

Uncaught TypeError: Object [object Object] has no method 'load' credit_requests:233
(anonymous function) credit_requests:233

I made a "load" function for each of my objects so that I could call it publicly and according to the documentation if I define "modulename.functionName" that should now be publicly accessible... :(


Also, the new way of defining modules is confusing to me so I'm trying to wrap my head around it... if you define it like:

ce.module("moduleNames",{

});

You can set some properties, and things...? what about initializer?

How do you define public vars this way?

Is this an alternate way of defining a module or is it for configuration stuff only? I guess I'm confused, probably just my basic understanding of javascript that's causing this. :P

mxriverlynn commented 12 years ago

Also, the new way of defining modules is confusing to me so I'm trying to wrap my head around it... if you define it like:

ce.module("moduleNames",{

}); You can set some properties, and things...? what about initializer?

the core module format hasn't changed. You can still define modules as a function. Initializers should now be added to the module and not the application, though.

ce.module("moduleName", function(theMod, ... ){ 

  theMod.addInitializer(function(){
    // init code goes here
  });

});

this way, when you call "start" on either the module directly, or on the app that owns the module, the module will be initialized correctly.


the new option of passing in an object literal only supports 2 things: startWithApp and define.

By default, modules start with the application start method. But you can prevent that by using an object literal to state that a module should not do that:

ce.module("MyMod", {
  startWithApp: false,

  define: function(MyMod, ce, Backbone, Marionette, $, _){
    // module definition goes here
  }
});

No other options are supported for this version, with the object literal.

Note that if you split the module across multiple definitions and do not want the module to start with the app, you have to specify startWithApp: false for all of the module definitions.


the big change that broke your "credit_requests.js" file is that module definitions are now lazy instead of immediate. this means the module you are defining does not have it's definition function run until the module is started.

the way you have things set up, you would have to start the module immediately:

ce.module("mod", function(Mod){

  Mod.region = ...

});

ce.mod.start();

ce.addRegions({
  someRegion: cd.mod.region
});

hope that helps.

i realize that there are some scenarios I never used and never had tests for, which you are doing in your code. i need to review what you are doing again and see what other tests and scenarios should be supported in order to make this easier for what you are trying to do.

jfrux commented 12 years ago

Thanks, this is very helpful.

Yeah, my app is dealing with an identity crisis... it's not a single-page app, it just doesn't make sense to remain 100% single entry point... I just don't feel right about that, or using hash-bang. Ideally... if full blown pushstate isn't supported, I just want page nav's to load the links normally and have every page init separately on it's own... but if loaded via pushstate, I have boot strapper's on the injected markup like

This will init the views and load all my collection / models in... then I should be solid...

My app is designed to have an ADMIN experience and a LEARNER experience. They both share the same primary layout, but certain "sub" layouts get swapped on the server side based on authentication / authority level.

It works as expected without Backbone or Routers if you hit any page url specifically.

I just need to get it bootstrapping properly and I think I'll be ready to actually "code" instead of "setup" :)

jfrux commented 12 years ago

ce.modName.start({ }); How do I reference this...

ce.module("activity",{
    startWithApp:false,
    define:function(self,ce,Backbone,Marionette,$,_) {
        self.addInitializer(function(params) {

It's saying "params is undefined" When I go to access one of the params inside the passed in { object }

mxriverlynn commented 12 years ago

are you still running in to issues with this?