From 634d4fece2f800d95104eaa4cedf62b751f2a3d9 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 17 Apr 2019 13:03:18 -0700 Subject: [PATCH] Added more inline comments --- src/devtools/store.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/devtools/store.js b/src/devtools/store.js index 817af3daf0..99ba142fca 100644 --- a/src/devtools/store.js +++ b/src/devtools/store.js @@ -458,6 +458,8 @@ export default class Store extends EventEmitter { } if (element.isCollapsed) { + // There's nothing to change in this case. + // We can exit early (without even emiting a "mutated" event). return; } @@ -469,6 +471,8 @@ export default class Store extends EventEmitter { element.parentID ): any): Element); while (parentElement != null) { + // We don't need to break on a collapsed parent in the same way as the expand case below. + // That's because collapsing a node doesn't "bubble" and affect its parents. parentElement.weight += weightDelta; parentElement = this._idToElement.get(parentElement.parentID); } @@ -490,6 +494,9 @@ export default class Store extends EventEmitter { while (parentElement != null) { parentElement.weight += weightDelta; if (parentElement.isCollapsed) { + // It's important to break on a collapsed parent when expanding nodes. + // That's because expanding a node "bubbles" up and expands all parents as well. + // Breaking in this case prevents us from over-incrementing the expanded weights. break; } parentElement = this._idToElement.get(parentElement.parentID);