Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
improve performance for template repeat over model objects with share…
Browse files Browse the repository at this point in the history
…d prototype
  • Loading branch information
John Messerly committed Sep 25, 2014
1 parent 957e177 commit 4efd467
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@

var observedSetCache = [];

var hasOwnProperty = Object.prototype.hasOwnProperty;

function newObservedSet() {
var observerCount = 0;
var observers = [];
Expand All @@ -619,15 +621,24 @@
if (!obj)
return;

if (obj === rootObj)
var observeProto = true;
if (obj === rootObj) {
rootObjProps[prop] = true;

// If we find the property on the root object, we can skip observing
// the prototype, which is expensive. This helps a common use case:
// when the user has <template repeat> over items that all share a
// prototype. See https://github.com/Polymer/polymer-dev/issues/101
observeProto = !hasOwnProperty.call(rootObj, prop);
}

if (objects.indexOf(obj) < 0) {
objects.push(obj);
Object.observe(obj, callback);
}

observe(Object.getPrototypeOf(obj), prop);
if (observeProto)
observe(Object.getPrototypeOf(obj), prop);
}

function allRootObjNonObservedProps(recs) {
Expand Down

0 comments on commit 4efd467

Please sign in to comment.