refactors Discourse.Model to bind context to self plus some minor clean-ups

This commit is contained in:
Wojciech Zawistowski 2013-10-09 18:00:55 +02:00
parent acca220380
commit 56a519c583
1 changed files with 6 additions and 10 deletions

View File

@ -16,12 +16,11 @@ Discourse.Model = Ember.Object.extend(Discourse.Presence, {
@param {Object} attrs The attributes we want to merge with @param {Object} attrs The attributes we want to merge with
**/ **/
mergeAttributes: function(attrs) { mergeAttributes: function(attrs) {
var _this = this; var self = this;
_.each(attrs, function(v,k) { _.each(attrs, function(v, k) {
_this.set(k, v); self.set(k, v);
}); });
} }
}); });
Discourse.Model.reopenClass({ Discourse.Model.reopenClass({
@ -31,16 +30,13 @@ Discourse.Model.reopenClass({
@method extractByKey @method extractByKey
@param {Object} collection The collection of values @param {Object} collection The collection of values
@param {Object} klass Optional The class to instantiate @param {Object} klass The class to instantiate
**/ **/
extractByKey: function(collection, klass) { extractByKey: function(collection, klass) {
var retval = {}; var retval = {};
if (!collection) return retval; _.each(collection, function(item) {
_.each(collection,function(c) { retval[item.id] = klass.create(item);
retval[c.id] = klass.create(c);
}); });
return retval; return retval;
} }
}); });