Skip to content

Commit

Permalink
Merge pull request #223 from Polymer/master
Browse files Browse the repository at this point in the history
8/1 master -> stable
  • Loading branch information
dfreedm committed Aug 1, 2013
2 parents 0b8de69 + 6e0338c commit 9c8068f
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 786 deletions.
5 changes: 5 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ECHO NPM INSTALL
@call npm install
@ECHO .
@ECHO GRUNT
@call grunt
41 changes: 0 additions & 41 deletions build.log

This file was deleted.

10 changes: 5 additions & 5 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ module.exports = function(grunt) {
Polymer = [
"polymer.js",
"boot.js",
"shimStyling.js",
"lib/lang.js",
"lib/dom.js",
"lib/deserialize.js",
"lib/job.js",
"lib/dom.js",
"lib/super.js",
"lib/deserialize.js",
"api.js",
"instance/utils.js",
"instance/events.js",
"instance/properties.js",
"instance/attributes.js",
"instance/properties.js",
"instance/mdv.js",
"instance/base.js",
"instance/styles.js",
Expand All @@ -38,7 +37,8 @@ module.exports = function(grunt) {
"declaration/events.js",
"declaration/properties.js",
"declaration/attributes.js",
"declaration/polymer-element.js"
"declaration/polymer-element.js",
"deprecated.js"
].map(function(n) {
return "src/" + n;
});
Expand Down
5 changes: 3 additions & 2 deletions polymer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var modules = [
"api.js",
"instance/utils.js",
"instance/events.js",
"instance/properties.js",
"instance/attributes.js",
"instance/properties.js",
"instance/mdv.js",
"instance/base.js",
"instance/styles.js",
Expand All @@ -31,7 +31,8 @@ var modules = [
"declaration/events.js",
"declaration/properties.js",
"declaration/attributes.js",
"declaration/polymer-element.js"
"declaration/polymer-element.js",
"deprecated.js"
].map(function(n) {
return "src/" + n;
}));
Expand Down
3 changes: 2 additions & 1 deletion src/declaration/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
isInstanceAttribute: function(name) {
return !this.blackList[name] && name.slice(0,3) !== 'on-';
},
blackList: {name: 1, 'extends': 1, constructor: 1}
// do not clone these attributes onto instances
blackList: {name: 1, 'extends': 1, constructor: 1, noscript: 1}
};

// add ATTRIBUTES symbol to blacklist
Expand Down
42 changes: 39 additions & 3 deletions src/declaration/polymer-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,62 @@
var extend = Polymer.extend;
var apis = scope.api.declaration;

var deferred = {};

// imperative implementation: Polymer()

// maps tag names to prototypes
var registry = {};

// register an 'own' prototype for tag `name`
function element(name, prototype) {
registry[name] = prototype;
registry[name] = prototype || {};
if (deferred[name]) {
deferred[name].define();
}
}

// returns a prototype that chains to <tag> or HTMLElement
function generatePrototype(tag) {
return Object.create(HTMLElement.getPrototypeForTag(tag));
}

// On platforms that do not support __proto__ (IE10), the prototype chain
// of a custom element is simulated via installation of __proto__.
// Although custom elements manages this, we install it here so it's
// available during desuaring.
function ensurePrototypeTraversal(prototype) {
if (!Object.__proto__) {
var ancestor = Object.getPrototypeOf(prototype);
prototype.__proto__ = ancestor;
if (scope.isBase(ancestor)) {
ancestor.__proto__ = Object.getPrototypeOf(ancestor);
}
}
}

// declarative implementation: <polymer-element>

var prototype = generatePrototype();
extend(prototype, {
// custom element processing
// TODO(sjmiles): temporary BC
readyCallback: function() {
this._createdCallback();
},
createdCallback: function() {
this._createdCallback();
},
// custom element processing
_createdCallback: function() {
// fetch our element name
var name = this.getAttribute('name');
if (registry[name]) {
this.define();
} else {
deferred[name] = this;
}
},
define: function() {
// fetch our element name
var name = this.getAttribute('name');
// fetch our extendee name
Expand All @@ -45,6 +80,7 @@
// Potentially remove when spec bug is addressed.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407
this.addResolvePathApi();
ensurePrototypeTraversal(this.prototype);
// declarative features
this.desugar();
// under ShadowDOMPolyfill, transforms to approximate missing CSS features
Expand Down Expand Up @@ -111,7 +147,7 @@
// make a fresh object that inherits from a prototype object
inheritObject: function(prototype, name) {
// copy inherited properties onto a new object
prototype[name] = extend({}, prototype.__proto__[name]);
prototype[name] = extend({}, Object.getPrototypeOf(prototype)[name]);
},
// register 'prototype' to custom element 'name', store constructor
register: function(name) {
Expand Down
14 changes: 14 additions & 0 deletions src/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2013 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/

// NOTE: put deprecated methods here that throw a useful error
Polymer.register = function(context) {
if (context != window) {
// context is the <element> here, with a name attribute
var name = context.getAttribute('name');
throw new Error('Polymer.register is deprecated in declaration of ' + name + '. Please see http://www.polymer-project.org/getting-started.html');
}
};
13 changes: 13 additions & 0 deletions src/instance/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
// convert representation of 'stringValue' based on type of 'defaultValue'
deserializeValue: function(stringValue, defaultValue) {
return scope.deserializeValue(stringValue, defaultValue);
},
serializeValue: function(value) {
if (typeof value != 'object' && value !== undefined) {
return value;
}
},
propertyToAttribute: function(name) {
if (Object.keys(this[PUBLISHED]).indexOf(name) >= 0) {
var serializedValue = this.serializeValue(this[name]);
if (serializedValue !== undefined) {
this.setAttribute(name, serializedValue);
}
}
}
};

Expand Down
55 changes: 45 additions & 10 deletions src/instance/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
// user entry point for constructor-like initialization
ready: function() {
},
// system entry point, do not override
// TODO(sjmiles): temporary BC
readyCallback: function() {
this._createdCallback();
},
createdCallback: function() {
this._createdCallback();
},
// system entry point, do not override
_createdCallback: function() {
//this.style.display = 'inline-block';
// install property observers
// do this first so we can observe changes during initialization
Expand All @@ -31,10 +38,44 @@
// bindings will self destruct after a short time; this is
// necessary to make elements collectable as garbage
// when polyfilling Object.observe
this.asyncUnbindAll();
//this.asyncUnbindAll();
// user initialization
this.ready();
},
insertedCallback: function() {
this._enteredDocumentCallback();
},
enteredDocumentCallback: function() {
this._enteredDocumentCallback();
},
_enteredDocumentCallback: function() {
this.cancelUnbindAll(true);
// TODO(sorvell): bc
if (this.inserted) {
this.inserted();
}
// invoke user action
if (this.enteredDocument) {
this.enteredDocument();
}
},
removedCallback: function() {
this._leftDocumentCallback();
},
leftDocumentCallback: function() {
this._leftDocumentCallback();
},
_leftDocumentCallback: function() {
this.asyncUnbindAll();
// TODO(sorvell): bc
if (this.removed) {
this.removed();
}
// invoke user action
if (this.leftDocument) {
this.leftDocument();
}
},
// recursive ancestral <element> initialization, oldest first
parseElements: function(p) {
if (p && p.element) {
Expand All @@ -57,14 +98,9 @@
var elderRoot = this.shadowRoot;
// make a shadow root
var root = this.createShadowRoot();
// memoize the elder root
root.olderShadowRoot = elderRoot;
// migrate flag(s)
root.applyAuthorStyles = this.applyAuthorStyles;
root.resetStyleInheritance = this.resetStyleInheritance;
// TODO(sorvell): host not set per spec; we set it for convenience
// so we can traverse from root to host.
root.host = this;
// stamp template
// which includes parsing and applying MDV bindings before being
// inserted (to avoid {{}} in attribute values)
Expand All @@ -74,8 +110,6 @@
root.appendChild(dom);
// perform post-construction initialization tasks on shadow root
this.shadowRootReady(root, template);
// watch future changes to shadow root
CustomElements.watchShadow(this);
// return the created shadow root
return root;
}
Expand All @@ -100,7 +134,8 @@
};
}
},
attributeChangedCallback: function() {
attributeChangedCallback: function(name, oldValue) {
this.attributeToProperty(name, this.getAttribute(name));
if (this.attributeChanged) {
this.attributeChanged.apply(this, arguments);
}
Expand Down
14 changes: 0 additions & 14 deletions src/instance/mdv.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,6 @@
}
});
}
},
insertedCallback: function() {
this.cancelUnbindAll(true);
// invoke user 'inserted'
if (this.inserted) {
this.inserted();
}
},
removedCallback: function() {
this.asyncUnbindAll();
// invoke user 'removed'
if (this.removed) {
this.removed();
}
}
};

