Skip to content

Commit ef0efa6

Browse files
committed
Add hasPaths optimziation
1 parent 9ed3189 commit ef0efa6

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lib/mixins/property-effects.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,20 +439,21 @@ const TRANSITIVE_DEPENDENCY = '~transitive~dependency~';
439439
* @param {?Object} changedProps Bag of current property changes
440440
* @param {?Object} oldProps Bag of previous values for changed properties
441441
* @param {?} info Effect metadata
442+
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
442443
* @return {void}
443444
* @private
444445
*/
445-
function runComputedEffect(inst, property, changedProps, oldProps, info) {
446+
function runComputedEffect(inst, property, changedProps, oldProps, info, hasPaths) {
446447
if (orderedComputed) {
447448
// Compute any computed dependencies first; this recurses through the
448449
// dependency graph to ensure computed properties are never computed with
449450
// dependencies that may become invalidated later in this turn
450-
computeDependencies(inst, info, changedProps, oldProps);
451+
computeDependencies(inst, info, changedProps, oldProps, hasPaths);
451452
// If the dependency was not transitive, it's definitely dirty and needs to
452453
// be computed; if it is transitive, check its arguments against the current
453454
// changed props and only re-compute if it is dirty
454455
if (property === TRANSITIVE_DEPENDENCY &&
455-
!computedPropertyIsDirty(inst, info, changedProps)) {
456+
!computedPropertyIsDirty(inst, info, changedProps, hasPaths)) {
456457
return;
457458
}
458459
}
@@ -502,16 +503,17 @@ function runComputedEffect(inst, property, changedProps, oldProps, info) {
502503
* @param {Object} info Effect metadata
503504
* @param {Object} changedProps Bag of current property changes
504505
* @param {Object} oldProps Bag of previous values for changed properties
506+
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
505507
* @return {void}
506508
* @private
507509
*/
508-
function computeDependencies(inst, info, changedProps, oldProps) {
510+
function computeDependencies(inst, info, changedProps, oldProps, hasPaths) {
509511
let deps = computedDependenciesFor(inst, info);
510512
if (deps.length) {
511513
deps.forEach(depInfo => {
512514
if (depInfo.lastRun !== info.lastRun) {
513515
depInfo.lastRun = info.lastRun;
514-
runComputedEffect(inst, TRANSITIVE_DEPENDENCY, changedProps, oldProps, depInfo);
516+
runComputedEffect(inst, TRANSITIVE_DEPENDENCY, changedProps, oldProps, depInfo, hasPaths);
515517
}
516518
});
517519
}
@@ -523,12 +525,13 @@ function runComputedEffect(inst, property, changedProps, oldProps, info) {
523525
* @param {!Polymer_PropertyEffects} inst The instance to test
524526
* @param {?} info Effect metadata
525527
* @param {Object} changedProps Bag of current property changes
528+
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
526529
* @return {boolean} true when the computed effect should be re-calculated
527530
* @private
528531
*/
529-
function computedPropertyIsDirty(inst, info, changedProps) {
530-
return info.dynamicFn && propertyIsDirty(inst, {name: info.methodName}, changedProps) ||
531-
info.args.some(arg => propertyIsDirty(inst, arg, changedProps));
532+
function computedPropertyIsDirty(inst, info, changedProps, hasPaths) {
533+
return info.dynamicFn && propertyIsDirty(inst, {rootProperty: info.methodName}, changedProps, hasPaths) ||
534+
info.args.some(arg => propertyIsDirty(inst, arg, changedProps, hasPaths));
532535
}
533536

534537
/**
@@ -537,17 +540,23 @@ function computedPropertyIsDirty(inst, info, changedProps) {
537540
* @param {!Polymer_PropertyEffects} inst The instance to test
538541
* @param {DataTrigger} trigger Descriptor
539542
* @param {Object} changedProps Bag of current property changes
543+
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
540544
* @return {boolean} true when the property is dirty
541545
* @private
542546
*/
543-
function propertyIsDirty(inst, trigger, changedProps) {
544-
return [changedProps, inst.__dataPending].some(props => {
545-
for (let p in props) {
546-
if (pathMatchesTrigger(p, trigger)) {
547-
return true;
547+
function propertyIsDirty(inst, trigger, changedProps, hasPaths) {
548+
if (hasPaths) {
549+
[changedProps, inst.__dataPending].some(props => {
550+
for (let p in props) {
551+
if (pathMatchesTrigger(p, trigger)) {
552+
return true;
553+
}
548554
}
549-
}
550-
});
555+
});
556+
} else {
557+
return changedProps && trigger.rootProperty in changedProps ||
558+
inst.__dataPending && trigger.rootProperty in inst.__dataPending;
559+
}
551560
}
552561

553562
/**

0 commit comments

Comments
 (0)