Remove event handlers from individual lines in file list

In order to speed up file list processing for large numbers of files,
event handlers have been removed on a per-line basis and instead
are listened for in a parent container that handles them according to
the click target.

With a sample of 1300 files, the dom-repeat after clicking 'show all'
gets rendered 25% faster.

Bug: Issue 5612
Change-Id: Idc1ba6e0810d5d4c6f36e76667c3748becc1358a
This commit is contained in:
Becky Siegel
2017-03-31 16:09:23 -07:00
parent 7261ceb876
commit 435c79a4c6
3 changed files with 130 additions and 109 deletions

View File

@@ -637,10 +637,13 @@ limitations under the License.
flushAsynchronousOperations();
var fileRows =
Polymer.dom(element.root).querySelectorAll('.row:not(.header)');
// Because the label surrounds the input, the tap event is triggered
// there first.
var showHideLabel = fileRows[0].querySelector('label.show-hide');
var showHideCheck = fileRows[0].querySelector(
'input.show-hide[type="checkbox"]');
assert.isNotOk(showHideCheck.checked);
MockInteractions.tap(showHideCheck);
MockInteractions.tap(showHideLabel);
assert.isOk(showHideCheck.checked);
assert.notEqual(element._expandedFilePaths.indexOf('myfile.txt'), -1);
});
@@ -763,18 +766,18 @@ limitations under the License.
// Remove href attribute so the app doesn't route to a diff view
commitMsgFile.removeAttribute('href');
var hiddenChangeSpy = sandbox.spy(element, '_handleHiddenChange');
var togglePathSpy = sandbox.spy(element, '_togglePathExpanded');
MockInteractions.tap(commitMsgFile);
flushAsynchronousOperations();
assert(hiddenChangeSpy.notCalled, 'file is opened as diff view');
assert(togglePathSpy.notCalled, 'file is opened as diff view');
assert.isNotOk(element.$$('.expanded'));
element._userPrefs = {expand_inline_diffs: true};
flushAsynchronousOperations();
MockInteractions.tap(commitMsgFile);
flushAsynchronousOperations();
assert(hiddenChangeSpy.calledOnce, 'file is expanded');
assert(togglePathSpy.calledOnce, 'file is expanded');
assert.isOk(element.$$('.expanded'));
});
@@ -812,32 +815,37 @@ limitations under the License.
element.push('_expandedFilePaths', path);
});
suite('_handleFileTap', function() {
suite('_handleFileListTap', function() {
function testForModifier(modifier) {
var e = {preventDefault: function() {}};
e.detail = {sourceEvent: {}};
e.target = {
dataset: {path: '/test'},
classList: element.classList,
};
e.detail.sourceEvent[modifier] = true;
var hiddenChangeStub = sandbox.stub(element, '_handleHiddenChange');
var togglePathStub = sandbox.stub(element, '_togglePathExpanded');
element._userPrefs = { expand_inline_diffs: true };
element._handleFileTap(e);
assert.isFalse(hiddenChangeStub.called);
element._handleFileListTap(e);
assert.isFalse(togglePathStub.called);
e.detail.sourceEvent[modifier] = false;
element._handleFileTap(e);
assert.equal(hiddenChangeStub.callCount, 1);
element._handleFileListTap(e);
assert.equal(togglePathStub.callCount, 1);
element._userPrefs = { expand_inline_diffs: false };
element._handleFileTap(e);
assert.equal(hiddenChangeStub.callCount, 1);
element._handleFileListTap(e);
assert.equal(togglePathStub.callCount, 1);
}
test('_handleFileTap meta', function() {
test('_handleFileListTap meta', function() {
testForModifier('metaKey');
});
test('_handleFileTap ctrl', function() {
test('_handleFileListTap ctrl', function() {
testForModifier('ctrlKey');
});
});