Skip to content

Commit e6e4803

Browse files
committed
Add setPrivate arg to setProperties
1 parent 07786b8 commit e6e4803

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

lib/mixins/property-effects.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,11 +1479,14 @@
14791479
*
14801480
* @param {Object} props Bag of one or more key-value pairs whose key is
14811481
* a property and value is the new value to set for that property.
1482+
* @param {boolean=} setPrivate When true, any private values set in
1483+
* `props` will be set. By default, `setProperties` will not set
1484+
* `readOnly: true` root properties.
14821485
* @public
14831486
*/
1484-
setProperties(props) {
1487+
setProperties(props, setPrivate) {
14851488
for (let path in props) {
1486-
if (!this.__readOnly || !this.__readOnly[path]) {
1489+
if (setPrivate || !this.__readOnly || !this.__readOnly[path]) {
14871490
//TODO(kschaaf): explicitly disallow paths in setProperty?
14881491
// wildcard observers currently only pass the first changed path
14891492
// in the `info` object, and you could do some odd things batching

test/unit/property-effects.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,36 @@
253253
assert.equal(el.observerCounts.multipleDepChangeHandler, 1, 'observer not called once');
254254
});
255255

256+
test('setProperties does not set readOnly by default', function() {
257+
assert.equal(el.observerCounts.valueChanged, 1);
258+
assert.equal(el.observerCounts.readonlyvalueChanged, 0);
259+
el.setProperties({
260+
value: 'shouldChange',
261+
nofx: 'shouldChange',
262+
readonlyvalue: 'shouldNotChange'
263+
});
264+
assert.equal(el.value, 'shouldChange');
265+
assert.equal(el.nofx, 'shouldChange');
266+
assert.equal(el.readonlyvalue, undefined);
267+
assert.equal(el.observerCounts.valueChanged, 2);
268+
assert.equal(el.observerCounts.readonlyvalueChanged, 0);
269+
});
270+
271+
test('setProperties sets readOnly using `setPrivate` arg', function() {
272+
assert.equal(el.observerCounts.valueChanged, 1);
273+
assert.equal(el.observerCounts.readonlyvalueChanged, 0);
274+
el.setProperties({
275+
value: 'shouldChange',
276+
nofx: 'shouldChange',
277+
readonlyvalue: 'shouldChange'
278+
}, true);
279+
assert.equal(el.value, 'shouldChange');
280+
assert.equal(el.nofx, 'shouldChange');
281+
assert.equal(el.readonlyvalue, 'shouldChange');
282+
assert.equal(el.observerCounts.valueChanged, 2);
283+
assert.equal(el.observerCounts.readonlyvalueChanged, 1);
284+
});
285+
256286
test('annotated computed property', function() {
257287
el.value = 20;
258288
el.add = 40;

0 commit comments

Comments
 (0)