-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
crisbeto
commented
Jan 23, 2017
- 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.
# Conflicts: # src/lib/button-toggle/button-toggle.html # src/lib/button-toggle/button-toggle.ts
Done @EladBezalel |
|
||
ngAfterContentInit(): void { | ||
this._model = new SelectionModel<MdButtonToggle>(this.multiple, | ||
this._tempValue ? [].concat(this._tempValue) : null); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
@crisbeto is this a breaking change for the toggle button API? If so, can you give a quick summary of the change? |
It's not. It just gets rid of the need for having directives both for |
@crisbeto Is this still something we want to do? If so, can you rebase? Didn't catch this one because I wasn't assigned. |
It does make sense, but looking at the amount of conflicts, it'll be easier to redo this from scratch. |
…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.
…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.
Closing in favor of #9191. |
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |