Skip to content

Commit

Permalink
built it
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ Ortega committed Apr 25, 2015
1 parent 6d7176f commit ee53ad0
Show file tree
Hide file tree
Showing 4 changed files with 629 additions and 477 deletions.
228 changes: 144 additions & 84 deletions dist/polymer-micro.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,44 @@
}
});
Polymer.Base = {
addFeature: function (feature) {
_addFeature: function (feature) {
this.extend(this, feature);
},
registerCallback: function () {
this.registerFeatures();
this.registered();
},
registered: function () {
this._registerFeatures();
this._doBehavior('registered');
},
createdCallback: function () {
Polymer.telemetry.instanceCount++;
this.root = this;
this.beforeCreated();
this.created();
this.afterCreated();
this.initFeatures();
},
beforeCreated: function () {
},
created: function () {
},
afterCreated: function () {
this._doBehavior('created');
this._initFeatures();
},
attachedCallback: function () {
this.isAttached = true;
this.attached();
},
attached: function () {
this._doBehavior('attached');
},
detachedCallback: function () {
this.isAttached = false;
this.detached();
},
detached: function () {
this._doBehavior('detached');
},
attributeChangedCallback: function (name) {
this.setAttributeToProperty(this, name);
this.attributeChanged.apply(this, arguments);
},
attributeChanged: function () {
this._doBehavior('attributeChanged', arguments);
},
extend: function (prototype, api) {
if (prototype && api) {
Object.getOwnPropertyNames(api).forEach(function (n) {
var pd = Object.getOwnPropertyDescriptor(api, n);
if (pd) {
Object.defineProperty(prototype, n, pd);
}
});
this.copyOwnProperty(n, api, prototype);
}, this);
}
return prototype || api;
},
copyOwnProperty: function (name, source, target) {
var pd = Object.getOwnPropertyDescriptor(source, name);
if (pd) {
Object.defineProperty(target, name, pd);
}
}
};
if (Object.__proto__) {
Expand Down Expand Up @@ -191,7 +178,7 @@
}
}
}());
Polymer.Base.addFeature({
Polymer.Base._addFeature({
_prepIs: function () {
if (!this.is) {
var module = (document._currentScript || document.currentScript).parentNode;
Expand All @@ -202,43 +189,95 @@
}
}
});
Polymer.Base.addFeature({
_prepMixins: function () {
if (this.mixins) {
this.mixins.forEach(function (m) {
Polymer.Base.extend(this, m);
Polymer.Base._addFeature({
behaviors: [],
_prepBehaviors: function () {
this._flattenBehaviors();
this._prepBehavior(this);
this.behaviors.forEach(function (b) {
this._mixinBehavior(b);
this._prepBehavior(b);
}, this);
},
_flattenBehaviors: function () {
var flat = [];
this.behaviors.forEach(function (b) {
if (!b) {
console.warn('Polymer: undefined behavior in [' + this.is + ']');
} else if (b instanceof Array) {
flat = flat.concat(b);
} else {
flat.push(b);
}
}, this);
this.behaviors = flat;
},
_mixinBehavior: function (b) {
Object.getOwnPropertyNames(b).forEach(function (n) {
switch (n) {
case 'registered':
case 'properties':
case 'observers':
case 'listeners':
case 'keyPresses':
case 'hostAttributes':
case 'created':
case 'attached':
case 'detached':
case 'attributeChanged':
case 'configure':
case 'ready':
break;
default:
this.copyOwnProperty(n, b, this);
break;
}
}, this);
},
_doBehavior: function (name, args) {
this.behaviors.forEach(function (b) {
this._invokeBehavior(b, name, args);
}, this);
this._invokeBehavior(this, name, args);
},
_invokeBehavior: function (b, name, args) {
var fn = b[name];
if (fn) {
fn.apply(this, args || Polymer.nar);
}
},
_marshalBehaviors: function () {
this.behaviors.forEach(function (b) {
this._marshalBehavior(b);
}, this);
this._marshalBehavior(this);
}
});
Polymer.Base.addFeature({
Polymer.Base._addFeature({
_prepExtends: function () {
if (this.extends) {
this.__proto__ = this.getExtendedPrototype(this.extends);
this.__proto__ = this._getExtendedPrototype(this.extends);
}
},
getExtendedPrototype: function (tag) {
return this.getExtendedNativePrototype(tag);
_getExtendedPrototype: function (tag) {
return this._getExtendedNativePrototype(tag);
},
nativePrototypes: {},
getExtendedNativePrototype: function (tag) {
var p = this.nativePrototypes[tag];
_nativePrototypes: {},
_getExtendedNativePrototype: function (tag) {
var p = this._nativePrototypes[tag];
if (!p) {
var np = this.getNativePrototype(tag);
p = this.extend(Object.create(np), Polymer.Base);
this.nativePrototypes[tag] = p;
this._nativePrototypes[tag] = p;
}
return p;
},
getNativePrototype: function (tag) {
return Object.getPrototypeOf(document.createElement(tag));
}
});
Polymer.Base.addFeature({
Polymer.Base._addFeature({
_prepConstructor: function () {
if (this.hasOwnProperty('constructor')) {
this._userConstructor = this.constructor;
}
this._factoryArgs = this.extends ? [
this.extends,
this.is
Expand All @@ -258,36 +297,33 @@
},
_factory: function (args) {
var elt = document.createElement.apply(document, this._factoryArgs);
if (this._userConstructor) {
this._userConstructor.apply(elt, args);
if (this.factoryImpl) {
this.factoryImpl.apply(elt, args);
}
return elt;
}
});
Polymer.nob = Object.create(null);
Polymer.Base.addFeature({
Polymer.Base._addFeature({
properties: {},
getPropertyInfo: function (property) {
return this._getPropertyInfo(property, this.properties);
var info = this._getPropertyInfo(property, this.properties);
if (!info) {
this.behaviors.some(function (b) {
return info = this._getPropertyInfo(property, b.properties);
}, this);
}
return info || Polymer.nob;
},
_getPropertyInfo: function (property, properties) {
var p = properties[property];
var p = properties && properties[property];
if (typeof p === 'function') {
p = properties[property] = { type: p };
}
return p || Polymer.nob;
},
getPropertyType: function (property) {
return this.getPropertyInfo(property).type;
},
isReadOnlyProperty: function (property) {
return this.getPropertyInfo(property).readOnly;
},
isNotifyProperty: function (property) {
return this.getPropertyInfo(property).notify;
},
isReflectedProperty: function (property) {
return this.getPropertyInfo(property).reflectToAttribute;
if (p) {
p.defined = true;
}
return p;
}
});
Polymer.CaseMap = {
Expand All @@ -314,17 +350,16 @@
});
}
};
Polymer.Base.addFeature({
Polymer.Base._addFeature({
_marshalAttributes: function () {
this._takeAttributes();
this._installHostAttributes(this.hostAttributes);
},
_installHostAttributes: function (attributes) {
if (attributes) {
this.applyAttributes(this, attributes);
this._applyAttributes(this, attributes);
}
},
applyAttributes: function (node, attr$) {
_applyAttributes: function (node, attr$) {
for (var n in attr$) {
this.serializeValueToAttribute(attr$[n], n, this);
}
Expand All @@ -333,22 +368,17 @@
this._takeAttributesToModel(this);
},
_takeAttributesToModel: function (model) {
for (var propName in this.properties) {
var attrName = Polymer.CaseMap.camelToDashCase(propName);
if (this.hasAttribute(attrName)) {
var val = this.getAttribute(attrName);
var type = this.getPropertyType(propName);
model[propName] = this.deserialize(val, type);
}
for (var i = 0, l = this.attributes.length; i < l; i++) {
this.setAttributeToProperty(model, this.attributes[i].name);
}
},
setAttributeToProperty: function (model, attrName) {
if (!this._serializing) {
var propName = Polymer.CaseMap.dashToCamelCase(attrName);
if (propName in this.properties) {
var type = this.getPropertyType(propName);
var info = this.getPropertyInfo(propName);
if (info.defined || this._propertyEffects && this._propertyEffects[propName]) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, type);
model[propName] = this.deserialize(val, info.type);
}
}
},
Expand Down Expand Up @@ -412,15 +442,45 @@
}
}
});
Polymer.Base.addFeature({
registerFeatures: function () {
Polymer.Base._addFeature({
_setupDebouncers: function () {
this._debouncers = {};
},
debounce: function (jobName, callback, wait) {
this._debouncers[jobName] = Polymer.Debounce.call(this, this._debouncers[jobName], callback, wait);
},
isDebouncerActive: function (jobName) {
var debouncer = this._debouncers[jobName];
return debouncer && debouncer.finish;
},
flushDebouncer: function (jobName) {
var debouncer = this._debouncers[jobName];
if (debouncer) {
debouncer.complete();
}
},
cancelDebouncer: function (jobName) {
var debouncer = this._debouncers[jobName];
if (debouncer) {
debouncer.stop();
}
}
});
Polymer.Base._addFeature({
_registerFeatures: function () {
this._prepIs();
this._prepMixins();
this._prepBehaviors();
this._prepExtends();
this._prepConstructor();
},
initFeatures: function () {
this._marshalAttributes();
_prepBehavior: function () {
},
_initFeatures: function () {
this._setupDebouncers();
this._marshalBehaviors();
},
_marshalBehavior: function (b) {
this._installHostAttributes(b.hostAttributes);
}
});</script>
</head><body>
Expand Down
Loading

0 comments on commit ee53ad0

Please sign in to comment.