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

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

Issue 2729783002: DevTools: Diff subsystem (Closed)
Patch Set: this 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 /**
6 * @param {!Workspace.UISourceCode} uiSourceCode
7 * @return {!Promise<!Diff.Diff.DiffArray>}
8 */
9 WorkspaceDiff.requestDiff = function(uiSourceCode) {
10 return WorkspaceDiff._uiSourceCodeDiff(uiSourceCode).requestDiff();
11 };
12
13 /**
14 * @param {!Workspace.UISourceCode} uiSourceCode
15 * @param {function(!WorkspaceDiff.DiffChangedEvent)} callback
16 * @param {!Object=} thisObj
17 */
18 WorkspaceDiff.addThrottledDiffListener = function(uiSourceCode, callback, thisOb j) {
lushnikov 2017/03/08 17:55:16 .subscribeToDiffChange(..)
einbinder 2017/03/08 23:12:47 Done.
19 WorkspaceDiff._uiSourceCodeDiff(uiSourceCode).on(WorkspaceDiff.DiffChangedEven t, callback, thisObj);
20 };
21
22 /**
23 * @param {!Workspace.UISourceCode} uiSourceCode
24 * @param {function(!WorkspaceDiff.DiffChangedEvent)} callback
25 * @param {!Object=} thisObj
26 */
27 WorkspaceDiff.removeThrottledDiffListener = function(uiSourceCode, callback, thi sObj) {
28 WorkspaceDiff._uiSourceCodeDiff(uiSourceCode).off(WorkspaceDiff.DiffChangedEve nt, callback, thisObj);
29 };
30
31 /**
32 * @param {!Workspace.UISourceCode} uiSourceCode
33 * @return {!WorkspaceDiff._UISourceCodeDiff}
34 */
35 WorkspaceDiff._uiSourceCodeDiff = function(uiSourceCode) {
36 if (!uiSourceCode[WorkspaceDiff._uiSourceCodeDiff.Symbol])
37 uiSourceCode[WorkspaceDiff._UISourceCodeDiff.Symbol] = new WorkspaceDiff._UI SourceCodeDiff(uiSourceCode);
38 return uiSourceCode[WorkspaceDiff._UISourceCodeDiff.Symbol];
39 };
40
41 WorkspaceDiff._UISourceCodeDiff = class extends Common.Object {
lushnikov 2017/03/08 17:55:16 Let's do the following: 1. introduce class Worksp
einbinder 2017/03/08 23:12:47 This will pull the Diff module into autostart.
42 /**
43 * @param {!Workspace.UISourceCode} uiSourceCode
44 */
45 constructor(uiSourceCode) {
46 super();
47 this._uiSourceCode = uiSourceCode;
48 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyChang ed, this._uiSourceCodeChanged, this);
49 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCommi tted, this._uiSourceCodeChanged, this);
50 this._requestDiffPromise = null;
51 this._pendingChanges = null;
52 }
53
54 _uiSourceCodeChanged() {
55 if (this._pendingChanges) {
56 clearTimeout(this._pendingChanges);
57 this._pendingChanges = null;
58 }
59 this._requestDiffPromise = null;
60 if (!this.hasEventListeners(WorkspaceDiff.DiffChangedEvent))
lushnikov 2017/03/08 17:55:16 we can omit this check - there's already one in th
einbinder 2017/03/08 23:12:47 Removed.
61 return;
62
63 var content = this._uiSourceCode.content();
64 if (content && content.length < 65536)
lushnikov 2017/03/08 17:55:16 typeof content === 'string'
65 emitDiffChanged.call(this);
lushnikov 2017/03/08 17:55:16 let's always call the throttled event through time
einbinder 2017/03/08 23:12:47 Done.
66 else
67 this._pendingChanges = setTimeout(emitDiffChanged.bind(this), 200);
68
69 /**
70 * @this {WorkspaceDiff._UISourceCodeDiff}
71 */
72 function emitDiffChanged() {
73 this.emit(new WorkspaceDiff.DiffChangedEvent());
74 this._pendingChanges = null;
75 }
76 }
77
78 /**
79 * @return {!Promise<!Diff.Diff.DiffArray>}
80 */
81 requestDiff() {
82 if (!this._requestDiffPromise) {
83 this._requestDiffPromise = this._uiSourceCode.requestOriginalContent().the n(baseline => {
84 var current = this._uiSourceCode.workingCopy();
85 var diff = Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n')) ;
86 return diff || [];
87 });
88 }
89 return this._requestDiffPromise;
90 }
91 };
92
93 /**
94 * @implements {Common.Emittable}
95 */
96 WorkspaceDiff.DiffChangedEvent = class {};
97
98 WorkspaceDiff._UISourceCodeDiff.Symbol = Symbol('WorkspaceDiff._UISourceCodeDiff .Symbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698