Advice On & Instruction in The Use of Ember.js
trek.github.com
trek.github.com
The page is basically unreadable in FF 7.0.1 on RHEL 5.3. I realize light grey on white with a really thin font is dead sexy on your Mac (probably looks great on my home computer as well) but it's useless to me at work.
I normally hate comments that simply criticize something not related to the content of the article, but in this case I found the lack of contrast made the article basically unreadable (on a MBP, using either the internal screen or a nice external display).
It is true as the author mentions that it doesn't aim to fix the UI/statefullness issue, but I slapped on Backbone Routing on to my knockout code and it made capturing 'state' and urls a breeze.
The last time I used ember was 0.9.6 and I don't think this routing stuff was even in it so I was excited to see talk about it. Unfortunately it looks to be even more complicated then I expected it to. :(
Knockout may be creating some massive memory footprint in the background that will bite me down the line, but I'm writing significantly less code than I was with Ember. For example, In ember you have to create view objects and if you want your view objects to sync data with your controller you have to explicitly define them:
App.userController = Ember.Object.create({
content: Ember.Object.create({
firstName: "Albert",
lastName: "Hofmann",
posts: 25,
hobbies: "Riding bicycles"
})
});App.UserView = Ember.View.extend({
templateName: 'user',
firstNameBinding: 'App.userController.content.firstName',
lastNameBinding: 'App.userController.content.lastName'
});Now I get to do my handlebars template <script>
<div>{{firstName}}</div>
</script>
In knockout just have to do: App.UserController = {
content = ko.observable(new content());
}
ko.applyBindings(App.UserController);
And now I get to do a knockout template inline with my html:
<div data-bind="text: content.firstName"></div>
It just seems like there are fewer steps with knockout and I'm getting more done. The html is a lot uglier, but it also clearer what is going on when I read it.
The ember guys have come a long way on their doc and they should be commended on it. I like the patterns they are talking about I'm just not sold that it has to be done the way they are doing it. Thanks to the author for putting together such an in depth post to me in the right direction in getting back into Ember.
App.UserView = Ember.View.extend({
templateName: 'user',
});
View: <script>
<div>{{user.firstName}}</div>
</script>
No need for the intermediate bindings. Effectively this is what you're doing in Knockout with the "content." prefixOnce my app grew complex, Knockout grew increasingly hard to reason about how it's view updating was working. It also grew slow.
Also, Knockout lacks any legitimate data laye (knockout-mapping isn't a data layer). Ember has ember-data.
No matter what framework you are using, if you are solving the problems that we are solving, you are going to end up with that code.
Now, that said, I agree that learning all of the frameworks out there is advantageous, but you can't assume that the code in the blog post is indicative of anything having to do with Backbone or any other framework.
One area where backbone is lacking is lifecycle management. You do sometimes have to unbind things in order to prevent leaks. Backbone is very minimal in this regard. At Rdio, we've built our own tools on top of Backbone to abstract lifecycle away from the developer as much as possible. That being said, that weakness isn't illustrated in the code example picked by the blog post.
It's an "all or nothing"-solution. I couldn't care less about Stateful Single-Page Applications. I'll take a stateless, curlable, crawlable (remember Google?), old-style web site any time. Of course, some parts might require more dynamicness than other, and in that case it's lovely to jump to client side MVC. But it doesn't seem that Ember.js wants to play this game. Every time I look at Ember it seems that it wants to define the architecture of my application. Thank you very much, I like my stateless-ness very much!
See the `rootElement` property of `Ember.Application`: http://docs.emberjs.com/#doc=Ember.Application&src=false
I take it that all of your applications involve public content with minimal if any enhancements to logged in users?
I am aware of that most the issues with single-page applications comes from the applications themselves, not the architecture (i.e. is the developers', not the technology's fault) but there seems to be quite a lot of complexity with this architecture. I've seen very few applications that handles all of these issues.
Also, an Ember app could be designed to function seamlessly with an intermittent connection where a normal website would just be unavailable. Also, many pages will just continue to function without doing any extra work, provided the user doesn't post to the server until the connection comes back.
> No silly "double loading";
What does double-loading mean?
> easy to bookmark; links I can Cmd-Tab;
The primary goal of the Ember router is to provide this functionality out of the box. The reason you get a single callback with an object regardless of how you arrived at a given state to is to ensure that entering through the router (cmd-tab, bookmark) is the same as transitioning in the app.
If you use the router with the Ember `{{action}}` helper, there isn't really any way to have URLs that don't have the features you desire.
> the page doesn't magically fail when my internet connection is broken.
I don't know exactly what this means. Surely when your internet connection is broken, regular "stateless" pages don't work either?
Are you just saying that there are fewer problem states as an end user? Either the page loaded or it didn't? I've personally had a ton of issues with Facebook Ajax requests failing when I'm in a flaky connection scenario resulting in a generally unusable page.
Can you elaborate on what you mean here?
Basically, a web app that is usable (or at least readable) before all your JavaScript initialization is done. With Facebook, as soon as the HTML and CSS hits your browser it can render a more or less complete page. With Ember.js, that doesn't happen until the application is initialized and all your templates are rendered.
[1] http://www.kaspertidemann.com/how-to-make-ember-js-use-histo...
Also, it's trivial to have some pieces of your app rendered by rails or whatever you're using server side.
We're using Ember to build the next generation of our product (a web app) and it has been an extremely pleasurable experience.
Ember really changes JS development in ways that the other frameworks don't even attempt. And in a way this hurts it in the perception of developers, since it more often than not is just tagged as "too complicated" or "too much to learn".
The more great articles like this, and I think there'll be a solid chance Ember catches on in a big way the same way Rails did. With 1.0rc, the tech seems to be solid enough now and it just needs a push on the other stuff (education, marketing, etc). And most importantly: some more successful Ember apps out in the wild (I'm working on that one).
So yeah. Ember's problem is convincing people there's a problem (hint: there definitely is).
That's because we're not writing good reusable views. We're writing one-off views that corresponding to the current needs of the current application we're working on. Here's a good view: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/...
It was created 5 years ago and I'm pretty sure it's got a lot of life left in it still.
[1]: https://github.com/documentcloud/backbone/commit/3ae1af6df1b...
Also, I think single page apps have a place as part of a greater architecture, but not as the entire app. If I wanted an entire app everything to be JS, fine, use Ember or something like it, but most parts of the web don't need this and single page apps make the web a bit worse if not done correctly.
Single page apps are the new hotness, but once the fad is over and the newness wears off, they'll be fit into their proper place over time and won't take over the entire app.
I'd appreciate it if you could quantify what you mean exactly by "magic". For example, one key difference between Ember and Knockout is that Ember's binding system automatically avoids triggering the same side-effect from multiple pieces of code.
For example, if you had a piece of the DOM that was calculated from several observables (the stupid example is a full name calculated from a salutation, first name and last name), and made changes to all three of those in separate lines of code (possibly in different areas of your codebase), Ember would ensure that the DOM only updated a single time, not three times. This is true no matter where the three lines of code are, without you needing to take any special action to coalesce the changes.
This aspect of Ember's codebase adds some magic, in that it introduces a higher-level abstraction that knows about computed properties and their side-effects (the "run loop"), but the end result is more predictable propagation of side-effects in an Ember application. Ember applications don't need to know about the specific mechanism that makes this work, but good Ember developers are aware that many side-effects happen asynchronously in an Ember application.
The browser does something similar when you make changes to DOM structures: it only updates the rendered version of the DOM once all of the JavaScript code handling an event has completed.
I would agree that something simpler would probably be a better fit for simple "islands of richness" on an existing application, but there are definitely a large number of applications with significant amounts of logic happening on the client side, even if those applications run inside of an area of a larger traditional page.
In general, I would say that Ember is a good fit for applications that will end up with more than 100k of application code. That sounds like a lot of code, but it's really only a lot of code for islands of richness. Applications like rdio, documentcloud, soundcloud and other popular Backbone applications can easily reach 500k or even a megabytes or two of code.
In my case for example (photo portfolio websites) it makes a lot of sense to have a single page app for the user backend and plain server rendered html (with a bit of js sugar) for the frontend.
I feel that Backbone.js was first on the scene and hence has found its way into the current developer lexicon and toolset, leaving Ember.js unfairly looked over.
Ember.js is just too opinionated for its own good.
Video: Beyond the DOM: Sane Structure for JS Apps: http://www.youtube.com/watch?v=cd7HHN6IkrU
connnect -> connect
Frankly I'd take any example application over a to-do app at this point.
As an aside, I've been using Sammy.js (http://sammyjs.org) more than most of these other frameworks lately, as the effort involved is disproportionate to the rewards unless you're building the entire frontend in JavaScript. For any less-than-enormous project, you really don't need all that complexity.
https://github.com/emberjs/ember.js/wiki/Production-Deployme...
The font here really sucks, for me anyway. I cannot see the "cross" of the t. It just looks like an l. Anyone else see this?
I am a firm believer in the utility of web frameworks, and I'm always willing to look at new ones. I assumed that the tutorial website had been built using Ember.js, and my first impression was not favorable.