-
Notifications
You must be signed in to change notification settings - Fork 2.8k
V16/feature: get context resolves in undefined if not found #18611
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
Merged
nielslyngsoe
merged 28 commits into
v16/dev
from
v16/feature/get-context-resolves-in-undefined-if-not-found
Mar 14, 2025
Merged
V16/feature: get context resolves in undefined if not found #18611
nielslyngsoe
merged 28 commits into
v16/dev
from
v16/feature/get-context-resolves-in-undefined-if-not-found
Mar 14, 2025
Conversation
This file contains hidden or 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
…ined-if-not-found
madsrasmussen
approved these changes
Mar 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Making context consumption
.asPromise()result in a Rejected Promise if the context did not show up within one frame.See examples below on how to handle Rejected Promises.
This means that the
getContext()results inundefined, if the context did not show up or if the host gets disconnected in the meantime.As well introducing a
umbOpenModalmethod to simplify opening a modal, and making the opening of Modals result in a Promise Rejection when closed, see examples below to learn how to handle rejected Promises.General corrections to respect failing promises and make sure to react properly to such.
How to handle Promise Rejections:
In some cases you need to handle the Rejection; in others, we handle it for you.
To understand how it works you need to get your head around how Async Methods/Promises are handled in general.
In short you need to be aware about if the rejection is taken care of for your Promise Chain.
Let's look at an actual example:
The rejection results in an error in the browser, to prevent the error we need to catch the Rejected Promise, this can be done like this:
In this case the result then becomes undefined, because that is what the given method to
catchreturns.What we need to learn is that we do not need to handle the rejection for every async method call, we can choose just to handle this for the start of the Promise Chain. In this way:
Now we both support if
methodAand ifmethodBresulted in a rejection.To understand why we need to learn this we can look at a few concrete examples:
How to handle Promise Rejections of
modal.onSubmit()or the newumbOpenModal()or existingumbConfirmModal()For v.16, we need to handle the rejection of
modal.onSubmit(), this example shows how that can take form:Because we appended
.catch(() => undefined);then the returned value will becomeundefinedif the Promise ofonSubmit()was rejected.Another example could look like this:
Because we catch the rejection and return
false, then we get the same value when the user declines and then the user just closes the modal.No need to handle rejections in already handled Promise Chains, like Action Api
execute()An example of a case that is already handled is for the
executemethod for a Action API. See this example:The rejection of
executeis handled on our side, meaning you do not need to catch the rejection ofumbConfirmModal.A rejection that is not handled locally results in the method execution stopping, meaning
this.#repository.delete('1234');will not be executed when the Modal gets closed.