Should we keep using Ember Data?

Ember-Data works quite well with HAL: https://github.com/201-created/ember-data-hal-9000

Or Firebase: GitHub - FirebaseExtended/emberfire: The officially supported adapter for using Firebase with Ember

In fact the included adapter is the ActiveModelAdapter, which tracks the Ruby ActiveModelSerializer gem.

If you want to use JSON-API, I suggest this adapter: https://github.com/kurko/ember-json-api

Anyway, whatever the fault of Ember-Data (and sure, there are faults), I would not suggest that one of them is a “coupling” to JSON-API. I regularly write customize adapters and serializers to match quirks in an API.

If you need the features Ember-Data provides, you can write an adapter for most well-constructed and consistent APIs. It takes some elbow grease, but so would adding all those features on top of a custom data-layer.

As a real-world example, this codebase uses a HAL adapter, _links to describe relationships (no ids), hits two different API hosts (even through relationships), and supports nested URLs. Definitely not a JSON-API, but we use Ember-Data quite successfully.

A few additional thoughts:

  • You will always have a more successful API story if you build it to a standard. I don’t care which. Choosing a standard will make your life with Ember-Data simpler, but also with any other kind of client. It provides a concrete guide to check your behavior against, instead of the design details being trapped in the head of a developer. This is the biggest single piece of advice I can offer. Reality dictates that you cannot always re-write an existing API, and I don’t suggest that, but you should keep the goal of moving toward standards in mind.
  • “Am I wrong to think that Ember Data can’t handle relationships that are manipulated by HTTP calls?” If an API call has a side-effect of changing a secondary model, we often either a) sideload the changed model. Ember-Data will load any data you push in a sideload at any time. Or b) on the client side, reload or fetch the needed data after the save completes. Promises are your friend here, and make chaining a save then a reload easy.

I suggest starting with unit tests and https://github.com/trek/pretender to be sure you understand how your data-layer works. Testing helps to break down the insurmountable task of writing a data layer (of any kind) into manageable pieces.

2 Likes