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 Button and ButtonGroup to Glimmer components #1022

Merged
merged 7 commits into from
Sep 6, 2020

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Mar 28, 2020

Proof of concept of how easy/difficult it would be to refactor components:

  • https://github.com/ember-codemods/ember-tracked-properties-codemod helped a bit
  • used https://github.com/jkusa/ember-arg-types at first, but later decided to move most usages into the template (named args, custom helpers instead of CPs), and a custom, very simple @args decorator
  • took a few hours, but was ok
  • tests for <BsButtonGroup> and <BsDropdown> are expectedly failing, as they access private properties of the button, which does not work anymore
  • tests for <BsButton> should be passing, without any changes. Does that make us confident enough that we can refactor component by component in minor version updates, without breaking changes? Or should we do a single major version release with all component refactored? 🤔

@simonihmig simonihmig requested a review from jelhan March 28, 2020 16:02
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.

This looks good to me.

used https://github.com/jkusa/ember-arg-types at first, but later decided to move most usages into the template (named args, custom helpers instead of CPs), and a custom, very simple @args decorator

I'm not sure if the @args decorator is needed at all. It's used at two placed in this pull request. Both could be refactored to named arguments. Such an alias with default value is only needed if the argument is used a lot in JavaScript file itself in my opinion.

tests for <BsButton> should be passing, without any changes. Does that make us confident enough that we can refactor component by component in minor version updates, without breaking changes? Or should we do a single major version release with all component refactored? thinking

In general: Yes. But there are edge cases. E.g. refactor <BsForm> and <BsForm::Element> to Glimmer Components would break the plugin API for validation support. Not sure if there are more of these cases. But at least these two must be changed as part of a major release.

addon/components/bs-button.js Show resolved Hide resolved
addon/components/bs-button.hbs Outdated Show resolved Hide resolved
addon/components/bs-button.js Outdated Show resolved Hide resolved
addon/components/bs-button.hbs Show resolved Hide resolved
@simonihmig simonihmig changed the base branch from dev-v4 to master April 14, 2020 20:34
@simonihmig simonihmig changed the title WIP: Refactor Button to Glimmer component WIP: Refactor Button and ButtonGroup to Glimmer components Aug 19, 2020
@simonihmig
Copy link
Contributor Author

I finally was able to get back to this:

  • rebased
  • refactored also ButtonGroup and Dropdown/Button
  • all tests pass now (without having touched them, yeah!)
  • CI is failing for Ember Canary, but for some form tests, so apparently unrelated

If we are confident enough to release this - and other future Glimmer refactorings - as a regular non-breaking update (seems so judging by not having touched any tests, but who knows if we miss some edge cases?) in the 4.x cycle (maybe with a pre-release like 4.1.0-beta?), then I should bring back the subclassing deprecations as discussed here

@jelhan thoughts?

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 for following up here. Awesome results. 👏

If we are confident enough to release this - and other future Glimmer refactorings - as a regular non-breaking update in the 4.x cycle

I think we should do! If we notice that we have broken something that we can not fix within @glimmer/component we can still revert and park that refactoring until v5 lands. Incrementally moving to a Octane worl without requiring a major release for each step seems to be the ember way. 😜

addon/components/bs-button.js Outdated Show resolved Hide resolved
addon/components/bs-button-group.js Show resolved Hide resolved
addon/components/bs-button-group/button.js Outdated Show resolved Hide resolved
@@ -12,33 +10,26 @@ import defaultValue from 'ember-bootstrap/utils/default-decorator';
@private
*/
export default class ButtonGroupButton extends Button {
'__ember-bootstrap_subclass' = true;

/**
* @property groupValue
* @private
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation for the removed private properties could be removed as well. Or did I missed something? It's the same for buttenGroupType as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those arguments are still passed, from the ButtonGroup component that yields the button. They are just not used on the component class, but as named arguments in the template. I thought we can still leave the doc blocks to document what arguments the component expects.

addon/components/bs-button.hbs Show resolved Hide resolved
addon/components/bs-button.js Outdated Show resolved Hide resolved
return;
}

if (!preventConcurrency || !this.isPending) {
let promise = onClick(this.value);
let promise = onClick(this.args.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems as if we can deprecate value argument. The same can be achieved with {{fn}} helper. Not related to this merge request but the refactoring makes it more visible. 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.

Yeah, so the ButtonGroup's version of a button needs a value, as that determines the value of the group (e.g. an array of all selected button values). The base button does not really need a value, I agree. I think we can refactor that eventually, but only separately as a breaking change!

Copy link
Contributor

@jelhan jelhan Sep 5, 2020

Choose a reason for hiding this comment

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

I'm still thinking that this is better done by currying the arguments using {{fn}} helper.

For the <Button group::Button> it's not that obvious cause how it extends from <BsButton>. Instead of invoking the <BsButton> component in a template it extends from its class. To be honest I don't like that pattern.

I think the <BsButtonGroup::Button> should be refactored to something like this:

<BsButton
  @active={{this.isActive}}
  @onClick={{fn @onClick @value}}
  @type={{@type}}
  @buttonType={{@buttonType}}
  ...attributes
  as |button|
>
  {{yield button}}
</BsButton>

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't get me wrong. This is nothing which is blocking this PR. I will see if I have some time in the next days to provide a PR showcasing such a refactoring.

@simonihmig
Copy link
Contributor Author

@jelhan thanks for the 2nd review! Some how I missed this...

I think I addressed your feedback, thanks for that! Rebased again, after some merge conflicts (#1221). And fixed the new submitButton feature, which was broken by these changes. Hope everything turns green now! 🤞

@simonihmig simonihmig changed the title WIP: Refactor Button and ButtonGroup to Glimmer components Refactor Button and ButtonGroup to Glimmer components Sep 5, 2020
@simonihmig
Copy link
Contributor Author

✅ All green! 🚀

I'll do another bugfix release first before merging this, so we get that fix out without coupling that to eventually (unforeseen) breaking changes.

But after that, I'll like to get this merged, if @jelhan you have nothing left, to not need another rebase! Also I have another branch lined up already that refactored BsAlert, but builds on top of this, so I'll wait to get this merged before opening the PR...

@simonihmig
Copy link
Contributor Author

I'll do another bugfix release first before merging this

Done! :)

@jelhan
Copy link
Contributor

jelhan commented Sep 5, 2020

I'll do another bugfix release first before merging this, so we get that fix out without coupling that to eventually (unforeseen) breaking changes.

I noticed that I missed to update include / exclude feature when implementing form submit button feature. Provided a fix in #1223.

But after that, I'll like to get this merged, if @jelhan you have nothing left, to not need another rebase! Also I have another branch lined up already that refactored BsAlert, but builds on top of this, so I'll wait to get this merged before opening the PR...

Awesome. 👏 Let's ship it.

Are you planning to bundle multiple refactored to @glimmer/component in the same minor? Or do you want to ship each one as soon as it's ready?

@simonihmig
Copy link
Contributor Author

Are you planning to bundle multiple refactored to @glimmer/component in the same minor? Or do you want to ship each one as soon as it's ready?

As I said, I have BsAlert already lined up, so would at least add that too.

Though about maybe releasing a 4.2.0-beta version for people to test this, before a stable v4.2.0? In that case, do you think it makes sense to bundle more refactorings into it, so to have less work testing these kind of prereleases?

@simonihmig simonihmig merged commit ed5a7d4 into master Sep 6, 2020
@simonihmig simonihmig deleted the glimmer-button branch September 6, 2020 13:22
@jelhan
Copy link
Contributor

jelhan commented Sep 6, 2020

Though about maybe releasing a 4.2.0-beta version for people to test this, before a stable v4.2.0? In that case, do you think it makes sense to bundle more refactorings into it, so to have less work testing these kind of prereleases?

Releasing directly as v4.2.0 would be fine for me as well. We can still revert if needed. But in both cases I would release as soon as possible. Better catch regressions not covered by our testing suite as early as possible to not waste time.

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