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
refactor to async/await instead of callbacks in BsModal #1528
refactor to async/await instead of callbacks in BsModal #1528
Conversation
@@ -506,45 +508,33 @@ export default class Modal extends Component { | |||
* @param callback | |||
* @private | |||
*/ | |||
handleBackdrop(callback) { | |||
let doAnimate = this.usesTransition; | |||
async handleBackdrop() { |
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.
Would love to refactor handleBackdrop
into two separate methods: showBackdrop
and hideBackdrop
. But this would also require renaming the existing showBackdrop
property. And I wanted to avoid touching too much in one pull request. I may do that one later.
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.
Thanks for the work!
The existing code originated from ancient times, where I mostly tried to copy the original bootstrap.js, and ember-ify it. This is way better! 👍
addon/components/bs-modal.js
Outdated
this.checkScrollbar(); | ||
this.setScrollbar(); | ||
|
||
schedule('afterRender', async () => { |
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.
While we are at it, could we refactor this also to an async helper, similar to nextRunloop()
, that we can await and then put the other code into the method body itself, rather than the callback?
I like these runloop-related helpers really, makes code much better readable, than the callback-based original primitives. Maybe extract into utils, or potentially an own addon? 😆
addon/components/bs-modal.js
Outdated
} | ||
|
||
this.hideModal(); |
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.
Should we await
this?
You were a little bit quicker than I'm. Actually planned to move the |
<BsModal>
was heavily using callbacks in logic to show and hide a modal. The resulting code was hard to read. This pull requests refactors it toasync
/await
.Pulled this change out of #1402, which got way too big.