From 7f433257511d2604e932b4ee45c0b822d78f854c Mon Sep 17 00:00:00 2001 From: alexandercerutti Date: Tue, 28 Aug 2018 15:07:30 +0200 Subject: [PATCH] Added some comments, fixed barcode problem when not valid, refactored a condition --- index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index f9e886c..997bf50 100644 --- a/index.js +++ b/index.js @@ -298,17 +298,13 @@ class Pass { data = [data]; } - let valid = data.filter(b => { - if (!(b instanceof Object)) { - return false; - } + let valid = data.filter(b => b instanceof Object && schema.isValid(b, "barcode")); - return schema.isValid(b, "barcode"); - }); - - this.props["barcode"] = valid[0] || {}; + this.props["barcode"] = valid[0] || undefined; this.props["barcodes"] = valid || []; + // I bind "this" to get a clean this when returning from the methods + return Object.assign({ length: valid.length, autocomplete: this.__barcodeAutocomplete.bind(this), @@ -390,6 +386,7 @@ class Pass { 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())); if (index === -1) {