REFACTOR: Prefer `this` over `self`

This commit is contained in:
Robin Ward 2019-01-30 14:29:45 -05:00
parent f7b7bc8abe
commit dca5486b78
1 changed files with 11 additions and 18 deletions

View File

@ -83,12 +83,9 @@ export default Ember.Object.extend({
// Mostly for legacy, things like TopicList without ResultSets // Mostly for legacy, things like TopicList without ResultSets
findFiltered(type, findArgs) { findFiltered(type, findArgs) {
const self = this;
return this.adapterFor(type) return this.adapterFor(type)
.find(this, type, findArgs) .find(this, type, findArgs)
.then(function(result) { .then(result => this._build(type, result));
return self._build(type, result);
});
}, },
_hydrateFindResults(result, type, findArgs) { _hydrateFindResults(result, type, findArgs) {
@ -149,28 +146,25 @@ export default Ember.Object.extend({
}, },
refreshResults(resultSet, type, url) { refreshResults(resultSet, type, url) {
const self = this;
return ajax(url).then(result => { return ajax(url).then(result => {
const typeName = Ember.String.underscore(self.pluralize(type)); const typeName = Ember.String.underscore(this.pluralize(type));
const content = result[typeName].map(obj => const content = result[typeName].map(obj =>
self._hydrate(type, obj, result) this._hydrate(type, obj, result)
); );
resultSet.set("content", content); resultSet.set("content", content);
}); });
}, },
appendResults(resultSet, type, url) { appendResults(resultSet, type, url) {
const self = this;
return ajax(url).then(function(result) { return ajax(url).then(function(result) {
let typeName = Ember.String.underscore(self.pluralize(type)); let typeName = Ember.String.underscore(this.pluralize(type));
let pageTarget = result.meta || result; let pageTarget = result.meta || result;
let totalRows = let totalRows =
pageTarget["total_rows_" + typeName] || resultSet.get("totalRows"); pageTarget["total_rows_" + typeName] || resultSet.get("totalRows");
let loadMoreUrl = pageTarget["load_more_" + typeName]; let loadMoreUrl = pageTarget["load_more_" + typeName];
let content = result[typeName].map(obj => let content = result[typeName].map(obj =>
self._hydrate(type, obj, result) this._hydrate(type, obj, result)
); );
resultSet.setProperties({ totalRows, loadMoreUrl }); resultSet.setProperties({ totalRows, loadMoreUrl });
@ -300,20 +294,19 @@ export default Ember.Object.extend({
}, },
_hydrateEmbedded(type, obj, root) { _hydrateEmbedded(type, obj, root) {
const self = this; Object.keys(obj).forEach(k => {
Object.keys(obj).forEach(function(k) {
const m = /(.+)\_id(s?)$/.exec(k); const m = /(.+)\_id(s?)$/.exec(k);
if (m) { if (m) {
const subType = m[1]; const subType = m[1];
if (m[2]) { if (m[2]) {
const hydrated = obj[k].map(function(id) { const hydrated = obj[k].map(id =>
return self._lookupSubType(subType, type, id, root); this._lookupSubType(subType, type, id, root)
}); );
obj[self.pluralize(subType)] = hydrated || []; obj[this.pluralize(subType)] = hydrated || [];
delete obj[k]; delete obj[k];
} else { } else {
const hydrated = self._lookupSubType(subType, type, obj[k], root); const hydrated = this._lookupSubType(subType, type, obj[k], root);
if (hydrated) { if (hydrated) {
obj[subType] = hydrated; obj[subType] = hydrated;
delete obj[k]; delete obj[k];