Skip to content

Commit

Permalink
Adding an isReady method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jachin Rupe committed Dec 12, 2023
1 parent 7da199d commit 2040784
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dist/much-select-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class MuchSelect extends HTMLElement {
constructor() {
super();

this._isReady = false;

/**
* Used in the CSS and elsewhere to determine what the
* minimum width should be.
Expand Down Expand Up @@ -381,6 +383,7 @@ class MuchSelect extends HTMLElement {
window.requestAnimationFrame(() => {
this.dispatchEvent(new CustomEvent("ready", { bubbles: true }));
this.dispatchEvent(new CustomEvent("muchSelectReady"));
this._isReady = true;
});
}),
);
Expand Down Expand Up @@ -2003,6 +2006,20 @@ class MuchSelect extends HTMLElement {
}
});
}

async isReady(count = 0) {
// return if this._isReady is true, if not wait a bit and then check 3 more times.
if (this._isReady) {
return true;
}
if (count < 3) {
await new Promise((resolve) => {
setTimeout(resolve, 100);
});
return this.isReady(count + 1);
}
return false;
}
}

// noinspection JSUnusedGlobalSymbols
Expand Down
17 changes: 17 additions & 0 deletions dist/much-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class MuchSelect extends HTMLElement {
constructor() {
super();

this._isReady = false;

/**
* Used in the CSS and elsewhere to determine what the
* minimum width should be.
Expand Down Expand Up @@ -381,6 +383,7 @@ class MuchSelect extends HTMLElement {
window.requestAnimationFrame(() => {
this.dispatchEvent(new CustomEvent("ready", { bubbles: true }));
this.dispatchEvent(new CustomEvent("muchSelectReady"));
this._isReady = true;
});
}),
);
Expand Down Expand Up @@ -2003,6 +2006,20 @@ class MuchSelect extends HTMLElement {
}
});
}

async isReady(count = 0) {
// return if this._isReady is true, if not wait a bit and then check 3 more times.
if (this._isReady) {
return true;
}
if (count < 3) {
await new Promise((resolve) => {
setTimeout(resolve, 100);
});
return this.isReady(count + 1);
}
return false;
}
}

// noinspection JSUnusedGlobalSymbols
Expand Down
17 changes: 17 additions & 0 deletions src/much-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class MuchSelect extends HTMLElement {
constructor() {
super();

this._isReady = false;

/**
* Used in the CSS and elsewhere to determine what the
* minimum width should be.
Expand Down Expand Up @@ -379,6 +381,7 @@ class MuchSelect extends HTMLElement {
window.requestAnimationFrame(() => {
this.dispatchEvent(new CustomEvent("ready", { bubbles: true }));
this.dispatchEvent(new CustomEvent("muchSelectReady"));
this._isReady = true;
});
}),
);
Expand Down Expand Up @@ -2001,6 +2004,20 @@ class MuchSelect extends HTMLElement {
}
});
}

async isReady(count = 0) {
// return if this._isReady is true, if not wait a bit and then check 3 more times.
if (this._isReady) {
return true;
}
if (count < 3) {
await new Promise((resolve) => {
setTimeout(resolve, 100);
});
return this.isReady(count + 1);
}
return false;
}
}

// noinspection JSUnusedGlobalSymbols
Expand Down

0 comments on commit 2040784

Please sign in to comment.