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

Unified Diff: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js

Issue 2592513002: DevTools: Add Closure docs and clean up UISourceCode (Closed)
Patch Set: Fast return Created 4 years 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
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/script-snippet-model.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js
diff --git a/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js b/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js
index 0979e6e0b301302803df054450025f58d676a19e..7872902a8c3287ff3140427ab810e47d36659a70 100644
--- a/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js
+++ b/third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js
@@ -56,8 +56,6 @@ Workspace.UISourceCode = class extends Common.Object {
}
this._contentType = contentType;
- /** @type {?function(?string)} */
- this._requestContentCallback = null;
/** @type {?Promise<?string>} */
this._requestContentPromise = null;
/** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */
@@ -68,6 +66,18 @@ Workspace.UISourceCode = class extends Common.Object {
/** @type {!Array<!Workspace.UISourceCode.Message>} */
this._messages = [];
+
+ this._contentLoaded = false;
+ /** @type {?string} */
+ this._content = null;
+ this._forceLoadOnCheckContent = false;
+ this._checkingContent = false;
+ /** @type {?string} */
+ this._lastAcceptedContent = null;
+ /** @type {?string} */
+ this._workingCopy = null;
+ /** @type {?function() : string} */
+ this._workingCopyGetter = null;
}
/**
@@ -210,15 +220,21 @@ Workspace.UISourceCode = class extends Common.Object {
* @return {!Promise<?string>}
*/
requestContent() {
- if (this._content || this._contentLoaded)
- return Promise.resolve(this._content);
- var promise = this._requestContentPromise;
- if (!promise) {
- promise = new Promise(fulfill => this._requestContentCallback = fulfill);
- this._requestContentPromise = promise;
- this._project.requestFileContent(this, this._fireContentAvailable.bind(this));
+ if (this._requestContentPromise)
+ return this._requestContentPromise;
+
+ if (this._contentLoaded) {
+ this._requestContentPromise = Promise.resolve(this._content);
+ } else {
+ var fulfill;
+ this._requestContentPromise = new Promise(x => fulfill = x);
+ this._project.requestFileContent(this, content => {
+ this._contentLoaded = true;
+ this._content = content;
+ fulfill(content);
+ });
}
- return promise;
+ return this._requestContentPromise;
}
checkContentUpdated() {
@@ -243,11 +259,11 @@ Workspace.UISourceCode = class extends Common.Object {
this.setWorkingCopy(workingCopy);
return;
}
- if (typeof this._lastAcceptedContent === 'string' && this._lastAcceptedContent === updatedContent)
+ if (this._lastAcceptedContent === updatedContent)
return;
if (this._content === updatedContent) {
- delete this._lastAcceptedContent;
+ this._lastAcceptedContent = null;
return;
}
@@ -297,9 +313,10 @@ Workspace.UISourceCode = class extends Common.Object {
* @param {boolean} committedByUser
*/
_contentCommitted(content, committedByUser) {
- delete this._lastAcceptedContent;
+ this._lastAcceptedContent = null;
this._content = content;
this._contentLoaded = true;
+ this._requestContentPromise = null;
var lastRevision = this.history.length ? this.history[this.history.length - 1] : null;
if (!lastRevision || lastRevision._content !== this._content) {
@@ -385,11 +402,11 @@ Workspace.UISourceCode = class extends Common.Object {
workingCopy() {
if (this._workingCopyGetter) {
this._workingCopy = this._workingCopyGetter();
- delete this._workingCopyGetter;
+ this._workingCopyGetter = null;
}
if (this.isDirty())
- return this._workingCopy;
- return this._content;
+ return /** @type {string} */ (this._workingCopy);
+ return this._content || '';
}
resetWorkingCopy() {
@@ -398,8 +415,8 @@ Workspace.UISourceCode = class extends Common.Object {
}
_innerResetWorkingCopy() {
- delete this._workingCopy;
- delete this._workingCopyGetter;
+ this._workingCopy = null;
+ this._workingCopyGetter = null;
}
/**
@@ -407,10 +424,13 @@ Workspace.UISourceCode = class extends Common.Object {
*/
setWorkingCopy(newWorkingCopy) {
this._workingCopy = newWorkingCopy;
- delete this._workingCopyGetter;
+ this._workingCopyGetter = null;
this._workingCopyChanged();
}
+ /**
+ * @param {function(): string } workingCopyGetter
+ */
setWorkingCopyGetter(workingCopyGetter) {
this._workingCopyGetter = workingCopyGetter;
this._workingCopyChanged();
@@ -427,7 +447,7 @@ Workspace.UISourceCode = class extends Common.Object {
if (!this._workingCopyGetter)
return;
this._workingCopy = this._workingCopyGetter();
- delete this._workingCopyGetter;
+ this._workingCopyGetter = null;
}
commitWorkingCopy() {
@@ -439,7 +459,7 @@ Workspace.UISourceCode = class extends Common.Object {
* @return {boolean}
*/
isDirty() {
- return typeof this._workingCopy !== 'undefined' || typeof this._workingCopyGetter !== 'undefined';
+ return this._workingCopy !== null || this._workingCopyGetter !== null;
}
/**
@@ -482,20 +502,6 @@ Workspace.UISourceCode = class extends Common.Object {
}
/**
- * @param {?string} content
- */
- _fireContentAvailable(content) {
- this._contentLoaded = true;
- this._content = content;
-
- var callback = this._requestContentCallback;
- this._requestContentCallback = null;
- this._requestContentPromise = null;
-
- callback.call(null, content);
- }
-
- /**
* @return {boolean}
*/
contentLoaded() {
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/script-snippet-model.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698