Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace_diff/UISourceCodeDiff.js

Issue 2729783002: DevTools: Diff subsystem (Closed)
Patch Set: requestDiff Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 WorkspaceDiff.UISourceCodeDiff = class extends Common.Object {
6 /**
7 * @param {!Workspace.UISourceCode} uiSourceCode
8 */
9 constructor(uiSourceCode) {
10 super();
11 this.uiSourceCode = uiSourceCode;
lushnikov 2017/03/04 04:00:28 private?
einbinder 2017/03/07 06:03:31 Ok
12 uiSourceCode.addEventListener(
13 Workspace.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeChan ged.bind(this));
lushnikov 2017/03/04 04:00:28 don't bind, pass "this" as a third parameter
einbinder 2017/03/07 06:03:31 Ok
14 uiSourceCode.addEventListener(
15 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeCh anged.bind(this));
lushnikov 2017/03/04 04:00:28 ditt
einbinder 2017/03/07 06:03:31 Done.
16 this._requestDiffPromise = null;
17 this._pendingChanges = null;
18 }
19
20 /**
21 * @param {!Workspace.UISourceCode} uiSourceCode
22 * @return {!WorkspaceDiff.UISourceCodeDiff}
23 */
24 static forUISourceCode(uiSourceCode) {
25 if (!uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol])
lushnikov 2017/03/04 04:00:28 symbol should be private
einbinder 2017/03/07 06:03:31 Done.
26 uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol] = new WorkspaceDiff.UI SourceCodeDiff(uiSourceCode);
27 return uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol];
28 }
29
30 _uiSourceCodeChanged() {
31 if (this._pendingChanges) {
32 clearTimeout(this._pendingChanges);
33 this._pendingChanges = null;
34 }
35 this._requestDiffPromise = null;
lushnikov 2017/03/04 04:00:28 can we fire event here, and defer all the actual w
einbinder 2017/03/07 06:03:31 Done.
36 if (!this.hasEventListeners(WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent) )
37 return;
38
39 var content = this.uiSourceCode.content();
40 if (content && content.length < 65536)
41 emitDiffChanged.call(this);
42 else
43 this._pendingChanges = setTimeout(emitDiffChanged.bind(this), 200);
lushnikov 2017/03/04 04:00:28 you should throttle on the view side, not at the m
einbinder 2017/03/07 06:03:31 If it doesn't get throttled here, then there is no
44
45 /**
46 * @this {WorkspaceDiff.UISourceCodeDiff}
47 */
48 function emitDiffChanged() {
49 this.emit(new WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent());
50 this._pendingChanges = null;
51 }
52 }
53
54 /**
55 * @return {!Promise<!Diff.Diff.DiffArray>}
56 */
57 requestDiff() {
lushnikov 2017/03/04 04:00:28 can we make this accept uiSourceCode as an argumen
einbinder 2017/03/07 06:03:31 Made these top level functions.
58 if (!this._requestDiffPromise) {
59 this._requestDiffPromise = this.uiSourceCode.requestOriginalContent().then (baseline => {
60 var current = this.uiSourceCode.workingCopy();
61 var diff = Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n')) ;
62 return diff || [];
63 });
64 }
65 return this._requestDiffPromise;
66 }
67 };
68
69 /**
70 * @implements {Common.Emittable}
71 */
72 WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent = class {};
73
74 WorkspaceDiff.UISourceCodeDiff.Symbol = Symbol('WorkspaceDiff.UISourceCodeDiff.S ymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698