-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix #19676 #19886
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
Merged
Fix #19676 #19886
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4881c61
observation as promise util
nielslyngsoe caa44cc
all success observer
nielslyngsoe a8a5e8f
next step todos
nielslyngsoe b09ce7f
await everything loaded
nielslyngsoe 5945123
contentTypeLoaded observable
nielslyngsoe f8c2f4e
tidying up
nielslyngsoe 65dd54a
Apply suggestion from @Copilot
nielslyngsoe cf2a2da
remove comment
nielslyngsoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
src/Umbraco.Web.UI.Client/src/libs/observable-api/utils/observation-as-promise.function.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs'; | ||
|
||
/** | ||
* @function observationAsPromise | ||
* @param {Observable<unknown>} observable - an Array of Observables to use for this combined observation. | ||
* @param {Promise<condition>} condition - an method which should return true or false, if rejected or returning undefined the observation will result in a rejected Promise. | ||
* @description - TODO:... | ||
nielslyngsoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns {Promise<unknown>} - Returns a Promise which resolves when the condition returns true or rejects when the condition returns undefined or is rejecting it self. | ||
* @example | ||
* | ||
* TODO: ... | ||
nielslyngsoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
export function observationAsPromise<T>( | ||
observable: Observable<T>, | ||
condition: (value: T) => Promise<boolean | undefined>, | ||
): Promise<T> { | ||
// Notice, we do not want to store and reuse the Promise, cause this promise guarantees that the value is not undefined when resolved. and reusing the promise would not ensure that. | ||
return new Promise<T>((resolve, reject) => { | ||
let initialCallback = true; | ||
let wantedToClose = false; | ||
const subscription = observable.subscribe(async (value) => { | ||
const shouldClose = await condition(value).catch(() => { | ||
if (initialCallback) { | ||
wantedToClose = true; | ||
} else { | ||
subscription.unsubscribe(); | ||
} | ||
reject(value); | ||
}); | ||
if (shouldClose === true) { | ||
if (initialCallback) { | ||
wantedToClose = true; | ||
} else { | ||
subscription.unsubscribe(); | ||
} | ||
resolve(value); | ||
} | ||
}); | ||
initialCallback = false; | ||
if (wantedToClose) { | ||
subscription.unsubscribe(); | ||
} | ||
}); | ||
} |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.