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

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

Issue 2729783002: DevTools: Diff subsystem (Closed)
Patch Set: requestDiff Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/workspace_diff/UISourceCodeDiff.js
diff --git a/third_party/WebKit/Source/devtools/front_end/workspace_diff/UISourceCodeDiff.js b/third_party/WebKit/Source/devtools/front_end/workspace_diff/UISourceCodeDiff.js
new file mode 100644
index 0000000000000000000000000000000000000000..7ca0ae2d916926bae5153c40cb62832b8a266cdc
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/workspace_diff/UISourceCodeDiff.js
@@ -0,0 +1,74 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+WorkspaceDiff.UISourceCodeDiff = class extends Common.Object {
+ /**
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ */
+ constructor(uiSourceCode) {
+ super();
+ this.uiSourceCode = uiSourceCode;
lushnikov 2017/03/04 04:00:28 private?
einbinder 2017/03/07 06:03:31 Ok
+ uiSourceCode.addEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeChanged.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
+ uiSourceCode.addEventListener(
+ Workspace.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeChanged.bind(this));
lushnikov 2017/03/04 04:00:28 ditt
einbinder 2017/03/07 06:03:31 Done.
+ this._requestDiffPromise = null;
+ this._pendingChanges = null;
+ }
+
+ /**
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ * @return {!WorkspaceDiff.UISourceCodeDiff}
+ */
+ static forUISourceCode(uiSourceCode) {
+ if (!uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol])
lushnikov 2017/03/04 04:00:28 symbol should be private
einbinder 2017/03/07 06:03:31 Done.
+ uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol] = new WorkspaceDiff.UISourceCodeDiff(uiSourceCode);
+ return uiSourceCode[WorkspaceDiff.UISourceCodeDiff.Symbol];
+ }
+
+ _uiSourceCodeChanged() {
+ if (this._pendingChanges) {
+ clearTimeout(this._pendingChanges);
+ this._pendingChanges = null;
+ }
+ 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.
+ if (!this.hasEventListeners(WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent))
+ return;
+
+ var content = this.uiSourceCode.content();
+ if (content && content.length < 65536)
+ emitDiffChanged.call(this);
+ else
+ 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
+
+ /**
+ * @this {WorkspaceDiff.UISourceCodeDiff}
+ */
+ function emitDiffChanged() {
+ this.emit(new WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent());
+ this._pendingChanges = null;
+ }
+ }
+
+ /**
+ * @return {!Promise<!Diff.Diff.DiffArray>}
+ */
+ 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.
+ if (!this._requestDiffPromise) {
+ this._requestDiffPromise = this.uiSourceCode.requestOriginalContent().then(baseline => {
+ var current = this.uiSourceCode.workingCopy();
+ var diff = Diff.Diff.lineDiff(baseline.split('\n'), current.split('\n'));
+ return diff || [];
+ });
+ }
+ return this._requestDiffPromise;
+ }
+};
+
+/**
+ * @implements {Common.Emittable}
+ */
+WorkspaceDiff.UISourceCodeDiff.DiffChangedEvent = class {};
+
+WorkspaceDiff.UISourceCodeDiff.Symbol = Symbol('WorkspaceDiff.UISourceCodeDiff.Symbol');

Powered by Google App Engine
This is Rietveld 408576698