oomph
Version:
Object Oriented javascript models for the client and the server
39 lines (33 loc) • 1.15 kB
JavaScript
// Generated by CoffeeScript 1.9.3
(function() {
var _, redisObjectClassDataStore, redisObjectInstanceDataStore;
_ = require('lodash');
redisObjectClassDataStore = require('./redisObjectClassDataStore');
redisObjectInstanceDataStore = {
save: function() {
var attr, i, len, ref, updateFields;
if (this.id) {
updateFields = {};
ref = Object.keys(this.constructor.attributes);
for (i = 0, len = ref.length; i < len; i++) {
attr = ref[i];
if (this[attr]) {
updateFields[attr] = this[attr];
}
}
return redisObjectClassDataStore.update.apply(this.constructor, [this.id, updateFields]).then((function(_this) {
return function(newProps) {
return _.assign(_this, newProps);
};
})(this));
} else {
return redisObjectClassDataStore.create.apply(this.constructor, [this]).then((function(_this) {
return function(newProps) {
return _.assign(_this, newProps);
};
})(this));
}
}
};
module.exports = redisObjectInstanceDataStore;
}).call(this);