Skip to content

Commit

Permalink
Move function out of closure. Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Dec 5, 2017
1 parent ed1454d commit ad539fe
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions lib/mixins/properties-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
(function() {
'use strict';

/**
* Mixes `moreProps` into `props` but upgrades shorthand type
* syntax to { type: Type}.
*
* @param {Object} props Properties to normalize
* @return {Object} Copy of input `props` with normalized properties that
* are in the form {type: Type}
* @private
*/
function normalizeProperties(props) {
const output = {};
for (let p in props) {
const o = props[p];
output[p] = (typeof o === 'function') ? {type: o} : o;
}
return output;
}

/**
* Mixin that provides a minimal starting point to using the PropertiesChanged
* mixin by providing a mechanism to declare properties in a static
Expand Down Expand Up @@ -43,44 +61,29 @@
*/
const base = Polymer.PropertiesChanged(superClass);

/**
* Mixes `moreProps` into `props` but upgrades shorthand type
* syntax to { type: Type}.
*
* @param {Object} props Properties to normalize
* @return {Object} Copy of input `props` with normalized properties that
* are in the form {type: Type}
* @private
*/
function normalizeProperties(props) {
const output = {};
for (let p in props) {
const o = props[p];
output[p] = (typeof o === 'function') ? {type: o} : o;
}
return output;
}

/**
* Returns the super class constructor for the given class, if it is an
* instance of the PropertiesMixin.
*
* @param {PropertiesMixinConstructor} constructor PropertiesMixin constructor
* @return {PropertiesMixinConstructor} Super class constructor
* @param {!PropertiesMixin} constructor PropertiesMixin constructor
* @return {PropertiesMixin} Super class constructor
*/
function superPropertiesClass(constructor) {
const superCtor = Object.getPrototypeOf(constructor);
if (superCtor.prototype instanceof PropertiesMixin) {
return superCtor;
}
// Note, the `PropertiesMixin` class below only refers to the class
// generated by this call to the mixin; the instanceof test only works
// because the mixin is deduped and guaranteed only to apply once, hence
// all constructors in a proto chain will see the same `PropertiesMixin`
return (superCtor.prototype instanceof PropertiesMixin) ?
/** @type {PropertiesMixin} */ (superCtor) : null;
}

/**
* Returns a memoized version of the `properties` object for the
* given class. Properties not in object format are converted to at
* least {type}.
*
* @param {PropertiesMixinConstructor} constructor PropertiesMixin constructor
* @param {PropertiesMixin} constructor PropertiesMixin constructor
* @return {Object} Memoized properties object
*/
function ownProperties(constructor) {
Expand Down Expand Up @@ -189,14 +192,12 @@
* `PropertiesChanged`.
*/
connectedCallback() {
if (super.connectedCallback) {
super.connectedCallback();
}
this._enableProperties();
}

/**
* Called when the element is removed from a document
*/
disconnectedCallback() {}

}

return PropertiesMixin;
Expand Down

0 comments on commit ad539fe

Please sign in to comment.