In Ember.JS, Is there a good reason to be doing this:
import Service, { inject } from '@ember/service';
export default Service.extend({
ajax: inject(),
getAll() {
return this.get('ajax').request(`api/users/`, {
method: 'GET',
contentType: 'application/json'
});
}
});
As opposed to this?
import Service, { inject } from '@ember/service';
export default Service.extend({
ajax: inject(),
getAll() {
return this.ajax.request(`api/users/`, {
method: 'GET',
contentType: 'application/json'
});
}
});
The second method looks cleaner IMO, but I'm wondering if there's a good functional reason to be using .get() over just referencing the service directly.
the future is this.whateverProperty
.
this.get
was implemented in a time where JS lacked a lot of features, and a lot of documentation has yet to be updated.
The official ember guides are already updated:
https://guides.emberjs.com/release/applications/services/#toc_accessing-services
as of Ember 3.1, you can use native getters everywhere.
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