Skip to content

Commit

Permalink
Add setPrivate arg to setProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 14, 2017
1 parent 07786b8 commit e6e4803
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e6e4803

Please sign in to comment.