Monday, 30 September 2013

Filtered arrays and since() functionality in ember-data

Filtered arrays and since() functionality in ember-data

I have a backend resource that contains user activities and in the
application I would like to present activities based on a single day's
worth of activities. I have an ArrayController called ActivitiesController
defined in the router like this:
this.resource('activities', { path: '/activities/:by_date' }, function() {
this.route('new');
});
The REST API provides the following GET method:
GET /activities/[by_date]
So far this looks pretty symmetrical and achievable but I'm running into
two problems:
Parameterized array find. Typically a parameterized route would be
serviced by a ObjectController but in this case the by_date parameter
simply reduces/filters the array of activities but it's still an array
that's returned. I'm not sure how to structure this in the model hook in
the ActivitiesRoute so that its effectively doing a "findAll" rather than
expecting a singular resultset.
Since functionality. As there is a reasonable network cost in bringing
back these arrays of activities I would like to minimize this as much as
possible and the REST API supports this by allowing for a since parameter
to be passed along with the date of the last request. This way the server
simply responds with a 304 code if no records have been updated since the
last call and if there are new records only the new records are returned.
Is there anyway to get this "out of the box" with ember-data? Does this
require building a custom Adaptor? If so, are there any open source
solutions that are available?

No comments:

Post a Comment