Expand Down
7 changes: 6 additions & 1 deletion src/instance/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// magic words

var OBSERVE_SUFFIX = 'Changed';

var PUBLISHED = scope.api.instance.attributes.PUBLISHED;

// element api

Expand Down Expand Up @@ -53,10 +55,13 @@
unregisterObservers(this);
},
// property should be observed if it has an observation callback
// or if it is published
shouldObserveProperty: function(name) {
return Boolean(this[name + OBSERVE_SUFFIX]);
return Boolean(this[name + OBSERVE_SUFFIX] ||
Object.keys(this[PUBLISHED]).indexOf(name) >= 0);
},
dispatchPropertyChange: function(name, oldValue) {
this.propertyToAttribute(name);
invoke.call(this, name + OBSERVE_SUFFIX, [oldValue]);
}
};
Expand Down
10 changes: 8 additions & 2 deletions src/instance/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
var scope = this.findStyleController();
if (scope && !this.scopeHasElementStyle(scope, STYLE_CONTROLLER_SCOPE)) {
// allow inherited controller styles
var proto = Object.getPrototypeOf(this), cssText = '';
var proto = getPrototypeOf(this), cssText = '';
while (proto && proto.element) {
cssText += proto.element.cssTextForScope(STYLE_CONTROLLER_SCOPE);
proto = Object.getPrototypeOf(proto);
proto = getPrototypeOf(proto);
}
if (cssText) {
var style = this.element.cssTextToScopeStyle(cssText,
Expand Down Expand Up @@ -73,6 +73,12 @@
}
}
};

// NOTE: use raw prototype traversal so that we ensure correct traversal
// on platforms where the protoype chain is simulated via __proto__ (IE10)
function getPrototypeOf(prototype) {
return prototype.__proto__;
}

// exports

Expand Down
Loading

0 comments on commit 9c8068f

Please sign in to comment.