@onehat/data 1.8.10 → 1.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cypress/integration/Entity.spec.js +11 -0
- package/package.json +1 -1
- package/src/Entity.js +29 -2
- package/src/Property/Property.js +12 -1
|
@@ -232,6 +232,17 @@ describe('Entity', function() {
|
|
|
232
232
|
expect(_.isEqual(this.entity.rawValues, expected)).to.be.true;
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
+
it('getParsedRawValues & parsedRawValues', function() {
|
|
236
|
+
const result = this.entity.getParsedRawValues(),
|
|
237
|
+
expected = {
|
|
238
|
+
foo: 1,
|
|
239
|
+
bar: 'one',
|
|
240
|
+
baz: true,
|
|
241
|
+
};
|
|
242
|
+
expect(_.isEqual(result, expected)).to.be.true;
|
|
243
|
+
expect(_.isEqual(this.entity.parsedRawValues, expected)).to.be.true;
|
|
244
|
+
});
|
|
245
|
+
|
|
235
246
|
it('getParsedValues & parsedValues', function() {
|
|
236
247
|
const result = this.entity.getParsedValues(),
|
|
237
248
|
expected = {
|
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -584,7 +584,7 @@ class Entity extends EventEmitter {
|
|
|
584
584
|
*/
|
|
585
585
|
getRawValues = () => {
|
|
586
586
|
if (this.isDestroyed) {
|
|
587
|
-
throw Error('this.
|
|
587
|
+
throw Error('this.getRawValues is no longer valid. Entity has been destroyed.');
|
|
588
588
|
}
|
|
589
589
|
let propertyValues = {};
|
|
590
590
|
_.forOwn(this.properties, (property) => {
|
|
@@ -604,6 +604,33 @@ class Entity extends EventEmitter {
|
|
|
604
604
|
return this.getRawValues();
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
+
/**
|
|
608
|
+
* Gets an object of values for this Entity,
|
|
609
|
+
* Values are the "raw" values in their parsed form, not the "parsed" or "submit" or "display" values.
|
|
610
|
+
* @return {object} propertyValues
|
|
611
|
+
*/
|
|
612
|
+
getParsedRawValues = () => {
|
|
613
|
+
if (this.isDestroyed) {
|
|
614
|
+
throw Error('this.getParsedRawValues is no longer valid. Entity has been destroyed.');
|
|
615
|
+
}
|
|
616
|
+
let propertyValues = {};
|
|
617
|
+
_.forOwn(this.properties, (property) => {
|
|
618
|
+
propertyValues[property.name] = property.getParsedRawValue();
|
|
619
|
+
});
|
|
620
|
+
return propertyValues;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Gets "raw" values in their parsed form for this Entity.
|
|
625
|
+
* @return {object} values
|
|
626
|
+
*/
|
|
627
|
+
get parsedRawValues() {
|
|
628
|
+
if (this.isDestroyed) {
|
|
629
|
+
throw Error('this.parsedRawValues is no longer valid. Entity has been destroyed.');
|
|
630
|
+
}
|
|
631
|
+
return this.getParsedRawValues();
|
|
632
|
+
}
|
|
633
|
+
|
|
607
634
|
/**
|
|
608
635
|
* Gets an object of values for this Entity,
|
|
609
636
|
* Values are the "parsed" values, not the "raw" or "submit" or "display" values.
|
|
@@ -726,7 +753,7 @@ class Entity extends EventEmitter {
|
|
|
726
753
|
*/
|
|
727
754
|
getChanged = () => {
|
|
728
755
|
const original = this._originalDataParsed,
|
|
729
|
-
current = this.
|
|
756
|
+
current = this.getParsedRawValues(),
|
|
730
757
|
diff = Object.keys(original).reduce((result, key) => { // from https://stackoverflow.com/a/40610459/9163076
|
|
731
758
|
if (current && !current.hasOwnProperty(key)) {
|
|
732
759
|
result.push(key);
|
package/src/Property/Property.js
CHANGED
|
@@ -183,7 +183,7 @@ export default class Property extends EventEmitter {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
/**
|
|
186
|
-
* Gets "raw" value
|
|
186
|
+
* Gets "raw" value
|
|
187
187
|
* @return {any} rawValue
|
|
188
188
|
*/
|
|
189
189
|
getRawValue = () => {
|
|
@@ -193,6 +193,17 @@ export default class Property extends EventEmitter {
|
|
|
193
193
|
return this.rawValue;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Gets "raw" value in its parsed form
|
|
198
|
+
* @return {any} rawValue
|
|
199
|
+
*/
|
|
200
|
+
getParsedRawValue = () => {
|
|
201
|
+
if (this.isDestroyed) {
|
|
202
|
+
throw Error('this.getParsedRawValue is no longer valid. Property has been destroyed.');
|
|
203
|
+
}
|
|
204
|
+
return this.parse(this.rawValue);
|
|
205
|
+
}
|
|
206
|
+
|
|
196
207
|
/**
|
|
197
208
|
* Gets "parsed" value, without any formatting applied
|
|
198
209
|
* @return {any} parsedValue
|