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

Put angular modules in their own files #86

Open
anselmbradford opened this issue Apr 28, 2014 · 4 comments
Open

Put angular modules in their own files #86

anselmbradford opened this issue Apr 28, 2014 · 4 comments

Comments

@anselmbradford
Copy link
Member

Break apart the controllers.js into a controllers directory with controllers/nofications.js and controllers/app.js. Each js file should have one module.

@anselmbradford
Copy link
Member Author

This applies to the models in services.js too.

@lovehandle
Copy link
Contributor

One thing to note is that Angular groups modules by a namespace (see below):

https://github.com/codeforamerica/trails-mobile/blob/master/www/js/application/services.js#L1319

If we put every module in a separate file, we'll either have to make separate angular modules for every controller,directive and service or put make each module group globally available to the window.

That's not terrible, I just wanted to document this for the sake of discussion. One thing we'll need to be sensitive of is avoiding namespace collisions on the module variables.

@anselmbradford
Copy link
Member Author

An option is to use RequireJS to handle module dependencies (as discussed here: http://marcoslin.github.io/angularAMD/#/home), though I'm unclear whether AMD modules are necessarily needed if modules aren't being loaded asynchronously, since Angular has its own module system. Seems it could be as simple as: http://stackoverflow.com/questions/20087627/how-to-create-separate-angularjs-controller-files

@Mr0grog
Copy link
Contributor

Mr0grog commented May 1, 2014

Seems it could be as simple as: http://stackoverflow.com/questions/20087627/how-to-create-separate-angularjs-controller-files

FWIW, that's pretty much how we do it in another Angular project I'm working on. I'm not sure the additional boilerplate for AMD is really worthwhile, as it gets pretty repetitive w/r/t the angular injector syntax. (Also worth noting is that Angular runs module constructors when they are first injected, so the order you concatenate files in mostly doesn't matter—though you do have to make sure module X is declared before you, say, add a controller to it. That controller can still inject something that comes later in the file, though.)

The only other suggestion I'd make is to group files by feature area (e.g. trail data, map stuff, main display+detail display, search) rather than by service/directive/controller. That's a bit larger of a refactor, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants