-
Notifications
You must be signed in to change notification settings - Fork 196
feat: Add a new whenAppLayoutReady to the plugin api #3863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c1fc43b
to
a3254d5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3863 +/- ##
=======================================
Coverage 97.22% 97.22%
=======================================
Files 844 844
Lines 24586 24595 +9
Branches 8672 8677 +5
=======================================
+ Hits 23904 23913 +9
+ Misses 675 633 -42
- Partials 7 49 +42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* Returns a promise that resolves once the app layout has loaded | ||
*/ | ||
export function whenAppLayoutReady() { | ||
return appLayoutReadyDefer.promise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
This code does not work, because the remove widget and the app layout widget are separate bundles, so they will refer to a different
appLayoutReadyDefer
instance -
What is going to happen if app layout renders and then unmounts? This code resolves the promise instantly, but there is no app layout on the page
-
What happens if app layout never renders? The promise will hang forever in this case. We should mention to the consuming team that they might want to add some timeout on their end, for example:
Promise.race([whenAppLayoutReady(), timeout(3000)])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Addressed. Now this promise is stored in
window
object, so any instance will have access to it - The purpose of this promise is to be resolved as soon as the app layout is available, it's not designed to handle other use cases such as unmounting. Do you have any suggestions on that?
- Point taken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Reverse the control.
export function whenAppLayoutReady() {
if(isAppLayoutReady()) {
return Promise.resolve();
}
return new Promise((resolve) => appLayoutReadyCallbacks.push(resolve));
}
function registerAppLayoutHandler () {
appLayoutReadyCallbacks.forEach(() => cb());
appLayoutReadyCallbacks = [];
// other code...
}
42bea39
to
53ee124
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this thread #3863 (comment)
} | ||
const win = getWindow(); | ||
win[storageKeyReadyDeferCallbacks] = win[storageKeyReadyDeferCallbacks] ?? []; | ||
const defer = new Defer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to introduce the defer helper any more. The code from my previous comment works without it
789e5b4
to
c8d86f2
Compare
Description
Added a new
whenAppLayoutReady
to the plugin api to keep track ofAppLayout
state loading. It's useful when left drawer needs to be updated - in this case making sure thatAppLayout
has already loaded is necessary.Related links, issue #, if available: n/a
How has this been tested?
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Security
checkSafeUrl
function.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.