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

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

Issue 2729783002: DevTools: Diff subsystem (Closed)
Patch Set: subscribe 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) {
lushnikov 2017/03/09 00:09:25 Let's do WorkspaceDiff.workspaceDiff().requestDiff
einbinder 2017/03/09 21:07:20 Done.
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.subscribeToDiffChange = function(uiSourceCode, callback, thisObj) {
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.unsubscribeToDiffChange = function(uiSourceCode, callback, thisObj ) {
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 {
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
61 var content = this._uiSourceCode.content();
62 var delay = (!content || content.length < 65536) ? 0 : 200;
lushnikov 2017/03/09 00:09:25 extract 200 into constant
einbinder 2017/03/09 21:07:20 Done.
63 this._pendingChanges = setTimeout(emitDiffChanged.bind(this), delay);
64
65 /**
66 * @this {WorkspaceDiff._UISourceCodeDiff}
67 */
68 function emitDiffChanged() {
69 this.emit(new WorkspaceDiff.DiffChangedEvent());
70 this._pendingChanges = null;
71 }
72 }
73
74 /**
75 * @return {!Promise<!Diff.Diff.DiffArray>}
76 */
77 requestDiff() {
78 if (!this._requestDiffPromise) {
79 this._requestDiffPromise = this._uiSourceCode.requestOriginalContent().the n(baseline => {
80 var current = this._uiSourceCode.workingCopy();
81 var diff = Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n')) ;
82 return diff || [];
83 });
84 }
85 return this._requestDiffPromise;
86 }
87 };
88
89 /**
90 * @implements {Common.Emittable}
91 */
92 WorkspaceDiff.DiffChangedEvent = class {};
93
94 WorkspaceDiff._UISourceCodeDiff.Symbol = Symbol('WorkspaceDiff._UISourceCodeDiff .Symbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698