diff --git a/src/micro/behaviors.html b/src/micro/behaviors.html
index 7c909de1..bd841d85 100644
--- a/src/micro/behaviors.html
+++ b/src/micro/behaviors.html
@@ -65,6 +65,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
},
_desugarSomeBehaviors: function(behaviors) {
+ var behaviorSet = [];
// iteration 1
behaviors = this._flattenBehaviorsList(behaviors);
// iteration 2
@@ -72,9 +73,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// `_mixinBehavior` has _first property wins_ behavior, this is done
// to optimize # of calls to `_copyOwnProperty`
for (var i=behaviors.length-1; i>=0; i--) {
- this._mixinBehavior(behaviors[i]);
+ var b = behaviors[i];
+ if (behaviorSet.indexOf(b) === -1) {
+ this._mixinBehavior(b);
+ behaviorSet.unshift(b);
+ }
}
- return behaviors;
+ return behaviorSet;
},
_flattenBehaviorsList: function(behaviors) {
@@ -141,7 +146,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
- // special properties on behaviors are not mixed in and are instead
+ // special properties on behaviors are not mixed in and are instead
// either processed specially (e.g. listeners, properties) or available
// for calling via doBehavior (e.g. created, ready)
Polymer.Base._behaviorProperties = {
diff --git a/test/unit/behaviors.html b/test/unit/behaviors.html
index 09e02221..266bf059 100644
--- a/test/unit/behaviors.html
+++ b/test/unit/behaviors.html
@@ -133,21 +133,33 @@ suite('multi-behaviors element', function() {
assert.match(message, /behavior is null/);
warned = true;
};
-
Polymer({
-
+ is: 'behavior-null',
behaviors: [
null
- ],
-
- is: 'behavior-null'
-
+ ]
});
-
assert.equal(warned, true, 'Null behaviour should generate warning');
Polymer.Base._warn = oldWarn;
});
+ test('behavior array is unique', function() {
+ Polymer({
+ is: 'behavior-unique',
+ behaviors: [Polymer.BehaviorA, Polymer.BehaviorA]
+ });
+ assert.equal(document.createElement('behavior-unique').behaviors.length, 1);
+ });
+
+ test('duplicate behaviors keep last behavior', function() {
+ Polymer({
+ is: 'behavior-unique-last-behavior',
+ behaviors: [[Polymer.BehaviorA, Polymer.BehaviorB], Polymer.BehaviorA]
+ });
+ var behaviors = document.createElement('behavior-unique-last-behavior').behaviors;
+ assert.deepEqual(behaviors, [Polymer.BehaviorB, Polymer.BehaviorA]);
+ });
+
});