I'm wondering if there's any way for me to create a custom ember-data method so I can do things like this:
this.store.customMethod('klass')
I know I can override the existing methods for my needs but I need more control than that
Most likely what you want to do is add a custom methods to your models adapter if you want to do custom things. So in adapters/klass.js
:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
customMethod(){
const data = {user: {email: this.get('email')}};
const baseUrl = this.urlForFindAll('user');
return Ember.$.post(`${baseUrl}/password`, data);
}
});
Then somewhere else:
const adapter = this.store.adapterFor('user');
adapter.customMethod();
But yeah sure you can extend the store. In stores/application.js
:
import DS from 'ember-data';
export default DS.Store.extend({
customMethod(model) {
// Do stuff
}
});
Another option is to implement a custom store service.
// app/services/store.js
import DS from 'ember-data';
export default DS.Store.extend({
init: function() {
console.log('Using custom store!');
return this._super.apply(this, arguments);
}
});
https://stackoverflow.com/a/34999549/634545
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With