Skip to content

Commit 011c597

Browse files
committed
code improve
1 parent 6c3437e commit 011c597

File tree

37 files changed

+569
-911
lines changed

37 files changed

+569
-911
lines changed

1.hello-world/1.minimum-code.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ <h1 style="font-size: 1.5em;">Read Barcodes from a Camera</h1>
2828

2929
/** LICENSE ALERT - THE END */
3030

31-
let pScanner = null;
3231
document.getElementById('btn-show-scanner').onclick = async function() {
3332
try {
34-
const scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
33+
const scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
3534
/*
3635
* onFrameRead is triggered after the library finishes reading a frame.
3736
* There can be multiple barcodes on one frame.

1.hello-world/10.read-video-pwa/helloworld-pwa.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ <h1 style="font-size: 1.5em;">Hello World for PWA</h1>
2828
// Dynamsoft.DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
2929

3030
/** LICENSE ALERT - THE END */
31-
32-
let pScanner = null;
31+
3332
let latestResult = null;
3433
document.getElementById('readBarcode').onclick = async function() {
3534
Notification.requestPermission().then((result) => {
@@ -38,18 +37,18 @@ <h1 style="font-size: 1.5em;">Hello World for PWA</h1>
3837
}
3938
});
4039
try {
41-
pScanner = pScanner || await Dynamsoft.DBR.BarcodeScanner.createInstance();
42-
pScanner.onFrameRead = results => {
40+
const scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
41+
scanner.onFrameRead = results => {
4342
console.log("Barcodes on one frame:");
4443
for (let result of results) {
4544
console.log(result.barcodeFormatString + ": " + result.barcodeText);
4645
}
4746
};
48-
pScanner.onUnduplicatedRead = (txt, result) => {
47+
scanner.onUnduplicatedRead = (txt, result) => {
4948
latestResult = txt;
5049
alert(txt, result);
5150
}
52-
await pScanner.show();
51+
await scanner.show();
5352
} catch (ex) {
5453
alert(ex.message);
5554
throw ex;

1.hello-world/11.read-video-requirejs.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ <h1 style="font-size: 1.5em;">Hello World for RequireJS</h1>
3232
/** LICENSE ALERT - THE END */
3333

3434
BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
35-
let pScanner = null;
3635
document.getElementById('readBarcode').onclick = async function() {
3736
try {
38-
const scanner = await (pScanner = pScanner || BarcodeScanner.createInstance());
37+
const scanner = await BarcodeScanner.createInstance();
3938
scanner.onFrameRead = results => {
4039
console.log("Barcodes on one frame:");
4140
for (let result of results) {

1.hello-world/12.minimum-code-es6.html

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ <h1 style="font-size: 1.5em;">Read Barcodes from a Camera</h1>
3131
// Dynamsoft.DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
3232

3333
/** LICENSE ALERT - THE END */
34-
import { DBR, BarcodeScanner } from 'https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.mjs';
34+
import { BarcodeRender, BarcodeScanner } from 'https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.mjs';
3535

3636
// DBR.productKeys = "PRODUCT-KEYS";
3737

38-
DBR.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
38+
BarcodeRender.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
3939

40-
41-
let pScanner = null;
4240
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
4341
try {
44-
pScanner = pScanner || await BarcodeScanner.createInstance();
42+
const scanner = await BarcodeScanner.createInstance();
4543
/*
4644
* onFrameRead is triggered after the library finishes reading a frame.
4745
* There can be one or multiple barcodes on each frame.
4846
*/
49-
pScanner.onFrameRead = results => {
47+
scanner.onFrameRead = results => {
5048
console.log("Barcodes on one frame:");
5149
for (let result of results) {
5250
console.log(result.barcodeFormatString + ": " + result.barcodeText);
@@ -57,11 +55,11 @@ <h1 style="font-size: 1.5em;">Read Barcodes from a Camera</h1>
5755
* The amount of time that the library 'remembers' a barcode is defined by
5856
* "duplicateForgetTime" in "ScanSettings". By default it is set to 3000 ms.
5957
*/
60-
pScanner.onUnduplicatedRead = (txt, result) => {
58+
scanner.onUnduplicatedRead = (txt, result) => {
6159
alert(txt);
62-
console.log("Unique Code Found: " + result);
60+
console.log("Unique Code Found: ", result);
6361
}
64-
await pScanner.show();
62+
await scanner.show();
6563
} catch (ex) {
6664
alert(ex.message);
6765
throw ex;

1.hello-world/12.read-video-webpack/src/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ import DBR from "dynamsoft-javascript-barcode";
1616

1717
DBR.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
1818

19-
let pScanner = null;
2019
if (document.getElementById('readBarcode')) {
2120
document.getElementById('readBarcode').onclick = async function() {
2221
try {
23-
pScanner = pScanner || await DBR.BarcodeScanner.createInstance();
24-
pScanner.onFrameRead = results => {
22+
const scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance();
23+
scanner.onFrameRead = results => {
2524
console.log("Barcodes on one frame:");
2625
for (let result of results) {
2726
console.log(result.barcodeFormatString + ": " + result.barcodeText);
2827
}
2928
};
30-
pScanner.onUnduplicatedRead = (txt, result) => {
29+
scanner.onUnduplicatedRead = (txt, result) => {
3130
alert(txt);
32-
console.log("Unique Code Found: " + result);
31+
console.log("Unique Code Found: ", result);
3332
}
34-
await pScanner.show();
33+
await scanner.show();
3534
} catch (ex) {
3635
alert(ex.message);
3736
throw ex;

1.hello-world/3.read-video-angular/src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { BrowserModule } from '@angular/platform-browser';
33

44
import { AppComponent } from './app.component';
55
import { HelloWorldComponent } from './hello-world/hello-world.component';
6-
import { BarcodeScannerComponent } from './barcode-scanner/barcode-scanner.component';
6+
import { VideoDecodeComponent } from './barcode-scanner/barcode-scanner.component';
77
import { ImgDecodeComponent } from './img-decode/img-decode.component';
88

99
@NgModule({
1010
declarations: [
1111
AppComponent,
1212
HelloWorldComponent,
13-
BarcodeScannerComponent,
13+
VideoDecodeComponent,
1414
ImgDecodeComponent
1515
],
1616
imports: [

0 commit comments

Comments
 (0)