Skip to content

Commit

Permalink
Merge pull request #1576 from Polymer/nested-behaviors
Browse files Browse the repository at this point in the history
allow behavior arrays to contain nested behavior arrays
  • Loading branch information
Steve Orvell committed May 20, 2015
2 parents cdecff4 + 6a2952d commit a43eb0f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/micro/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
var flat = [];
behaviors.forEach(function(b) {
if (b instanceof Array) {
flat = flat.concat(b);
flat = flat.concat(this._flattenBehaviorsList(b));
} else {
flat.push(b);
}
Expand Down
55 changes: 53 additions & 2 deletions test/unit/behaviors-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

overridableProperty: {
value: false
},

hasBehaviorA: {
value: true
}

},
Expand Down Expand Up @@ -68,6 +72,10 @@
hasOptionsB: {
readOnly: true,
notify: true
},

hasBehaviorB: {
value: true
}

},
Expand Down Expand Up @@ -106,8 +114,6 @@

<script>

Polymer._toOverride = function() {};

Polymer({

behaviors: [
Expand Down Expand Up @@ -141,3 +147,48 @@
</script>

</dom-module>

<script>

Polymer.BehaviorC = {

properties: {

hasBehaviorC: {
value: true
}

}

};

Polymer.BehaviorD = {

properties: {

hasBehaviorD: {
value: true
}

}

};

</script>

<dom-module id="nested-behaviors">

<script>

Polymer({

behaviors: [
[[Polymer.BehaviorC, Polymer.BehaviorB], Polymer.BehaviorA],
Polymer.BehaviorD
]

});

</script>

</dom-module>
23 changes: 23 additions & 0 deletions test/unit/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@
});
});


suite('nexted-behaviors element', function() {

var el;

setup(function() {
el = document.createElement('nested-behaviors');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('properties from nested behaviors', function() {
assert.ok(el.hasBehaviorA, "missing BehaviorA");
assert.ok(el.hasBehaviorB, "missing BehaviorB");
assert.ok(el.hasBehaviorC, "missing BehaviorC");
assert.ok(el.hasBehaviorD, "missing BehaviorD");
});

});

</script>

</body>
Expand Down

0 comments on commit a43eb0f

Please sign in to comment.