Skip to content
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

Merged

Conversation

jelhan
Copy link
Contributor

@jelhan jelhan commented May 25, 2021

<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 to async/await.

Pulled this change out of #1402, which got way too big.

@@ -506,45 +508,33 @@ export default class Modal extends Component {
* @param callback
* @private
*/
handleBackdrop(callback) {
let doAnimate = this.usesTransition;
async handleBackdrop() {
Copy link
Contributor Author

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.

@jelhan jelhan requested a review from simonihmig May 25, 2021 19:55
Copy link
Contributor

@simonihmig simonihmig left a 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! 👍

this.checkScrollbar();
this.setScrollbar();

schedule('afterRender', async () => {
Copy link
Contributor

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? 😆

}

this.hideModal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we await this?

@simonihmig simonihmig merged commit f64e675 into master May 26, 2021
@simonihmig simonihmig deleted the refactor-bs-modal-to-use-async-await-instead-of-callbacks branch May 26, 2021 18:30
@jelhan
Copy link
Contributor Author

jelhan commented May 26, 2021

You were a little bit quicker than I'm. Actually planned to move the nextRunloop and afterRender utils into a separate file. But got distracted. 🙈 Will try to recall when I need them next time. 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants