promised-models
Version:
promise based, typed attributes, nested models and collections
30 lines (26 loc) • 551 B
JavaScript
/**
* Serializeable object attribute
*/
var StringAttribute = require('./string');
module.exports = StringAttribute.inherit({
/**
* @override {StringAttribute}
*/
default: 'null',
/**
* @override {StringAttribute}
*/
get: function () {
return JSON.parse(this.value);
},
/**
* @override {StringAttribute}
*/
parse: function (value) {
if (typeof value !== 'string') {
return JSON.stringify(value);
} else {
return value;
}
}
});