Skip to content

Commit

Permalink
perf: do not refresh when expanding already selected node (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jledentu committed May 5, 2023
1 parent 8cb889d commit f2d55f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/__tests__/Finder.test.js
Expand Up @@ -492,6 +492,21 @@ describe("Finder", () => {
]);
});

it("should not emit the `expand` event when expanding the already expanded node", async () => {
const wrapper = mount(Finder, {
propsData: {
tree,
selectable: true,
defaultExpanded: "test112",
},
});

wrapper.vm.expand("test112");
await wrapper.vm.$nextTick();

expect(wrapper.emitted().expand).toBeFalsy();
});

it("should accept a 'sourceEvent' argument", async () => {
const wrapper = mount(Finder, {
props: {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/tree-model.js
Expand Up @@ -125,6 +125,9 @@ export default class extends EventManager {
* @param {string} sourceEvent Name of the event that triggered the expand
*/
expandNode(nodeId, sourceEvent) {
if (this.expanded && nodeId === this.expanded[this.expanded.length - 1]) {
return;
}
this.expanded = path(nodeId, this.nodesMap);
this.expandedWithoutFilter = this.expanded;
this._updateVisibleTree();
Expand Down

0 comments on commit f2d55f3

Please sign in to comment.