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

HMVC #28

Closed
AlMcKinlay opened this issue Dec 21, 2015 · 5 comments
Closed

HMVC #28

AlMcKinlay opened this issue Dec 21, 2015 · 5 comments

Comments

@AlMcKinlay
Copy link

I was wondering if you guys would be open to supporting an HMVC setup with trails? It's something that I've found has improved my development massively, and currently I'm doing it with my front-end code, but as I'm using sails, I can't use it with my backend code. It would be great if we could get this.

For those unaware, currently the backend is defined like this:

  • api
    • controllers
      • CommentController
      • UserController
    • models
      • Comment
      • User
    • policies
      • loggedIn
    • services
      • CommentService
      • UserService

HMVC is where you could organise it more like this:

  • api
    • User
      • UserController
      • UserModel
      • UserService
      • LoggedInPolicy
    • Comment
      • CommentController
      • CommentModel
      • CommentService

And it means that everything you need for a particular feature is in the folder together.

Ideally, we would also be able to add the routes as individual files into these folders as well, that would be brilliant. I really hope you look to doing this, as it would mean that there was a massive reason for me to use Trails (as I've not found a good node framework that uses hmvc yet).

@tjwebb
Copy link
Member

tjwebb commented Dec 21, 2015

HMVC is where you could organise it more like this:

That sounds like a fine idea; because Trails doesn't dynamically require() things, you can structure the namespace however you want, as long as it ends up in the Trails format below:

app = {
  api: {
    controllers: { ... },
    models: { ... },
    services: { ... }
  },
  config: { ... }
}

In practice, we want to encourage a particular convention. The current design is how Rails and Grails organize their directories, so users coming from those frameworks (or others that are inspired by them, like Sails) are familiar already with where things are.

I see two ways to do this.

1. you can manually setup the require's to load stuff like this. e.g.

// api/index.js
exports.controllers = {
  UserController: require('./User/UserController'),
  CommentController: require('./Comment/CommentController'),
  // etc...
}
exports.models = {
  User: require('./User/UserModel')
  // etc ...
}

You'd probably want to create a modified generator to do this automatically.

2. you could write your own trailpack to translate the object all at once.

@AlMcKinlay
Copy link
Author

Brilliant, I hadn't even noticed the index.js files, that makes things much easier.

Cool, I'm going to have a play around, make a fork of the example, and get that working, and then I'll probably look at getting some yo scripts for it as well. Would there be any interest in these for anyone in the future wanting to do this?

@tjwebb
Copy link
Member

tjwebb commented Dec 21, 2015

@YaManicKill awesome, let me know what you come up with. Yea, I'd be open to merging in a trails:hmvc subgenerator that sets up the hmvc directory structure. Then also you'll want to update the logic that inserts the require statements into the index files when new models/controllers/etc are generated.

@tjwebb
Copy link
Member

tjwebb commented Dec 21, 2015

I think this work can fall entirely under the purview of generator-trails, so @YaManicKill open an issue over there and we can continue discussion there. sound good?

@AlMcKinlay
Copy link
Author

Alrighty, created trailsjs/generator-trails#12. Closing this.

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

2 participants