addyosmani / largescale-demo

Scalable JS architecture demo for #jqcon
138 stars 26 forks source link

Regarding structure... #1

Open panosru opened 12 years ago

panosru commented 12 years ago

I want to mention some things related application structure because I tend to disagree on some topics.

First of all I try to figure out what I'm missing here... is there any reason why you placed facade under sandbox path?

I believe the right way should be to have 2nd facade under sandbox and main facade outside of sandbox the reason behind this is when the application is in production it will load the facade outside of sandbox when the application is in development/testing/integration env it will load the facade inside sandbox which will extend/override the facade outside sandbox. Sandbox facade will work as a temporary container for testing/development purposes once it is tested then the code could move to main facade.

Regarding libs, I believe libs folder should host application's libraries like facade, mediator etc jquery and dojo are 3rd party libs more like vendors and I believe they should be placed in vendors path instead of libs

application_core is a bit missleading, I don't really understand from first glance what exacly is the "core" there that it is "more core" than libs for example or utils, core gives higher priority on that path which is something that I believe shouldn't happen in this case. The files inside that path are more like invokers or wrappers if you want... I believe they should be part of the libs folder, same exist for utils, this too should be part of the libs folder.

currently the structure look like this:

application_core/
  dojo-core.js
  jquery-core.js
libs/
  dojo.js
  jquery.js
modules/
  modules.js
sandbox/
  facade.js
utils/
  utils.js
main.js

The above structure really gives me the feel of "what is where, wha tis the purpose of everything here?". I would propose the following structure as more clean in my personal opinion.

libs/
  facade.js
  invoke-dojo.js
  invoke-jquery.js
  utils.js
modules/
  modules.js
sandbox/
  facade.js
vendors/
  dojo.js
  jquery.js
main.js
panosru commented 12 years ago

Regarind sandbox/facade.js if we say that we will add underscore.js in vendors then sandbox/facade.js would look something like this:

(function(app, _) {
  // sandbox/facade
  _.extend(app.f, {
    // our sandbox facade methods (we could use defaults instead of extend if our
    // business logic does not allow sandbox to override main facade options/methods)
  });
})(app, _);

also if we say that we are very stricted in our code writing we could save some bits from our js files by wirtting instead of (function(app, _) { })(app, _); this: !function(app, _) { }(app, _); which result in the same thing :)

james-gardner commented 12 years ago

Why would the facade be any different between the two? Do you just mean you work on one while the other stays as 'stable' ?

panosru commented 12 years ago

@crungmungus yeap this is exactly what I mean :)