Last active
January 5, 2016 14:06
-
-
Save raido/efc6b04753e705b40bbc to your computer and use it in GitHub Desktop.
extactMeta + query + JSONSerializer
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({ | |
appName:'Ember Twiddle' | |
}); |
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.Route.extend({ | |
model() { | |
return this.get('store').query('user'); | |
}, | |
setupController(controller, model) { | |
this._super(...arguments); | |
controller.set('metadata', JSON.stringify(model.get('meta'))); | |
} | |
}); |
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.JSONSerializer.extend({ | |
extractMeta (store, modelClass, payload) { | |
// Only pitfall, that this is called twice | |
// First from normalizeQueryResponse below and | |
// second time from private _normalizeResponse | |
// so you probably need some conditionals here | |
// OR you could rename it "myExtractMeta" - then theres no twice function call | |
return payload.pagination; | |
}, | |
normalizeQueryResponse (store, primaryModelClass, payload, id, requestType) { | |
let meta = this.extractMeta(store, primaryModelClass, payload) | |
let doc = this._super(store, primaryModelClass, payload.result, id, requestType); | |
doc.meta = meta; | |
return doc; | |
} | |
}); |
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({ | |
name: 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
{ | |
"version": "0.4.17", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js" | |
} | |
} |
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.Adapter.extend({ | |
query() { | |
return { | |
result: [{ | |
id: 1, | |
name: 'User' | |
},{ | |
id: 2, | |
name: 'Second User' | |
}], | |
pagination: { | |
page: 1, | |
total: 100 | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment