Skip to content

Commit

Permalink
Merge pull request #5476 from Polymer/5475-kschaaf-stale-wildcard
Browse files Browse the repository at this point in the history
Ensure that marshalArgs pulls wildcard info value from __data
  • Loading branch information
kevinpschaaf committed Feb 4, 2019
2 parents b77f756 + 67caf45 commit 5501554
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 86 deletions.
58 changes: 27 additions & 31 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,19 @@ function parseArg(rawArg) {
return a;
}

function getArgValue(data, props, path) {
let value = get(data, path);
// when data is not stored e.g. `splices`, get the value from changedProps
// TODO(kschaaf): Note, this can cause a rare issue where the wildcard
// info.value could pull a stale value out of changedProps during a reentrant
// change that sets the value back to undefined.
// https://github.com/Polymer/polymer/issues/5479
if (value === undefined) {
value = props[path];
}
return value;
}

// data api

/**
Expand All @@ -979,11 +992,8 @@ function parseArg(rawArg) {
* @private
*/
function notifySplices(inst, array, path, splices) {
let splicesPath = path + '.splices';
inst.notifyPath(splicesPath, { indexSplices: splices });
inst.notifyPath(path + '.splices', { indexSplices: splices });
inst.notifyPath(path + '.length', array.length);
// Null here to allow potentially large splice records to be GC'ed.
inst.__data[splicesPath] = {indexSplices: null};
}

/**
Expand Down Expand Up @@ -2140,37 +2150,23 @@ export const PropertyEffects = dedupingMixin(superClass => {
*/
_marshalArgs(args, path, props) {
const data = this.__data;
let values = [];
const values = [];
for (let i=0, l=args.length; i<l; i++) {
let arg = args[i];
let name = arg.name;
let v;
if (arg.literal) {
v = arg.value;
} else {
if (arg.structured) {
v = get(data, name);
// when data is not stored e.g. `splices`
if (v === undefined) {
v = props[name];
}
let {name, structured, wildcard, value, literal} = args[i];
if (!literal) {
if (wildcard) {
const matches = isDescendant(name, path);
const pathValue = getArgValue(data, props, matches ? path : name);
value = {
path: matches ? path : name,
value: pathValue,
base: matches ? get(data, name) : pathValue
};
} else {
v = data[name];
value = structured ? getArgValue(data, props, name) : data[name];
}
}
if (arg.wildcard) {
// Only send the actual path changed info if the change that
// caused the observer to run matched the wildcard
let baseChanged = (name.indexOf(path + '.') === 0);
let matches = (path.indexOf(name) === 0 && !baseChanged);
values[i] = {
path: matches ? path : name,
value: matches ? props[path] : v,
base: v
};
} else {
values[i] = v;
}
values[i] = value;
}
return values;
}
Expand Down

0 comments on commit 5501554

Please sign in to comment.