Initialize diff cursors as soon as diffs render content
Previously diff cursors initialized when their diffs completely finished rendering. This means waiting longer than needed because the diff render process includes processing and rendering syntax highlights whereas the diff cursor only needs to wait on the content of the diff. With this change diffs fire an event when they've finished with their content only, and diff cursors await this event instead of the full render. Bug: Issue 5681 Change-Id: Ida9da83a20fe4c2dcd8920304504ec7e1185eb5d
This commit is contained in:
@@ -80,6 +80,13 @@ limitations under the License.
|
||||
* @event render
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fired when the diff finishes rendering text content, but not
|
||||
* necessarily syntax highlights.
|
||||
*
|
||||
* @event render-content
|
||||
*/
|
||||
|
||||
properties: {
|
||||
diff: Object,
|
||||
viewMode: String,
|
||||
@@ -137,11 +144,13 @@ limitations under the License.
|
||||
|
||||
reporting.time(TimingLabel.TOTAL);
|
||||
reporting.time(TimingLabel.CONTENT);
|
||||
this.fire('render-start');
|
||||
this.dispatchEvent(new CustomEvent('render-start', {bubbles: true}));
|
||||
return this.$.processor.process(this.diff.content).then(function() {
|
||||
if (this.isImageDiff) {
|
||||
this._builder.renderDiffImages();
|
||||
}
|
||||
this.dispatchEvent(new CustomEvent('render-content',
|
||||
{bubbles: true}));
|
||||
|
||||
if (this._anyLineTooLong()) {
|
||||
this.$.syntaxLayer.enabled = false;
|
||||
@@ -152,7 +161,7 @@ limitations under the License.
|
||||
return this.$.syntaxLayer.process().then(function() {
|
||||
reporting.timeEnd(TimingLabel.SYNTAX);
|
||||
reporting.timeEnd(TimingLabel.TOTAL);
|
||||
this.fire('render');
|
||||
this.dispatchEvent(new CustomEvent('render', {bubbles: true}));
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
@@ -807,10 +807,13 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('render-start and render are fired', function(done) {
|
||||
var fireStub = sinon.stub(element, 'fire');
|
||||
var dispatchEventStub = sinon.stub(element, 'dispatchEvent');
|
||||
element.render({left: [], right: []}, {}).then(function() {
|
||||
assert.isTrue(fireStub.calledWithExactly('render-start'));
|
||||
assert.isTrue(fireStub.calledWithExactly('render'));
|
||||
var firedEventTypes = dispatchEventStub.getCalls()
|
||||
.map(function(c) { return c.args[0].type; });
|
||||
assert.include(firedEventTypes, 'render-start');
|
||||
assert.include(firedEventTypes, 'render-content');
|
||||
assert.include(firedEventTypes, 'render');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -360,7 +360,7 @@
|
||||
i < splice.index + splice.addedCount;
|
||||
i++) {
|
||||
this.listen(this.diffs[i], 'render-start', '_handleDiffRenderStart');
|
||||
this.listen(this.diffs[i], 'render', 'handleDiffUpdate');
|
||||
this.listen(this.diffs[i], 'render-content', 'handleDiffUpdate');
|
||||
}
|
||||
|
||||
for (i = 0;
|
||||
|
||||
Reference in New Issue
Block a user