@onehat/data 1.8.8 → 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.
|
@@ -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
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -357,9 +357,10 @@ class AjaxRepository extends Repository {
|
|
|
357
357
|
* Loads data into the Repository.
|
|
358
358
|
* This loads only a single page of data.
|
|
359
359
|
* @param {object} params - Params to send to server
|
|
360
|
+
* @param {function} callback - Function to call after loading is complete
|
|
360
361
|
* @fires beforeLoad,changeData,load,error
|
|
361
362
|
*/
|
|
362
|
-
load = async (params) => {
|
|
363
|
+
load = async (params, callback = null) => {
|
|
363
364
|
if (this.isDestroyed) {
|
|
364
365
|
throw Error('this.load is no longer valid. Repository has been destroyed.');
|
|
365
366
|
}
|
|
@@ -417,6 +418,10 @@ class AjaxRepository extends Repository {
|
|
|
417
418
|
|
|
418
419
|
this.emit('changeData', this.entities);
|
|
419
420
|
this.emit('load', this);
|
|
421
|
+
|
|
422
|
+
if (callback) {
|
|
423
|
+
callback(this.entities);
|
|
424
|
+
}
|
|
420
425
|
})
|
|
421
426
|
.finally(() => {
|
|
422
427
|
this.isLoading = false;
|
|
@@ -426,10 +431,11 @@ class AjaxRepository extends Repository {
|
|
|
426
431
|
/**
|
|
427
432
|
* Reload a single entity from storage.
|
|
428
433
|
* If the entity is in the internal representation, update it.
|
|
434
|
+
* @param {function} callback - Function to call after loading is complete
|
|
429
435
|
* @returns {entity} The newly updated entity
|
|
430
436
|
* @fires reloadEntity,beforeLoad,changeData,load,error
|
|
431
437
|
*/
|
|
432
|
-
reloadEntity = async (entity) => {
|
|
438
|
+
reloadEntity = async (entity, callback = null) => {
|
|
433
439
|
if (this.isDestroyed) {
|
|
434
440
|
throw Error('this.reloadEntity is no longer valid. Repository has been destroyed.');
|
|
435
441
|
}
|
|
@@ -470,6 +476,10 @@ class AjaxRepository extends Repository {
|
|
|
470
476
|
this.emit('changeData', this.entities);
|
|
471
477
|
this.emit('load', this);
|
|
472
478
|
this.emit('reloadEntity', entity);
|
|
479
|
+
|
|
480
|
+
if (callback) {
|
|
481
|
+
callback(entity);
|
|
482
|
+
}
|
|
473
483
|
})
|
|
474
484
|
.finally(() => {
|
|
475
485
|
this.isLoading = false;
|
|
@@ -285,7 +285,7 @@ class LocalFromRemoteRepository extends EventEmitter {
|
|
|
285
285
|
/**
|
|
286
286
|
* Syncs local and remote repositories, based on operation mode.
|
|
287
287
|
*/
|
|
288
|
-
sync = async (entity) => {
|
|
288
|
+
sync = async (entity, callback = null) => {
|
|
289
289
|
try {
|
|
290
290
|
if (!this.isOnline) {
|
|
291
291
|
this._doAutoSync(true);
|
|
@@ -405,6 +405,9 @@ class LocalFromRemoteRepository extends EventEmitter {
|
|
|
405
405
|
} finally {
|
|
406
406
|
this.isSyncing = false;
|
|
407
407
|
this.emit('endSync', this);
|
|
408
|
+
if (callback) {
|
|
409
|
+
callback();
|
|
410
|
+
}
|
|
408
411
|
}
|
|
409
412
|
|
|
410
413
|
}
|