mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #1510 from velesin/model_refactoring
refactors Discourse.Model
This commit is contained in:
commit
3854c2d24f
@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user