Skip to content

Commit

Permalink
Merge pull request #4390 from Polymer/mutable-data-behavior-fix
Browse files Browse the repository at this point in the history
Allow hybrid elements (like iron-list) to make template instances with mutable data
  • Loading branch information
dfreedm authored Mar 7, 2017
2 parents 5846078 + d9418e1 commit 428e3b0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
}
}
} else {
Polymer._warn('behavior is null, check for missing or 404 import');
console.warn('behavior is null, check for missing or 404 import');
}
}
return list;
Expand Down Expand Up @@ -312,7 +312,7 @@
*/
Polymer.Class = function(info) {
if (!info) {
Polymer._warn('Polymer.Class requires `info` argument');
console.warn('Polymer.Class requires `info` argument');
}
let klass = GenerateClassFromInfo(info, info.behaviors ?
// note: mixinBehaviors ensures `LegacyElementMixin`.
Expand Down
6 changes: 5 additions & 1 deletion lib/legacy/templatizer-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@
* by `stamp` to create new instances of the template.
*
* @param {HTMLTemplateElement} template Template to prepare
* @param {Boolean=} mutableData When `true`, the generated class will skip
* strict dirty-checking for objects and arrays (always consider them to
* be "dirty"). Defaults to false.
* @return {TemplateInstance} Description
*/
templatize(template) {
templatize(template, mutableData) {
this._templatizerTemplate = template;
this.ctor = Polymer.Templatize.templatize(template, this, {
mutableData: Boolean(mutableData),
parentModel: this._parentModel,
instanceProps: this._instanceProps,
forwardHostProp: this._forwardHostPropV2,
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@
* to the instance by the templatize owner. These properties shadow any
* host properties, and changes within the template to these properties
* will result in `notifyInstanceProperties` to be called.
* - `mutableData`: When `true`, the generated class will skip strict
* dirty-checking for objects and arrays (always consider them to be
* "dirty").
* - `notifyInstanceProperties(instance, property, value)`: Called when
* an instance property changes. Users may choose to call `notifyPath`
* on e.g. the owner to notify the change.
Expand Down
2 changes: 2 additions & 0 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<link rel="import" href="lib/elements/array-selector.html">
<!-- custom-style -->
<link rel="import" href="lib/elements/custom-style.html">
<!-- bc behaviors -->
<link rel="import" href="lib/legacy/mutable-data-behavior.html">
<script>
// bc
Polymer.Base = Polymer.LegacyElementMixin(HTMLElement).prototype;
Expand Down
10 changes: 3 additions & 7 deletions test/unit/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,16 @@
});

test('behavior is null generates warning', function() {
var warned = false, oldWarn = Polymer._warn;
Polymer._warn = function(message) {
assert.match(message, /behavior is null/);
warned = true;
};
sinon.spy(console, 'warn');
Polymer({
is: 'behavior-null',
behaviors: [
null
]
});
document.createElement('behavior-null');
assert.equal(warned, true, 'Null behaviour should generate warning');
Polymer.Base._warn = oldWarn;
assert.equal(console.warn.callCount, 1, 'Null behaviour should generate warning');
console.warn.restore();
});

test('behavior array is unique', function() {
Expand Down
10 changes: 3 additions & 7 deletions test/unit/mixin-behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,20 +495,16 @@
});

test('behavior is null generates warning', function() {
var warned = false, oldWarn = Polymer._warn;
Polymer._warn = function(message) {
assert.match(message, /behavior is null/);
warned = true;
};
sinon.spy(console, 'warn');
Polymer({
is: 'behavior-null',
behaviors: [
null
]
});
document.createElement('behavior-null');
assert.equal(warned, true, 'Null behaviour should generate warning');
Polymer.Base._warn = oldWarn;
assert.equal(console.warn.callCount, 1, 'Null behaviour should generate warning');
console.warn.restore();
});

test('behavior array is unique', function() {
Expand Down
3 changes: 0 additions & 3 deletions test/unit/property-effects-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../../lib/legacy/mutable-data-behavior.html">
<link rel="import" href="../../lib/mixins/mutable-data.html">

<dom-module id="x-basic">
<template>
<div id="boundChild"
Expand Down

0 comments on commit 428e3b0

Please sign in to comment.