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 Nav/Navbar/Dropdown's LinkTo components to not extend from Ember's LinkComponent #1455

Merged
merged 10 commits into from May 14, 2021

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Mar 14, 2021

According to RFC671 and deprecations introduced in latest Ember Canary.

Should fix the last remaining deprecation, see #1440.

addon/components/bs-link-to.js Outdated Show resolved Hide resolved
addon/components/bs-link-to.js Outdated Show resolved Hide resolved
return;
}

params = params.slice();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We haven't formally deprecated positional params for link params it seems. While this is now deprecated for Ember's original LinkComponent, we do not trigger this deprecation anymore. So we should deprecate this explicitly by ourselves I think. Should be a follow up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't we dropped support for curly-bracket component invocation in v4? If so, there shouldn't be a public API to provide positional params to a component. Or did I missed something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't we dropped support for curly-bracket component invocation in v4

We haven't declared so, no. We dropped arguments for HTML attributes, and more or less recommended to use angle brackets, but haven't explicitly stopped support for curly invocation. At the time there was no reason for this, and this is still not deprecated from Ember's side AFAIK. Except for this positional arguments issue there is no reason why curly invocation should bother us, as long as Ember supports it we can basically not care about it.

We can choose to drop support in a next major, or just say that the use of our custom link component drops support for positional arguments and all the other things (currentWhen) that accidentally became part of our implementation due to extending from LinkComponent, whether or not we consider this a public API or not. (it's a "gray area" I guess)

IIRC you were more on the side of accepting major versions more often, right? So should we actually do this refactoring as part of a v5, with just this edge case-y thing as the (potentially, but rather rare) breaking change?

@simonihmig simonihmig requested a review from jelhan March 14, 2021 23:44
@simonihmig simonihmig changed the title Refactor Nav/Navbar/Dropdown's LinkTo components to not extend from Ember's LinkComponent WIP: Refactor Nav/Navbar/Dropdown's LinkTo components to not extend from Ember's LinkComponent Mar 14, 2021
@simonihmig
Copy link
Contributor Author

The deprecation in Canary is gone, but something else related to FastBoot is failing now... 🤔

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.

Thanks a lot for picking this one up!

Was wondering why you decided to have a base class, which is than extended. Wouldn't implementation be easier to follow and require less code duplication, if <BsLinkTo> is invoked in templates instead of extending from it?

If we can avoid much of the complexity by dropping support for position params, currentWhen and activeClass arguments and may accept some differences in edge cases I would be fully onboard. I'm a little bit afraid of the maintenance burden if trying to exactly replicate current functionality.

addon/components/bs-link-to.js Outdated Show resolved Hide resolved
addon/components/bs-link-to.js Outdated Show resolved Hide resolved
return;
}

params = params.slice();
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't we dropped support for curly-bracket component invocation in v4? If so, there shouldn't be a public API to provide positional params to a component. Or did I missed something?

@uses Mixins.ComponentChild
@public
*/
@classNames(macroCondition(getOwnConfig().isBS4) ? 'nav-link' : '')
export default class NavLinkTo extends LinkComponent.extend(ComponentChild) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't the component render <BsLinkTo> and passing the arguments forward instead of extending from it?

@simonihmig
Copy link
Contributor Author

Was wondering why you decided to have a base class, which is than extended. Wouldn't implementation be easier to follow and require less code duplication, if is invoked in templates instead of extending from it?

I just tried that, which made me remember why: doesn't work for positional arguments. However if we want to drop them anyway - as part of a breaking change or not, see my other comment - then this makes sense!

@simonihmig
Copy link
Contributor Author

I just tried that, which made me remember why: doesn't work for positional arguments. However if we want to drop them anyway - as part of a breaking change or not, see my other comment - then this makes sense!

I refactored this more, this is now yielding the BsLinkTo component directly, without extending it or even having to use a template-only wrapper. This still allows positional arguments, so no need for a semi-breaking change yet...

Will still look if I can remove the old cruft from the BsLinkTo component, i.e. just use the public router.isActive()...

@simonihmig
Copy link
Contributor Author

Will still look if I can remove the old cruft from the BsLinkTo component, i.e. just use the public router.isActive()...

I have done this now as much as possible...

  • Our link component only uses public API of the router service, which is nice.
  • I removed that current-when and other stuff implicitly inherited from Ember's LinkComponent, as indeed we never indicated that was supported
  • However we did have tests for positional arguments! 😕 So removing those kinda feels like introducing a breaking change. I therefore left support, but will add a deprecation for those.
  • The link component is still an Ember.Component as it uses the ComponentChild mixin. We could get rid of the mixin itself, but still require the use of Ember.Component as we have to find the "parent" component (e.g. a nav item), for this annoying entangling of <a> having knowledge or the routing params and <li> needing to set the .active class. (Btw this is not the case anymore in BS5 it seems! 🎉)
  • This could be solved much easier if the navItem would yield the navLinkto component as it could then simply curry a parent=this argument. But unfortunately that's not our API, we yield the navLinkto from the nav itself 😔. I think we should change that (and deprecate the other way), right? Or accept it like it is today, and hope for people to switch to BS5 sooner than later? 🤔

@simonihmig simonihmig changed the title WIP: Refactor Nav/Navbar/Dropdown's LinkTo components to not extend from Ember's LinkComponent Refactor Nav/Navbar/Dropdown's LinkTo components to not extend from Ember's LinkComponent May 13, 2021
@simonihmig simonihmig requested a review from jelhan May 13, 2021 18:08
@simonihmig
Copy link
Contributor Author

Finally CI is passing. @jelhan want to have another look?

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 very good. Thanks a lot for working on this.

addon/components/bs-link-to.js Outdated Show resolved Hide resolved
Comment on lines 6 to 9
@replace={{@replace}}
@disabled={{@disabled}}
@current-when={{@current-when}}
@activeClass={{@activeClass}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think <BsLinkTo> supports @replace, @current-when and @activeClass. I guess a left-over from an earlier iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, will fix!

simonihmig and others added 2 commits May 14, 2021 16:30
Co-authored-by: Jeldrik Hanschke <jelhan@users.noreply.github.com>
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