This post is a followup to some discussions in Slack with Learning Team people. I wrote:
Hypothesis: we should stop trying to teach routing and ember-data simultaneously. They are separate topics and each is complex enough by itself that mashing them together leads to a lot of confusion. I’m speaking specifically about places like here. People are often amazed when I point out that they can just use
jQuery.ajaxor anything else they already understand.
And we had a lot of general agreement. There was a followup question that I thought deserves a more thorough response, which is: what is the rationale for when you should choose Ember Data?
There is certainly nothing wrong with just always starting with Ember Data, and that is why it’s in the default app blueprint. But I frequently see questions from beginners who are struggling because they have found a use case where it’s not obvious how to make Ember Data do something, and they’re not even aware that they can simply bypass it and do a simpler thing. When you’re already busy learning routing and components and services, it’s pretty nice to just
fetch some JSON and delay learning about models and adapters and serializers until you actually need those things.
So when do you need those things? It comes down to a few dimensions:
- the more concurrent, interactive reading and writing your app does, the more you will benefit from having Ember Data’s identity map. Apps that mostly just read data are easier to keep consistent, so they don’t benefit as much.
- as the number of different kinds of data (models) in your application grows, you’ll start to benefit more from standardizing how they’re all defined, loaded, and saved. At a certain scale, having
fetchsprinkled throughout your codebase makes it pretty hard to even know where all the data is coming from.
I think an ideal way to teach these areas is to start without Ember Data, and point out the missing features in the app (caching, identity mapping, shared code for translating to and from the server formats, etc), and start implementing some of these features directly so the learner understands what they are for, and then switch to Ember Data and delete a bunch of code.