by statenjason on 3/6/13, 8:20 PM with 137 comments
by avolcano on 3/6/13, 9:13 PM
As far as I attempted to implement it in my app (https://github.com/thomasboyt/noted-app), it seemed simple enough. Models were data; all they contained was their properties and operations that controlled their properties.
I mainly used controllers as the "state" for parts of my app. In Ember, this doesn't even need to mean it's tied to a specific model type. For example, my Dropbox integration is handled within a controller that's bound to several separate views (in this case, those views included buttons that triggered syncing and modals that displayed the progress of syncing). There's no "Dropbox model," just other models that I'm using this controller to sync. Controllers are not simply an intermediary between models and views, they are an intermediary between state and views.
> I'm trying my best to reconcile this with the notion that a controller (classically speaking) is supposed to ... well control the view. Here, it's not doing that.
I think what the author was looking for in controllers is what's actually handled by, well, views. The view handles any user interaction, and then uses the controller to change the state of various bits (whether calling methods in the controller or simply updating properties on it).
To sum up: model is data, controller is state (including instance(s) of models), and the view is user interaction. Templates can bind to properties on any of these. Routes are what hook these components together depending on the page.
by ef4 on 3/6/13, 9:05 PM
Ember is explicitly not about "desktop apps". That's actually why Ember broke off from Sproutcore. Ember is very opinionatedly focused on building web applications that are native to the web and stick to web conventions.
The best web applications still behave like the web is supposed to behave: they have shareable, bookmarkable URLs that allow the application's state to be recreated. This is a big reason Ember's router is different than the other examples you mentioned -- in Ember the router automatically handles a lot more of the state reconstruction stuff.
by sideproject on 3/6/13, 10:42 PM
I decided to try Emberjs - not for any other reason than trying to pick up something else and see how other JS framework approaches.
I gave full two-days worth of time into it. Initially I thought - "How different can it get?" Plus, I believe even if it's very foreign I'll just keep reading, googling, stackoverflowin', youtube-tutorialin' to get my head around.
I gave up though. Here's my hopefully constructive rant, though my views are probably not as deep as the OP's.
* Many of the posts on the net are outdated. I followed a few tutorials here and there, and then things didn't work, so I asked on Stackoverflow, then the answer I got was "Dude, your code is outdated". Sure this is probably similar thing for other frameworks - but I'm just sayin'
* Models - So there is Ember Object, which you can use as models, but you can also use Ember-data.js which is more "glorified" data. Documentation wasn't clear on the difference. Plus, Ember-data.js was quite hard to get started with. It didn't work well with other versions of Emberjs. I really had to dig in to find the right one to start off with. I ended up cloning a github repo of a tutorial that worked, because nothing else did.
* Documentation on "convention over configuration" - OK, so convention over conf. is fine. But the official documentation and many of the tutorials didn't explain what all the conventions there were. I went through a tutorial app, which only had Controller, but things just "worked", because the Emberjs builds all other things for you. Well I didn't know that! THE BEST INTRO EMBERJS VIDEO I found was this.
It finally made sense in the end for me.
* But in the end, among all other things I wanted to do, I gave up, because the frustration was mounting up. I guess I can still persist through it. But I just finished AngularJS tutorial demo and in 2 hours, it makes sense to me.
by jfarmer on 3/6/13, 8:56 PM
It looks like instead of the controller pushing data to the view, the view asks the controller for data (which it might proxy to the model).
This makes sense with a long-running controller, right? On the web both the controller and view are ephemeral -- they last for just that one request -- but if the controller is running continuously then it needs to reflect changes in the models as they happen. The model(s) the controller references can change without the view changing its reference to the controller.
Without something like this the view would render stale data. I'm assuming this is why we have a controller.model, to add that layer of indirection.
What am I missing? How is this more complicated making the controller<->view relationship pull instead of push?
by pilgrim689 on 3/6/13, 8:51 PM
I'm a bit off-topic, but you don't need to "compromise" your HTML with AngularJS, you can place "data-" in front of your attributes and you're HTML-compliant again :).
by jacquesc on 3/6/13, 8:55 PM
It took me a while as well to figure out why controllers proxied to models. However it started to make a lot of sense in when building an app, since the controllers are there to stay around, and the models are swappable.
Having the option to easily swap out a model at the controller level is worth the extra layer abstraction. That and the ability to add additional UI specific properties on the controller that don't necessarily belong in the model (since they don't need to be persisted).
by tree_of_item on 3/6/13, 9:33 PM
by jondot on 3/7/13, 8:36 AM
One can think of it as Eclipse with its ecosystem.
To build such a system on the Enterprise with its typical NIH (not invented here) paranoid attitude was VERY hard.
I had to reinvent a lot of wheels.
On the Web, I've used backbone for a long time now, since almost the time it was out. I saw the same problems building complex applications with it (that backbone-marionette amends to a great deal). For a larger project, I evaluated Angular. Had very strong negative feelings about it.
Then I tried Ember. It took me a long time to "get" it. The only thing that kept me motivated is knowing that Yehuda, Tom and Trek and other capable people are contributing on it. I kept fighting through the outdated tutorials, the outdated videos, and even the peepcode video was embarrassingly confusing to me at some point.
But then it hit me. Ember and its infrastructure, the way its MVC is rigged, was very similar to what I was building from scratch on the desktop many years ago. It truly IS the one framework that "gets" desktop, or client-side, applications.
The causer of my confusion was that I didn't completely let go of the "Web-think" for building application. I was stuck at either server-side MVC (MVP), or bare-bones frameworks such as Backbone.
It's been just too long out of the real complex desktop game for me, to realize what that I'm looking at is a proper MVC framework.
So for me, Ember ended up as being great - it still takes me back to the way I was building desktop applications, and I'm sure it will become even better and better. To understand it, you need to cold-boot your thoughts into that classic desktop MVC place; and if you were never in it, I think Ember is an excellent way to get into it as opposed to other frameworks.
by tonycoco on 3/6/13, 10:36 PM
Though, I understand the pain of coming from a server-side MVC architecture, I found it refreshing that Ember.js takes the "desktop" MVC approach. Our web apps are now living on the client, acting like desktop apps. Most people struggle with this reverse at first, but can conceptually catch on if shown the way. I think what really needs to happen is a good screencast or two walking through these concepts. I'm interested in putting something together and will when I have the time.
by selvan on 3/7/13, 4:26 AM
Angularjs was easy to pickup and I have completed what I wanted to do in about half a day, except one issue, angularjs template rendering is DOM driven. I wanted server-side templates, hence I have to boot phantomjs at server-side. I didn't quite like booting phantomjs for server-side templates.
Since Emberjs offered, handlebar based templates, I was happy that I could render my templates at server-side. So tried emberjs, it took about 3 days, to get it done. Many out dated tutorials & documents spread across internet about older versions of Emberjs. Documentation at emberjs.com is minimal and not helpful. I started looking at source code of discourse.org and try to understand how they used ember. I felt the power of emberjs when I needed complete control of context and rendering of nested templates. It was real beauty.
by tericho on 3/6/13, 11:41 PM
I switched to Angular (which I also had never used before) and got the same app up and running in a couple days with even more functionality because I was able to hash lots of the trickier "outside-the-box" functionality that I could not for the life of me get working in Ember.
That being said I really like Ember's syntax, Handlebars integration, core values (performance & stability specifically) and have the utmost respect for its creators. I'm hoping since it hit 1.0 that lots of new sample apps, blog posts and SO-type Q&A resources will start showing up and actually stay relevant for more than a month.
by pixelcort on 3/6/13, 9:07 PM
The idea is you can have a commentsController instance, and when you switch to a different post, the view(s) bound to it will automatically pick up the new comments array that is swapped out on behind the controller.
Routing is just rewiring the pointers on your controllers and getting the right views up on the page.
by andreipop on 3/6/13, 10:22 PM
by pradeepin on 3/7/13, 6:27 AM
1)They say it follows MVC. Its actually MVC but MVP, if you look closely at the implementation.
2)Controller job is not precisely defined. Example: Even the data validations are done at controller level not a model level
So i switched to Backbone.js, which is very flexible library with tons of plugins that can be used when needed.
Since implementation of UI is different from requirement to another requirement. I feel EmberJS doesn't satisfy this, which leads to people using Backbone.js.
Regarding AngularJS, please use it only if you are new javascript and prefer learning Angular Javascript (which is not javascript by the way) :)
by melc on 3/7/13, 9:18 AM
I had decided to build the frontend in a js mvc framework and the candidates were backbone, emberjs (pre version), angularjs. Read about them and gave backbone a try, however from the documentation only emberjs approach felt better maybe because of a similar in-house development java framework that we work on. So i tried to give emberjs a try at the same time, due to the tight deadlines. I dropped backbone, and spent more time on emberjs because everything simply worked and fitted together nicely. All these binding mechanisms are great and actually work :) . Haven't tried angularjs.
The system now works with emberjs (pre and rc) with a nice layered architecture and separate independent business logic modules.
My advice is to read the documentation carefully and choose what fits better to your needs and coding styles.
by terbanator on 3/6/13, 9:33 PM
by clintjhill on 3/6/13, 8:54 PM
by ghurlman on 3/6/13, 8:57 PM
text-only: http://webcache.googleusercontent.com/search?q=cache:http://...
by anarchotroll on 3/6/13, 10:04 PM
Potatos, Potahtos.
by pspeter3 on 3/6/13, 8:57 PM
by sudhanshu80 on 3/7/13, 4:26 PM
by Pherdnut on 3/8/13, 4:07 AM
by Tichy on 3/6/13, 9:59 PM
That usage of Controllers is not part of the MVC pattern, I'd say. It's just a recycling of the controller instance - not forbidden, just confusing if you wonder what it has to do with MVC.
Actually it's also the RoR way to have short lived controllers (a controller is instantiated for every request), other frameworks use one static controller instance instead.
by randall on 3/6/13, 9:01 PM
Just a little clarity in the code. Thanks for the writeup!
by stevewilhelm on 3/7/13, 12:33 AM
This may be the issue. I think most of us never really wanted to build web applications, but we were forced to do so due to browser and framework limitations.
We really just wanted to build the best damn desktop app possible that just happened to be deployed in a browser via the Web. This might explain our confusion and disappointment when client side frameworks don't deliver on that desire.
by jhysum on 3/6/13, 9:47 PM
by gosukiwi on 3/6/13, 8:36 PM
by sandstrom on 3/6/13, 10:28 PM
by itsbits on 3/7/13, 8:38 AM
by mark_l_watson on 3/6/13, 9:32 PM
by fcatalan on 3/7/13, 6:15 AM
by devinrhode2 on 3/6/13, 10:05 PM
by nXqd on 3/7/13, 12:31 PM
So no matter which framework we use, we should talk about real world project. Not simple usage that only exists in trying and testing.
Use the framework, you love and you will make it beautiful no matter what :D
by seivan on 3/6/13, 9:32 PM
by newishuser on 3/6/13, 9:46 PM
by gavanwoolery on 3/7/13, 3:37 AM
by richo on 3/7/13, 12:07 AM
I always get confused by this. I don't understand how being nice factors into technical decisions?
(For the record, I also think wycats is nice, but I don't really care when I'm trying to decide whether or not what he's saying makes sense)
by visarga on 3/7/13, 6:29 PM
by nirvanatikku on 3/6/13, 11:59 PM
by ZoFreX on 3/6/13, 8:55 PM
by xmlninja on 3/7/13, 6:29 AM
by BlindRubyCoder on 3/7/13, 2:15 AM