Skip to content

Commit 1e3728b

Browse files
authored
refactor!: drop the support for value array mutations (#4149)
1 parent bdb5d71 commit 1e3728b

3 files changed

Lines changed: 10 additions & 77 deletions

File tree

‎packages/checkbox-group/src/vaadin-checkbox-group.d.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ export interface CheckboxGroupEventMap extends HTMLElementEventMap, CheckboxGrou
7777
*/
7878
declare class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(ThemableMixin(HTMLElement))))) {
7979
/**
80-
* The value of the checkbox group.
81-
* Note: toggling the checkboxes modifies the value by creating new
82-
* array each time, to override Polymer dirty-checking for arrays.
83-
* You can still use Polymer array mutation methods to update the value.
80+
* An array containing values of the currently checked checkboxes.
81+
*
82+
* The array is immutable so toggling checkboxes always results in
83+
* creating a new array.
8484
*/
8585
value: string[];
8686

‎packages/checkbox-group/src/vaadin-checkbox-group.js‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,22 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
117117
static get properties() {
118118
return {
119119
/**
120-
* The value of the checkbox group.
121-
* Note: toggling the checkboxes modifies the value by creating new
122-
* array each time, to override Polymer dirty-checking for arrays.
123-
* You can still use Polymer array mutation methods to update the value.
120+
* An array containing values of the currently checked checkboxes.
121+
*
122+
* The array is immutable so toggling checkboxes always results in
123+
* creating a new array.
124+
*
124125
* @type {!Array<!string>}
125126
*/
126127
value: {
127128
type: Array,
128129
value: () => [],
129130
notify: true,
131+
observer: '__valueChanged',
130132
},
131133
};
132134
}
133135

134-
static get observers() {
135-
return ['__valueChanged(value, value.splices)'];
136-
}
137-
138136
constructor() {
139137
super();
140138

‎packages/checkbox-group/test/checkbox-group.test.js‎

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect } from '@esm-bundle/chai';
22
import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers';
33
import { sendKeys } from '@web/test-runner-commands';
44
import sinon from 'sinon';
5-
import '@polymer/polymer/lib/elements/dom-bind.js';
65
import '../vaadin-checkbox-group.js';
76

87
describe('vaadin-checkbox-group', () => {
@@ -564,70 +563,6 @@ describe('vaadin-checkbox-group', () => {
564563
});
565564
});
566565

567-
describe('array mutation methods', () => {
568-
let bind;
569-
570-
beforeEach(async () => {
571-
group = fixtureSync(`
572-
<dom-bind>
573-
<template>
574-
<vaadin-checkbox-group id="group" value="{{value}}">
575-
<vaadin-checkbox value="a" label="Checkbox A"></vaadin-checkbox>
576-
<vaadin-checkbox value="b" label="Checkbox B"></vaadin-checkbox>
577-
<vaadin-checkbox value="c" label="Checkbox C"></vaadin-checkbox>
578-
</vaadin-checkbox-group>
579-
</template>
580-
</template>
581-
</dom-bind>
582-
`);
583-
bind = document.querySelector('dom-bind');
584-
checkboxes = group.querySelectorAll('vaadin-checkbox');
585-
await nextFrame();
586-
});
587-
588-
it('should notify the value changes from inside', () => {
589-
expect(bind.value).to.be.instanceOf(Array);
590-
expect(bind.value.length).to.equal(0);
591-
checkboxes[0].checked = true;
592-
expect(bind.value.length).to.equal(1);
593-
expect(bind.value[0]).to.equal('a');
594-
});
595-
596-
it('should update checkboxes when a checkbox value is updated using push', () => {
597-
bind.push('value', 'a');
598-
expect(checkboxes[0].checked).to.be.true;
599-
});
600-
601-
it('should update checkboxes when a checkbox value is updated using pop', () => {
602-
bind.value = ['a', 'b'];
603-
bind.pop('value');
604-
expect(checkboxes[0].checked).to.be.true;
605-
expect(checkboxes[1].checked).to.be.false;
606-
});
607-
608-
it('should update checkboxes when a checkbox value is updated using push', () => {
609-
bind.value = ['b'];
610-
bind.unshift('value', 'a');
611-
expect(checkboxes[1].checked).to.be.true;
612-
expect(checkboxes[0].checked).to.be.true;
613-
});
614-
615-
it('should update checkboxes when a checkbox value is updated using unshift', () => {
616-
bind.value = ['a', 'b'];
617-
bind.shift('value');
618-
expect(checkboxes[0].checked).to.be.false;
619-
expect(checkboxes[1].checked).to.be.true;
620-
});
621-
622-
it('should update checkboxes when a checkbox value is updated using splice', () => {
623-
bind.value = ['a', 'b'];
624-
bind.splice('value', 1, 1, 'c');
625-
expect(checkboxes[0].checked).to.be.true;
626-
expect(checkboxes[1].checked).to.be.false;
627-
expect(checkboxes[2].checked).to.be.true;
628-
});
629-
});
630-
631566
describe('wrapping', () => {
632567
beforeEach(async () => {
633568
group = fixtureSync(`

0 commit comments

Comments
 (0)