zendesk/ember-resource — pull request #76 by jamesarosen (2014-03-19 22:25:42+00:00)
Title: Add Ember.Resource.find

:bird: @zendesk/harrier

Previously, consumers of resource classes had to create an instance in order to fetch it:

Book.create({ id: 772 }).fetch()

This introduces Resource.find, which has two advantages:

1. it lazily constructs instances after the fetch succeeds
2. the promise it returns resolves with the model

The latter means that Resource.find is a great fit for Ember 1's `Ember.Route#model` hook.

There are several pieces of this code that deserve to be cleaned up in the future:

1. in order to put the code in a separate file, it currently exports the function as `Ember.Resource.__find`, where `Ember.Resource` and `Ember.ResourceCollection` pick it up. ES6 modules will make this much cleaner.
2. the `initializeIdentityMap` functionality already exists in `Ember.Resource.create`. ES6 modules could help here, as could a `NullIdentityMap` for classes that don't want a real identity map.
3. `findByNewRequest` creates its own Deferred and resolves it when the AJAX request resolves. According to the Promises/A spec, this should be done via a simple `.then` chain, but Ember.Resource.ajax returns a "greedy" promise that allows chaining, but doesn't let chained callbacks change the resolution arguments.

Resolves AI-1500