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 BsAlert to Glimmer component #1224

Merged
merged 2 commits into from Sep 10, 2020
Merged

Refactor BsAlert to Glimmer component #1224

merged 2 commits into from Sep 10, 2020

Conversation

simonihmig
Copy link
Contributor

No description provided.

Copy link
Contributor

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Looks good to me in general. The requested change is only about the fade property, which doesn't seem to be used.

I noticed (again) some architectural decision, which doesn't seem to make much sense anymore to me. They don't need to be addressed while doing the refactoring. But I wanted to get the discussion rolling as we normally don't dig that deep into the code base.

It boils down to having three different states (this.args.visible, this._visible and this.hidden), which control the visibility of the alert (unless I missed something). That seems to be wrong to me.

addon/components/bs-alert.js Show resolved Hide resolved
@@ -55,7 +51,7 @@ export default class Alert extends Component {
* @readonly
* @private
*/
@defaultValue
@tracked
hidden = !this._visible;
Copy link
Contributor

Choose a reason for hiding this comment

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

This default value seems wrong to me. _visible is an alias for this.visible when creating an instance. So it should be either this.visible or this.args.visible. Or did I missed something?

Are you sure about the timing? Is this.args populated early enough?

To be honest I'm also confused about how this.args.visible, this._visible and this.hidden play together. Three different states coming together to decide if the alert is shown seems to be overcomplex. 🤯

Wondering if we can simplify this as it raises so many questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This default value seems wrong to me. _visible is an alias for this.visible when creating an instance. So it should be either this.visible or this.args.visible. Or did I missed something?

this.args.visible would be wrong, as that would not take the default of true into account. And this.visible === this._visible and instantiation time, so does not really matter I think?

this.args.visible and this._visible are the samantically the same, except that _visible can diverge (see the other comment re controlled vs. uncontrolled), which we can revisit as a breaking API change, but not now. IIRC hidden was needed due to CSS transitions, as the outer element that has transitions defined needs to be present in DOM before the transition is triggered. But tbh I was also quite a bit confused about this when I started this refactoring...

Copy link
Contributor

Choose a reason for hiding this comment

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

this.args.visible and this._visible are the samantically the same, except that _visible can diverge

Using a state, which can diverge from the passed in for a default value is confusing for me. Would it be okay for you to use this.visible instead?

Suggested change
hidden = !this._visible;
hidden = !this.visible;

addon/components/bs-alert.js Outdated Show resolved Hide resolved
addon/components/bs-alert.js Show resolved Hide resolved
addon/components/bs-alert.js Outdated Show resolved Hide resolved
},
};
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not getting how this is related to a transition. It seems to guard against fastboot only. It seems to be a @unlessFastboot decorator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really new, we had it already as a CP macro here: https://github.com/kaliber5/ember-bootstrap/blob/master/addon/utils/cp/uses-transition.js

It does check for this.args.fade, so not really just about FastBoot though!?

Copy link
Contributor

@jelhan jelhan Sep 9, 2020

Choose a reason for hiding this comment

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

It does check for this.args.fade, so not really just about FastBoot though!?

Maybe I totally missed something but it doesn't seem to check this.args.fade but a dynamic argument passed in. The only relationship to fade, which I can see is the variable name fadeProperty.

But I agree that we can revisit this later as it was like this before.

Copy link
Contributor

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Would still prefer if we can change the default value of hidden to this.visible but I'm also okay to merge without. Your call. 😄

Thanks a lot for the great work!

@simonihmig
Copy link
Contributor Author

Would still prefer if we can change the default value of hidden to this.visible but I'm also okay to merge without. Your call.

Done. Only for you! 😉

@jelhan jelhan merged commit 5bf366d into master Sep 10, 2020
@jelhan jelhan deleted the glimmer-alert branch September 10, 2020 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants