This repository was archived by the owner on Dec 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathValueObject.js
More file actions
114 lines (99 loc) · 2.86 KB
/
Copy pathValueObject.js
File metadata and controls
114 lines (99 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
define(function (require, exports, module) { // jshint ignore:line
'use strict';
var Extend = require('structurejs/util/Extend');
var Util = require('structurejs/util/Util');
var BaseObject = require('structurejs/BaseObject');
/**
* Value Object (VO) is a design pattern used to transfer data between software application subsystems.
*
* @class ValueObject
* @extends BaseObject
* @param [data] {any} Provide a way to update the value object upon initialization.
* @module StructureJS
* @submodule model
* @constructor
* @author Robert S. (www.codeBelt.com)
*/
var ValueObject = (function () {
var _super = Extend(ValueObject, BaseObject);
function ValueObject() {
_super.call(this);
}
/**
* Provide a way to update the value object.
*
* @method update
* @param data {any}
* @public
*/
ValueObject.prototype.update = function (data) {
for (var key in data) {
if (this.hasOwnProperty(key)) {
this[key] = data[key];
}
}
return this;
};
/**
* ...
*
* @method toJSON
* @returns {ValueObject}
* @public
*/
ValueObject.prototype.toJSON = function () {
var clone = this.clone();
return Util.deletePropertyFromObject(clone, ['cid']);
};
/**
* ...
*
* @method toJSONString
* @returns {string}
* @public
*/
ValueObject.prototype.toJSONString = function () {
return JSON.stringify(this.toJSON());
};
/**
* Converts the string json data into an Object and calls the {{#crossLink "ValueObject/update:method"}}{{/crossLink}} method with the converted Object.
*
* @method fromJSON
* @param json {string}
* @public
*/
ValueObject.prototype.fromJSON = function (json) {
var parsedData = JSON.parse(json);
this.update(parsedData);
return this;
};
/**
*
*
* @method Object
* @returns {any}
* @public
*/
ValueObject.prototype.clone = function () {
return Util.clone(this);
};
/**
*
*
* @method copy
* @returns {IValueObject}
* @public
*/
ValueObject.prototype.copy = function () {
var copy = new Object();
for (var key in this) {
if (this.hasOwnProperty(key)) {
copy[key] = this[key];
}
}
return copy;
};
return ValueObject;
})();
module.exports = ValueObject;
});