-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Extension should refetch after save changes, save button should …
…only enable when form is dirty
- Loading branch information
1 parent
93f0b74
commit 9ebc177
Showing
4 changed files
with
110 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type CheckConditionFunction = () => Promise<boolean>; | ||
|
||
export function waitForCondition( | ||
checkCondition: CheckConditionFunction, | ||
options: { | ||
interval?: number; | ||
timeout?: number; | ||
customError?: string; | ||
}, | ||
): Promise<void> { | ||
const { | ||
interval = 1000, | ||
timeout = 30000, | ||
customError = `After ${timeout / 1000} seconds, failed to meet condition`, | ||
} = options; | ||
|
||
return new Promise<void>((resolve, reject) => { | ||
const initTime = new Date().valueOf(); | ||
const intervalId = setInterval(async () => { | ||
// Check if the timeout has been reached | ||
if (new Date().valueOf() - initTime > timeout) { | ||
// After timeout, assume something went wrong | ||
clearInterval(intervalId); | ||
reject(new Error(customError)); | ||
return; | ||
} | ||
|
||
// Check the condition | ||
const conditionMet = await checkCondition(); | ||
|
||
if (conditionMet) { | ||
clearInterval(intervalId); | ||
resolve(); | ||
} | ||
}, interval); | ||
}); | ||
} |