Should i use a controller or do all the work in router?


#1

Hi guys.I am new to ember.I have followed along with 2 tutorials.One uses controller, one doesn’t.

From what i have seen, not using controller looks better, less files, 1 place for common logic.I also heard controllers may be depracaded with the relase of ember 3.0.

So… Is this thinkin right? Or should i use controller no matter what?


#2

The Ember core team started announcing too soon that Ember will have controllers removed and instead introduce routable components “soon” (as early as Ember 1.12), and then due to apparent technical issues they prioritized other projects. Unfortunately, that back-and-forth has caused a great deal of confusion but we need to understand their position.

Controllers are still part of Ember. For now it doesn’t matter if they will be deprecated (curious, where did you hear about Ember 3.0?).

I, personally, rarely use controllers. Not because I hate them but because I find that all of my Ember code fits nicely in other parts of the application. If you’d like to understand why, here is a beginners tutorial that doesn’t use controllers but uses actions in routes instead: https://emberigniter.com/getting-started-ember-cli-data-down-actions-up-tutorial/ . Again, this does not mean that when the app gets more complex you won’t have to use a controller.

The “router” is the place where URL are mapped to routes, so there’s not much work to do there. I think you mean “routes”.


#3

Yeah.Routes file :).So it is okay to define actions, computed properties etc. in routes file.Right?.BTW, about the controller depracation, i have read about it on some guys beginner tutorial.He wasn’t sure.The sentence more or less was like this:“There are some rumors that saying controllers will be depracated with the relase of ember v3.So i will use routes for actions.”.Hope i answered your question right.


#4

Actions in routes yes, computed properties? I don’t think so.


#5

Thank you so much.You have answered both of my questions ^.^But, unfortunately i have to ask 1 more question.Can you suggest any good tutorial for a beginner? (i have done this one http://yoember.com/ <–)


#6

I suggested a tutorial in my first reply.


#7

Thank you for your care and time ^.^


#8

you can just use components moving forward!