Skip to content

Commit

Permalink
Avoid initialize >1 time
Browse files Browse the repository at this point in the history
  • Loading branch information
educastellano committed Oct 23, 2023
1 parent 9ab9ed5 commit 67f6fd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var QRReader = class _QRReader extends HTMLElement {
#barcodeDetector = new BarcodeDetector({ formats: ["qr_code"] });
#timer = 0;
#initialized = false;
video = null;
canvas = null;
constructor() {
Expand All @@ -28,7 +29,10 @@
// LifeCycle Callbacks
//
connectedCallback() {
this.initialize();
if (!this.#initialized) {
this.initialize();
this.#initialized = true;
}
}
attributeChangedCallback(attributeName, oldValue, newValue) {
const fn = this[attributeName + "Changed"];
Expand Down
6 changes: 5 additions & 1 deletion qr-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
} = window

export default class QRReader extends HTMLElement {
#initialized = false
#barcodeDetector = new BarcodeDetector({ formats: ['qr_code'] })
#timer = 0
video = null
Expand Down Expand Up @@ -34,7 +35,10 @@ export default class QRReader extends HTMLElement {
// LifeCycle Callbacks
//
connectedCallback () {
this.initialize()
if (!this.#initialized) {
this.initialize()
this.#initialized = true
}
}

attributeChangedCallback (attributeName, oldValue, newValue) {
Expand Down

0 comments on commit 67f6fd9

Please sign in to comment.