Last active
May 4, 2016 16:23
-
-
Save chrism/18dad80b4eebf7314ccfab58b53b3f51 to your computer and use it in GitHub Desktop.
Normalizing Issue with JSON API
This file contains hidden or 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
import DS from 'ember-data'; | |
export default DS.RESTAdapter.extend({ | |
namespace: 'api' | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
queryParams: ['petName'], | |
petName: null, | |
filteredOwners: Ember.computed('petName', '[email protected].[]', function() { | |
let petName = this.get('petName'); | |
let ownersArray = this.get('model').toArray(); | |
let filterPromise = Ember.RSVP.filter(ownersArray, owner => { | |
return owner.get('pets').then( pets => { | |
return pets.isAny('name', petName); | |
}); | |
}); | |
return DS.PromiseArray.create({ | |
promise: filterPromise | |
}); | |
}) | |
}); |
This file contains hidden or 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
export default function() { | |
const videos = { | |
"data": [ | |
{ | |
"type": "video", | |
"id": "f745bec3-7871-43f2-945f-4a96cce5b3df", | |
"attributes": { | |
"hyphenated-attribute": "present", | |
"simple": "also present" | |
} | |
} | |
] | |
} | |
getJSON('/api/videos', videos); | |
} | |
function getJSON(url, jsonResponse) { | |
$.mockjax({ url: url, responseText: jsonResponse }); | |
} |
This file contains hidden or 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
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
hyphenatedAttribute: DS.attr('string'), | |
simple: DS.attr('string') | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
import getMocks from '../mocks'; | |
export default Ember.Route.extend({ | |
init() { | |
this._super(...arguments); | |
getMocks(); | |
}, | |
model() { | |
// this works | |
// https://ember-twiddle.com/dcfb829a48dbbcabee77778ec459861a | |
// return this.store.findAll('video'); | |
// this removes hyphenated attributes | |
return Ember.$.getJSON('/api/videos').then( response => { | |
return this.store.push(response); | |
}); | |
} | |
}); |
This file contains hidden or 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
import DS from 'ember-data'; | |
export default DS.JSONAPISerializer.extend({ | |
}); |
This file contains hidden or 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
{ | |
"version": "0.4.8", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.1.0", | |
"ember-data": "2.1.0", | |
"ember-template-compiler": "2.1.0", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment