Skip to content

Instantly share code, notes, and snippets.

@ncolgan
Created December 17, 2012 23:38
Show Gist options
  • Save ncolgan/4323483 to your computer and use it in GitHub Desktop.
Save ncolgan/4323483 to your computer and use it in GitHub Desktop.
Singleton resources in ember.js
App.Store = DS.Store.extend({
revision: 10,
adapter: DS.RESTAdapter.extend({
bulkCommit: false,
find: function(store, type, id) {
if (id === 'singleton') {
var url = '/' + this.rootForType(type);
$.getJSON(url, function(data) {
data.id = id;
store.load(type, id, data);
});
} else {
this._super.apply(this, arguments);
}
}
})
})
App.Profile = DS.Model.extend({
first_name: DS.attr('string'),
last_name: DS.attr('string')
});
App.Profile.reopenClass({
find: function() {
return this._super('singleton');
}
});
@mupkoo
Copy link

mupkoo commented Jun 3, 2014

This looks like a nice solution. Thank you for sharing

@foxnewsnetwork
Copy link

Note for folks now in 2014 using Ember 1.7, and Data 1.0 (or abouts), the

store.load type, id, data

part should be replaced with the following

store.push type, data

since the newer versions of ember no longer supports store.load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment