Skip to content

refactor(button-toggle): switch to SelectionModel #2773

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

Closed
wants to merge 3 commits into from

Conversation

crisbeto
Copy link
Member

  • Switches the MdButtonToggleGroup to use the SelectionModel.
  • Avoids having to define two toggle group directives.
  • No longer fires change events from actions that weren't generated by the user.

* Switches the MdButtonToggleGroup to use the SelectionModel.
* Avoids having to define two toggle group directives.
* No longer fires change events from actions that weren't generated by the user.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 23, 2017
@EladBezalel
Copy link
Member

@crisbeto can you please resolve the conflicts?
#2694 pr is based on some changes here

# Conflicts:
#	src/lib/button-toggle/button-toggle.html
#	src/lib/button-toggle/button-toggle.ts
@crisbeto
Copy link
Member Author

Done @EladBezalel


ngAfterContentInit(): void {
this._model = new SelectionModel<MdButtonToggle>(this.multiple,
this._tempValue ? [].concat(this._tempValue) : null);
Copy link
Member

Choose a reason for hiding this comment

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

you can do [this._tempValue] instead of [].concat(this._tempValue)

Copy link
Member Author

Choose a reason for hiding this comment

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

This will end up being wrong if the _tempValue is an array.

this._isInitialized = true;
// Listen to changes in child toggles and re-subscribe when toggles are adde/removed.
this._subscribeToToggleChanges();
this._toggleSubscription = this._toggles.changes.subscribe(() => {
Copy link
Member

Choose a reason for hiding this comment

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

looks better IMO

this._toggleSubscription = this._toggles.changes.subscribe(() => this._subscribeToToggleChanges());

Copy link
Member Author

Choose a reason for hiding this comment

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

It exceeds the maximum line length from the linter config.

Copy link
Member

Choose a reason for hiding this comment

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

yuck

this.value = selected ? selected.value : null;
/** Subscribes to user-generated changes of the button toggles. */
private _subscribeToToggleChanges(): void {
let source = Observable.merge.apply(Observable, this._toggles.map(toggle => toggle.change));
Copy link
Member

Choose a reason for hiding this comment

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

maybe mergeMap is a better solution?

Copy link
Member Author

@crisbeto crisbeto Feb 15, 2017

Choose a reason for hiding this comment

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

I haven't really used mergeMap before, but it doesn't look like it's appropriate here. We only want to merge all of the subscriptions into one so it's easier to listen and unsubscribe to all of them.

Copy link
Member

Choose a reason for hiding this comment

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

It just feel like there's an operator for that.. maybe combineAll?

is toggle.change an observable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's an event that is fired when the selected state changes. We use merge for a couple of other similar cases as well (in the autocomplete and in the select once the multiple selection PR is merged).

@EladBezalel
Copy link
Member

@crisbeto thanks!
@kara can you please review as well?

@jelbourn
Copy link
Member

@crisbeto is this a breaking change for the toggle button API? If so, can you give a quick summary of the change?

@crisbeto
Copy link
Member Author

It's not. It just gets rid of the need for having directives both for md-button-toggle-group and md-button-toggle-group[multiple].

@kara
Copy link
Contributor

kara commented Aug 16, 2017

@crisbeto Is this still something we want to do? If so, can you rebase? Didn't catch this one because I wasn't assigned.

@kara kara removed their request for review August 16, 2017 01:07
@crisbeto
Copy link
Member Author

It does make sense, but looking at the amount of conflicts, it'll be easier to redo this from scratch.

crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 2, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 2, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
@crisbeto
Copy link
Member Author

crisbeto commented Jan 2, 2018

Closing in favor of #9191.

@crisbeto crisbeto closed this Jan 2, 2018
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 3, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 10, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
jelbourn pushed a commit that referenced this pull request Jan 21, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as #2773, however #2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes #9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 22, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 26, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Feb 3, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Feb 19, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Feb 20, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Feb 25, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Mar 12, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Mar 12, 2018
…t in multiple mode

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as angular#2773, however angular#2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes angular#9058.
mmalerba pushed a commit that referenced this pull request Mar 13, 2018
…t in multiple mode (#9191)

* Reworks the `MatButtonToggleGroup` component to remove the need for the `MatButtonToggleGroupMultiple` component and to avoid having to implement features in two places.
* Reworks the `MatButtonToggleGroup` to use the `SelectionModel` for managing its state.
* Switches all of the `async` button toggle tests to run in `fakeAsync`.

As a side-effect of the above-mentioned changes, the toggle group in multiple mode now supports the same inputs as the one in single-selection mode (`value` input/output, `name` input, `change` event etc.).

Note: this is along the same lines as #2773, however #2773 got left behind for too long and it would need a lot more work to fit in our current setup.

Fixes #9058.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants