Created
May 19, 2014 21:48
-
-
Save csprocket777/456fac14f21d7af32d74 to your computer and use it in GitHub Desktop.
Ember-Data Poop box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var adapter = DS.RESTAdapter.extend({ | |
host: window.apiHost, | |
ajax: function(url, method, hash){ | |
hash = hash || {}; | |
hash.crossDomain = true; | |
return this._super(url, method, hash); | |
}, | |
findQuery: function(store, type, id) { | |
var allOfType = store.all(type); | |
if( allOfType.content.length === 0 ) | |
{ | |
return this._super.apply(this, arguments); | |
}else{ | |
return new Ember.RSVP.Promise(function(resolve, reject){ | |
allOfType = allOfType.filter(function(item){ | |
var $return = true; | |
for(var prop in id){ | |
if( $return === false ) | |
{ | |
return $return; | |
}else{ | |
switch( Ember.get(type, 'fields').get(prop) ) | |
{ | |
case "attribute": | |
$return = item.get(prop) === id[prop]; | |
break; | |
case "belongsTo": | |
$return = item.get(prop + '.id') === id[prop]; | |
break; | |
case "hasMany": | |
$return = item.get(prop + '.id') === id[prop]; | |
break; | |
} | |
} | |
} | |
return $return; | |
}.bind(this)); | |
allOfType = allOfType.map(function(item){ return item.serialize({includeId: true}); }); | |
var $returnObj = {}; | |
$returnObj[type.typeKey.pluralize()] = allOfType; | |
resolve($returnObj); | |
}.bind('this')); | |
} | |
}, | |
findMany: function(store, type, ids) { | |
var allOfType = store.all(type); | |
if( allOfType.content.length === 0 ) | |
{ | |
return this._super.apply(this, arguments); | |
}else{ | |
return new Ember.RSVP.Promise(function(resolve, reject){ | |
allOfType = allOfType.filter(function(item){ | |
return ids.contains(item.get("id")); | |
}.bind(this)); | |
allOfType = allOfType.map(function(item){ return item.serialize({includeId: true}); }); | |
var $returnObj = {}; | |
$returnObj[type.typeKey.pluralize()] = allOfType; | |
resolve($returnObj); | |
}.bind('this')); | |
} | |
} | |
}); | |
export default adapter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok. this is currently MORE poop. :(