Skip to content

Commit

Permalink
Minor updates based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 30, 2017
1 parent d3e1bae commit ed1454d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 121 deletions.
88 changes: 0 additions & 88 deletions closure.log

This file was deleted.

38 changes: 17 additions & 21 deletions lib/mixins/properties-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
'use strict';

/**
* Mixin that provides minimal starting point to using the PropertiesChanged
* Mixin that provides a minimal starting point to using the PropertiesChanged
* mixin by providing a mechanism to declare properties in a static
* getter (e.g. static get properties() { return { foo: String } }). Changes
* are reported via the `_propertiesChanged` method.
*
* This mixin provides no specific support for rendering. Users are expected
* to create a shadowRoot and put content into it and update it in whatever
* way makes sense for the use case.
* to create a ShadowRoot and put content into it and update it in whatever
* way makes sense. This can be done in reaction to properties changing by
* implementing `_propertiesChanged`.
*
* @mixinFunction
* @polymer
Expand Down Expand Up @@ -54,11 +55,8 @@
function normalizeProperties(props) {
const output = {};
for (let p in props) {
let o = props[p];
if (typeof o == 'function') {
o = { type: o };
}
output[p] = o;
const o = props[p];
output[p] = (typeof o === 'function') ? {type: o} : o;
}
return output;
}
Expand All @@ -70,9 +68,8 @@
* @param {PropertiesMixinConstructor} constructor PropertiesMixin constructor
* @return {PropertiesMixinConstructor} Super class constructor
*/
function superForClass(constructor) {
const proto = /** @type {PropertiesMixinConstructor} */ (constructor).prototype;
const superCtor = Object.getPrototypeOf(proto).constructor;
function superPropertiesClass(constructor) {
const superCtor = Object.getPrototypeOf(constructor);
if (superCtor.prototype instanceof PropertiesMixin) {
return superCtor;
}
Expand Down Expand Up @@ -110,9 +107,7 @@
*/
static get observedAttributes() {
const props = this._properties;
return props ? Object.keys(props).map(p => {
return this.attributeNameForProperty(p);
}) : [];
return props ? Object.keys(props).map(p => this.attributeNameForProperty(p)) : [];
}

/**
Expand All @@ -123,7 +118,7 @@
*/
static finalize() {
if (!this.hasOwnProperty(JSCompiler_renameProperty('__finalized', this))) {
const superCtor = superForClass(this);
const superCtor = superPropertiesClass(this);
if (superCtor) {
superCtor.finalize();
}
Expand All @@ -149,23 +144,24 @@
/**
* Returns a memoized version of all properties, including those inherited
* from super classes. Properties not in object format are converted to
* at lesat {type}.
* at least {type}.
*
* @return {Object} Object containing properties for this class
* @protected
*/
static get _properties() {
if (!this.hasOwnProperty(
JSCompiler_renameProperty('__properties', this))) {
const superCtor = superForClass(this);
const superCtor = superPropertiesClass(this);
this.__properties = Object.assign({},
superCtor && superCtor._properties, ownProperties(this));
superCtor && superCtor._properties,
ownProperties(this));
}
return this.__properties;
}

/**
* Overrides PropertiesChanged method to return type specified in the
* Overrides `PropertiesChanged` method to return type specified in the
* static `properties` object for the given property.
* @param {string} name Name of property
* @return {*} Type to which to deserialize attribute
Expand All @@ -178,8 +174,8 @@
}

/**
* Overrides default behavior and adds a call to `finalize` which lazily
* configures the element's property accessors.
* Overrides `PropertiesChanged` method and adds a call to
* `finalize` which lazily configures the element's property accessors.
* @override
*/
_initializeProperties() {
Expand Down
5 changes: 3 additions & 2 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,9 @@
constructor() {
super();
/** @type {number} */
// NOTE: used to track re-entrant calls to `_flushProperties`
// path changes dirty check against `__dataTemp` only during one "turn"
// and are cleared when `__dataCounter` returns to 0.
this.__dataCounter = 0;
/** @type {boolean} */
this.__dataClientsReady;
Expand Down Expand Up @@ -1150,8 +1153,6 @@
this.__observeEffects;
/** @type {Object} */
this.__readOnly;
/** @type {number} */
this.__dataCounter;
/** @type {!TemplateInfo} */
this.__templateInfo;
}
Expand Down
12 changes: 6 additions & 6 deletions test/unit/polymer.properties-mixin-with-property-accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<script>
suite('class extends Polymer.PropertiesMixin', function() {

var el;
let el;

setup(function() {
el = document.createElement('my-element');
Expand Down Expand Up @@ -237,7 +237,7 @@
});

test('attributes', function() {
var fixtureEl = fixture('my-element-attr');
const fixtureEl = fixture('my-element-attr');
assert.equal(fixtureEl.prop, 'attr');
assert.equal(fixtureEl._callAttributeChangedCallback, 1);
assert.isTrue(fixtureEl.hasAttribute('tabindex'));
Expand All @@ -247,7 +247,7 @@

suite('subclass', function() {

var el;
let el;

setup(function() {
el = document.createElement('sub-element');
Expand Down Expand Up @@ -284,7 +284,7 @@
});

test('attributes', function() {
var fixtureEl = fixture('sub-element-attr');
const fixtureEl = fixture('sub-element-attr');
assert.equal(fixtureEl.prop, 'attr');
assert.equal(fixtureEl.prop2, 'attr');
assert.equal(fixtureEl._callAttributeChangedCallback, 2);
Expand All @@ -296,7 +296,7 @@

suite('mixin', function() {

var el;
let el;

setup(function() {
el = document.createElement('sub-mixin-element');
Expand Down Expand Up @@ -336,7 +336,7 @@
});

test('attributes', function() {
var fixtureEl = fixture('sub-mixin-element-attr');
const fixtureEl = fixture('sub-mixin-element-attr');
assert.strictEqual(fixtureEl.prop, 'attr');
assert.strictEqual(fixtureEl.prop2, 'attr');
assert.strictEqual(fixtureEl.prop3, 'attr');
Expand Down
8 changes: 4 additions & 4 deletions test/unit/polymer.properties-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<script>
suite('class extends Polymer.PropertiesMixin', function() {

var el;
let el;

setup(function() {
el = document.createElement('my-element');
Expand Down Expand Up @@ -327,7 +327,7 @@
});

test('attributes', function() {
var fixtureEl = fixture('sub-element-attr');
const fixtureEl = fixture('sub-element-attr');
assert.equal(fixtureEl.prop, 'attr');
assert.equal(fixtureEl.prop2, 'attr');
assert.equal(fixtureEl.camelCase, 'camelCase');
Expand All @@ -339,7 +339,7 @@

suite('mixin', function() {

var el;
let el;

setup(function() {
el = document.createElement('sub-mixin-element');
Expand Down Expand Up @@ -379,7 +379,7 @@
});

test('attributes', function() {
var fixtureEl = fixture('sub-mixin-element-attr');
const fixtureEl = fixture('sub-mixin-element-attr');
assert.strictEqual(fixtureEl.prop, 'attr');
assert.strictEqual(fixtureEl.prop2, 'attr');
assert.strictEqual(fixtureEl.prop3, 'attr');
Expand Down

0 comments on commit ed1454d

Please sign in to comment.