refactor: refs #7644 Optimized barcode #2819

Open
guillermo wants to merge 7 commits from 7644-optimizedBarcode into master
1 changed files with 19 additions and 11 deletions
Showing only changes of commit 1a2ed9ce68 - Show all commits

View File

@ -12,20 +12,28 @@ module.exports = {
const date = new Date();
this.weekNum = moment(date).isoWeek();
this.dayNum = moment(date).day();
this.barcodes = [];
await this.generateAllBarcodes(this.buys);
},
methods: {
getBarcode(id) {
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
generateAllBarcodes(buys) {
const uniqueBuyIds = new Set(buys.map(buy => buy.id));
for (let buy of uniqueBuyIds) {
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
jsBarcode(svgNode, id, {
xmlDocument: document,
format: 'code128',
displayValue: false,
width: 3.8,
height: 115,
});
return new XMLSerializer().serializeToString(svgNode);
jsBarcode(svgNode, buy, {
xmlDocument: document,
format: 'code128',
displayValue: false,
width: 3.8,
height: 115,
});
this.barcodes.push({id: buy, barcode: new XMLSerializer().serializeToString(svgNode)});
}
},
getBarcode(id) {
return this.barcodes.find(item => item.id === id).barcode;
Review

Podries haver fet que this.barcodes fora un Map (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) axina despres sols has de accedir a ixe registre en concret encomter de buscar cada 1

https://www.measurethat.net/Benchmarks/Show/23555/5/arrayfind-vs-mapget#latest_results_block

Podries haver fet que this.barcodes fora un Map (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) axina despres sols has de accedir a ixe registre en concret encomter de buscar cada 1 https://www.measurethat.net/Benchmarks/Show/23555/5/arrayfind-vs-mapget#latest_results_block
}
},
props: {