Skip to content

Commit

Permalink
Add accessor property to properties object
Browse files Browse the repository at this point in the history
This forces a property listed in `properties` to create a property accessor regardless of whether or not it is needed for effects. This allows using `_propertiesChanged` to process changes for properties that may not have effects.
  • Loading branch information
Steven Orvell committed Sep 15, 2017
1 parent e91b6a7 commit c7b43f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@
* * observer: {string} name of a method that runs when the property
* changes. The arguments of the method are (value, previousValue).
*
* * accessor: {boolean} Set to true to force a property accessor to be
* created regardless of whether or not one is needed for other property
* effects.
*
* Note: Users may want control over modifying property
* effects via subclassing. For example, a user might want to make a
* reflectToAttribute property not do so in a subclass. We've chosen to
Expand Down Expand Up @@ -397,6 +401,10 @@
if (info.observer) {
proto._createPropertyObserver(name, info.observer, allProps[info.observer]);
}
// add an accessor if `accessor` is true
if (info.accessor) {
proto._createPropertyAccessor(name);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/unit/polymer.element.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
},
computedProp: {
computed: '_compute(computedPropDep)'
},
accessor: {
accessor: true
}
};
}
Expand Down Expand Up @@ -383,6 +386,13 @@ <h1>Sub template</h1>
assert.equal(el.computedProp, true);
});

test('properties accessor: true creates accessor', function() {
assert.isTrue(el.__dataHasAccessor.accessor);
el._propertiesChanged = sinon.spy();
el.accessor = 'hi';
assert.equal(el._propertiesChanged.args[0][0].accessor, 'hi');
});

test('attributes', function() {
var fixtureEl = fixture('my-element-attr');
assert.equal(fixtureEl.prop, 'attr');
Expand Down

0 comments on commit c7b43f7

Please sign in to comment.