Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4818 #4839

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elements/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
this.__instance._setPendingProperty(prop, this.__dataHost[prop]);
}
this.__invalidProps = null;
this.__instance._flushProperties();
this.__instance._flushProperties(true);
}
}

Expand Down
50 changes: 31 additions & 19 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@
* @return {boolean} True if an effect ran for this property
* @private
*/
function runEffects(inst, effects, props, oldProps, hasPaths, extraArgs) {
function runEffects(inst, effects, props, oldProps, hasPaths, extraArgs, moreArgs) {
if (effects) {
let ran = false;
let id = dedupeId++;
for (let prop in props) {
if (runEffectsForProperty(inst, effects, id, prop, props, oldProps, hasPaths, extraArgs)) {
if (runEffectsForProperty(inst, effects, id, prop, props, oldProps, hasPaths, extraArgs, moreArgs)) {
ran = true;
}
}
Expand All @@ -146,7 +146,7 @@
* @return {boolean} True if an effect ran for this property
* @private
*/
function runEffectsForProperty(inst, effects, dedupeId, prop, props, oldProps, hasPaths, extraArgs) {
function runEffectsForProperty(inst, effects, dedupeId, prop, props, oldProps, hasPaths, extraArgs, moreArgs) {
let ran = false;
let rootProperty = hasPaths ? Polymer.Path.root(prop) : prop;
let fxs = effects[rootProperty];
Expand All @@ -157,7 +157,7 @@
if (fx.info) {
fx.info.lastRun = dedupeId;
}
fx.fn(inst, prop, props, oldProps, fx.info, hasPaths, extraArgs);
fx.fn(inst, prop, props, oldProps, fx.info, hasPaths, extraArgs, moreArgs);
ran = true;
}
}
Expand Down Expand Up @@ -548,24 +548,25 @@
* metadata
* @private
*/
function runBindingEffect(inst, path, props, oldProps, info, hasPaths, nodeList) {
function runBindingEffect(inst, path, props, oldProps, info, hasPaths, nodeList, moreArgs) {
let node = nodeList[info.index];
let binding = info.binding;
let part = info.part;
let forceChange = moreArgs && moreArgs.forceChange;
// Subpath notification: transform path and set to client
// e.g.: foo="{{obj.sub}}", path: 'obj.sub.prop', set 'foo.prop'=obj.sub.prop
if (hasPaths && part.source && (path.length > part.source.length) &&
(binding.kind == 'property') && !binding.isCompound &&
node.__dataHasAccessor && node.__dataHasAccessor[binding.target]) {
let value = props[path];
path = Polymer.Path.translate(part.source, binding.target, path);
if (node._setPendingPropertyOrPath(path, value, false, true)) {
if (node._setPendingPropertyOrPath(path, value, false, true, forceChange)) {
inst._enqueueClient(node);
}
} else {
let value = info.evaluator._evaluateBinding(inst, part, path, props, oldProps, hasPaths);
// Propagate value to child
applyBindingValue(inst, node, binding, part, value);
applyBindingValue(inst, node, binding, part, value, forceChange);
}
}

Expand All @@ -580,7 +581,7 @@
* @param {*} value Value to set
* @private
*/
function applyBindingValue(inst, node, binding, part, value) {
function applyBindingValue(inst, node, binding, part, value, forceChange) {
value = computeBindingValue(node, value, binding, part);
if (Polymer.sanitizeDOMValue) {
value = Polymer.sanitizeDOMValue(value, binding.target, binding.kind, node);
Expand All @@ -593,7 +594,7 @@
let prop = binding.target;
if (node.__dataHasAccessor && node.__dataHasAccessor[prop]) {
if (!node[TYPES.READ_ONLY] || !node[TYPES.READ_ONLY][prop]) {
if (node._setPendingProperty(prop, value)) {
if (node._setPendingProperty(prop, value, null, forceChange)) {
inst._enqueueClient(node);
}
}
Expand Down Expand Up @@ -1334,7 +1335,7 @@
* the pending changes bag.
* @protected
*/
_setPendingPropertyOrPath(path, value, shouldNotify, isPathNotification) {
_setPendingPropertyOrPath(path, value, shouldNotify, isPathNotification, forceChange) {
if (isPathNotification ||
Polymer.Path.root(Array.isArray(path) ? path[0] : path) !== path) {
// Dirty check changes being set to a path against the actual object,
Expand All @@ -1354,13 +1355,13 @@
}
}
this.__dataHasPaths = true;
if (this._setPendingProperty(/**@type{string}*/(path), value, shouldNotify)) {
if (this._setPendingProperty(/**@type{string}*/(path), value, shouldNotify, forceChange)) {
computeLinkedPaths(this, path, value);
return true;
}
} else {
if (this.__dataHasAccessor && this.__dataHasAccessor[path]) {
return this._setPendingProperty(/**@type{string}*/(path), value, shouldNotify);
return this._setPendingProperty(/**@type{string}*/(path), value, shouldNotify, forceChange);
} else {
this[path] = value;
}
Expand Down Expand Up @@ -1433,10 +1434,11 @@
* @return {boolean} Returns true if the property changed
* @override
*/
_setPendingProperty(property, value, shouldNotify) {
_setPendingProperty(property, value, shouldNotify, forceChange) {
let isPath = this.__dataHasPaths && Polymer.Path.isPath(property);
let prevProps = isPath ? this.__dataTemp : this.__data;
if (this._shouldPropertyChange(property, value, prevProps[property])) {
if (this._shouldPropertyChange(property, value, prevProps[property]) ||
(forceChange && (typeof value === 'object' && value !== null))) {
if (!this.__dataPending) {
this.__dataPending = {};
this.__dataOld = {};
Expand Down Expand Up @@ -1623,7 +1625,7 @@
*
* @override
*/
_propertiesChanged(currentProps, changedProps, oldProps) {
_propertiesChanged(currentProps, changedProps, oldProps, forceChange) {
// ----------------------------
// let c = Object.getOwnPropertyNames(changedProps || {});
// window.debug && console.group(this.localName + '#' + this.id + ': ' + c);
Expand All @@ -1638,7 +1640,7 @@
let notifyProps = this.__dataToNotify;
this.__dataToNotify = null;
// Propagate properties to clients
this._propagatePropertyChanges(changedProps, oldProps, hasPaths);
this._propagatePropertyChanges(changedProps, oldProps, hasPaths, forceChange);
// Flush clients
this._flushClients();
// Reflect properties
Expand Down Expand Up @@ -1667,14 +1669,14 @@
* @param {boolean} hasPaths True with `props` contains one or more paths
* @protected
*/
_propagatePropertyChanges(changedProps, oldProps, hasPaths) {
_propagatePropertyChanges(changedProps, oldProps, hasPaths, forceChange) {
if (this[TYPES.PROPAGATE]) {
runEffects(this, this[TYPES.PROPAGATE], changedProps, oldProps, hasPaths);
runEffects(this, this[TYPES.PROPAGATE], changedProps, oldProps, hasPaths, null, {forceChange});
}
let templateInfo = this.__templateInfo;
while (templateInfo) {
runEffects(this, templateInfo.propertyEffects, changedProps, oldProps,
hasPaths, templateInfo.nodeList);
hasPaths, templateInfo.nodeList, {forceChange});
templateInfo = templateInfo.nextTemplateInfo;
}
}
Expand Down Expand Up @@ -2622,6 +2624,16 @@
return value;
}

_flushProperties(forceChange) {
if (this.__dataPending && this.__dataOld) {
let changedProps = this.__dataPending;
this.__dataPending = null;
this.__dataCounter++;
this._propertiesChanged(this.__data, changedProps, this.__dataOld, forceChange);
this.__dataCounter--;
}
}

}

// make a typing for closure :P
Expand Down
89 changes: 89 additions & 0 deletions test/smoke/dom-if-changes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
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
-->
<html>
<head>
<title>data-table</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>

<dom-module id="my-outer-element">
<template>
<style>
:host {
display: block;
}
</style>
<div style="width: 100px; height: 40px; background-color:red" on-click="ttt"></div>
<template is='dom-if' if='[[b]]'>
<my-inner-element prop="[[p]]"></my-inner-element>
</template>
</template>
</dom-module>
<dom-module id="my-inner-element">
<template>
Inner: [[prop]]
</template>
</dom-module>

<script>
HTMLImports.whenReady(function() {
class MyOuterElement extends Polymer.Element {
static get is() { return 'my-outer-element'; }
static get properties() {
return {
b: Boolean,
p: Array,
}
}
static get observers() {
return [
'obs(p.*)'
];
}
obs() {
this.b = !this.b;
}
constructor() {
super();
this.b = true;
this.p = ['0'];
}
ttt() {
this.set('p.0', this.p[0] + '!');
console.log(this.p[0]);
}
}
class MyInnerElement extends Polymer.Element {
static get is() { return 'my-inner-element'; }
static get properties() {
return {
prop: Array,
}
}
}
customElements.define(MyOuterElement.is, MyOuterElement);
customElements.define(MyInnerElement.is, MyInnerElement);
});

</script>

<my-outer-element></my-outer-element>

</body>
</html>


</body>
</html>