From c7b43f78cd1d019898367608f62b811b78227179 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 15 Sep 2017 10:54:58 -0700 Subject: [PATCH] Add `accessor` property to properties object 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. --- lib/mixins/element-mixin.html | 8 ++++++++ test/unit/polymer.element.html | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index 429e9de049..98849e0884 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -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 @@ -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); + } } /** diff --git a/test/unit/polymer.element.html b/test/unit/polymer.element.html index 63de66421e..44fba981f2 100644 --- a/test/unit/polymer.element.html +++ b/test/unit/polymer.element.html @@ -38,6 +38,9 @@ }, computedProp: { computed: '_compute(computedPropDep)' + }, + accessor: { + accessor: true } }; } @@ -383,6 +386,13 @@

Sub template

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');