Added some comments, fixed barcode problem when not valid, refactored a condition

This commit is contained in:
alexandercerutti
2018-08-28 15:07:30 +02:00
parent 04c379f9dd
commit 7f43325751

View File

@@ -298,17 +298,13 @@ class Pass {
data = [data]; data = [data];
} }
let valid = data.filter(b => { let valid = data.filter(b => b instanceof Object && schema.isValid(b, "barcode"));
if (!(b instanceof Object)) {
return false;
}
return schema.isValid(b, "barcode"); this.props["barcode"] = valid[0] || undefined;
});
this.props["barcode"] = valid[0] || {};
this.props["barcodes"] = valid || []; this.props["barcodes"] = valid || [];
// I bind "this" to get a clean this when returning from the methods
return Object.assign({ return Object.assign({
length: valid.length, length: valid.length,
autocomplete: this.__barcodeAutocomplete.bind(this), autocomplete: this.__barcodeAutocomplete.bind(this),
@@ -390,6 +386,7 @@ class Pass {
return this; return this;
} }
// Checking which object among barcodes has the same format of the specified one.
let index = this.props["barcodes"].findIndex(b => b.format.toLowerCase().includes(format.toLowerCase())); let index = this.props["barcodes"].findIndex(b => b.format.toLowerCase().includes(format.toLowerCase()));
if (index === -1) { if (index === -1) {