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

Use objectAt to fetch rowValues (cause meta alloc) #727

Merged
merged 3 commits into from
Jul 19, 2019
Merged
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
37 changes: 34 additions & 3 deletions addon/-private/collapse-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,44 @@ export const TableRowMeta = EmberObject.extend({
let meta = this;
let currentValue = rowValue;

// If the parent is selected all of its children are selected. Since
// the current row is going to be removed from the selection, add all
// the sibling rows at each level of its grouping to be explicitly
// selected so their state remains stable.
while (get(meta, '_parentMeta.isSelected')) {
meta = get(meta, '_parentMeta');

for (let child of get(meta, '_rowValue.children')) {
if (child !== currentValue) {
selection.add(child);
// Iterate from the parent meta to the "next" tree node. Since this
// is a group it will have at least one child, so there should be at
// least one next row to iterate over.
let expectedChildDepth = get(meta, 'depth') + 1;
let childIndex = get(meta, 'index'); // will be incremented by 1 before use
let child;
while ((child = tree.objectAt(++childIndex))) {
// The currentValue is being toggled, don't add it to the selection
if (child === currentValue) {
continue;
}

// If the depth of the row is lower than the expectedChildDepth a
// non-child meta has been found (a sibling or something higher.
// That means iterating children is complete, so break.
//
// If the depth is higher than expected then children of a child
// group are being iterated. Skip over them, but don't break since
// there may be a leaf child after a group child.
let childMeta = rowMetaCache.get(child);
let childDepth = get(childMeta, 'depth');
if (childDepth < expectedChildDepth) {
break;
}
if (childDepth > expectedChildDepth) {
continue;
}

// Else, this is a child node which must be explictly selected.
// Add it to the list.
selection.add(child);
}

selection.delete(currentValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export default class SimpleController extends Controller {
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
],
},
];
Expand Down