From e6e4803f842316ddfe5937dc4c162b41a4b2c344 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 14 Apr 2017 15:24:07 -0700 Subject: [PATCH] Add `setPrivate` arg to `setProperties` --- lib/mixins/property-effects.html | 7 +++++-- test/unit/property-effects.html | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/mixins/property-effects.html b/lib/mixins/property-effects.html index 2db0fbffa6..8e7d182283 100644 --- a/lib/mixins/property-effects.html +++ b/lib/mixins/property-effects.html @@ -1479,11 +1479,14 @@ * * @param {Object} props Bag of one or more key-value pairs whose key is * a property and value is the new value to set for that property. + * @param {boolean=} setPrivate When true, any private values set in + * `props` will be set. By default, `setProperties` will not set + * `readOnly: true` root properties. * @public */ - setProperties(props) { + setProperties(props, setPrivate) { for (let path in props) { - if (!this.__readOnly || !this.__readOnly[path]) { + if (setPrivate || !this.__readOnly || !this.__readOnly[path]) { //TODO(kschaaf): explicitly disallow paths in setProperty? // wildcard observers currently only pass the first changed path // in the `info` object, and you could do some odd things batching diff --git a/test/unit/property-effects.html b/test/unit/property-effects.html index d42d1704e5..1310ef0365 100644 --- a/test/unit/property-effects.html +++ b/test/unit/property-effects.html @@ -253,6 +253,36 @@ assert.equal(el.observerCounts.multipleDepChangeHandler, 1, 'observer not called once'); }); + test('setProperties does not set readOnly by default', function() { + assert.equal(el.observerCounts.valueChanged, 1); + assert.equal(el.observerCounts.readonlyvalueChanged, 0); + el.setProperties({ + value: 'shouldChange', + nofx: 'shouldChange', + readonlyvalue: 'shouldNotChange' + }); + assert.equal(el.value, 'shouldChange'); + assert.equal(el.nofx, 'shouldChange'); + assert.equal(el.readonlyvalue, undefined); + assert.equal(el.observerCounts.valueChanged, 2); + assert.equal(el.observerCounts.readonlyvalueChanged, 0); + }); + + test('setProperties sets readOnly using `setPrivate` arg', function() { + assert.equal(el.observerCounts.valueChanged, 1); + assert.equal(el.observerCounts.readonlyvalueChanged, 0); + el.setProperties({ + value: 'shouldChange', + nofx: 'shouldChange', + readonlyvalue: 'shouldChange' + }, true); + assert.equal(el.value, 'shouldChange'); + assert.equal(el.nofx, 'shouldChange'); + assert.equal(el.readonlyvalue, 'shouldChange'); + assert.equal(el.observerCounts.valueChanged, 2); + assert.equal(el.observerCounts.readonlyvalueChanged, 1); + }); + test('annotated computed property', function() { el.value = 20; el.add = 40;