Warren Buckley
09/20/2024, 8:44 AMWarren Buckley
09/20/2024, 8:48 AMWarren Buckley
09/20/2024, 10:03 AMPromise.all()
and using the method .asPromise()
on the Consume Contexts like so...
ts
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<RemoveUnpublishConditionConfig>) {
super(host, args);
// Need to ensure both contexts have been consumed before we can check if we are permitted
// Hence each context is consumed as a promise and then once all resolved we can check if we are permitted
Promise.all([
this.consumeContext(UMB_CURRENT_USER_CONTEXT, (currentUserCtx) =>{
// Observe the current user object
this.observe(currentUserCtx.currentUser, (currentUser) => {
this.#currentUser = currentUser;
});
}).asPromise(),
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (workspaceCtx) => {
// Observe the current document type alias & the document guid/key
this.observe(observeMultiple([workspaceCtx.structure.ownerContentType, workspaceCtx.unique]), ([currentDocType, unique]) => {
this.#unique = unique;
this.#currentDocTypeAlias = currentDocType?.alias;
});
}).asPromise()
]).then(() => {
console.log('🎉🎉 All contexts consumed & observers?! - check if we are permitted 🎉🎉');
// Checks user permissions & sets bool
this.#checkUserPermissions();
// Checks if current doctype should be excluded or not
this.#checkForDocType();
// Once both set above then we can perform final check
this.#checkIfPemitted();
});
}
Is there a neater/better way to do this or.... ?Warren Buckley
09/20/2024, 10:06 AMobserveMultiple
ts
this.observe(observeMultiple([workspaceCtx.structure.ownerContentType, workspaceCtx.unique]), ([currentDocType, unique]) => {
this.#unique = unique;
this.#currentDocTypeAlias = currentDocType?.alias;
});
Warren Buckley
09/20/2024, 10:16 AMnathanwoulfe
09/20/2024, 10:18 AMnathanwoulfe
09/20/2024, 10:19 AMWarren Buckley
09/20/2024, 10:20 AMNiels Lyngsø
09/20/2024, 10:22 AMthis.consumeContext(CONTEXT_TOKEN_A, (context) =>{
this.observe(..., () => {
this.#myvalueA = ....
this.gotSomething();
});
}),
this.consumeContext(CONTEXT_TOKEN_B, (context) => {
this.observe(..., () => {
this.#myvalueB = ....
this.gotSomething();
});
})
...
gotSomething() {
if(!this.#myValueA || !this.myValueB) return;
console.log('I have my values and can do my thing');
}
Niels Lyngsø
09/20/2024, 10:24 AMworkspaceCtx.structure.ownerContentType
Then we should expose a observable just for the alias.Warren Buckley
09/20/2024, 10:25 AMWarren Buckley
09/20/2024, 10:26 AMNiels Lyngsø
09/20/2024, 10:26 AMWarren Buckley
09/20/2024, 10:27 AMWarren Buckley
09/20/2024, 10:32 AM