Chromium Code Reviews| 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..2b261f5e104b7cd94f4338a0a4b1018d54d0661b 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; |
|
einbinder
2016/12/19 21:34:16
Make things explicit. Never undefined.
|
| + /** @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,16 @@ Workspace.UISourceCode = class extends Common.Object { |
| * @return {!Promise<?string>} |
| */ |
| requestContent() { |
| - if (this._content || this._contentLoaded) |
|
einbinder
2016/12/19 21:34:16
Just return the same loading promise. Makes things
|
| - 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) { |
| + 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 +254,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 +308,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 = Promise.resolve(/** @type {?string} */ (content)); |
|
einbinder
2016/12/19 21:34:16
Closure gets confused with {?string} and {string}.
lushnikov
2016/12/19 23:32:13
let's clean the promise here to not do unnecessary
einbinder
2016/12/19 23:48:49
Done.
|
| var lastRevision = this.history.length ? this.history[this.history.length - 1] : null; |
| if (!lastRevision || lastRevision._content !== this._content) { |
| @@ -385,11 +397,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); |
|
einbinder
2016/12/19 21:34:16
we know that workingCopyGetter is null, and it is
|
| + return this._content || ''; |
| } |
| resetWorkingCopy() { |
| @@ -398,8 +410,8 @@ Workspace.UISourceCode = class extends Common.Object { |
| } |
| _innerResetWorkingCopy() { |
| - delete this._workingCopy; |
| - delete this._workingCopyGetter; |
| + this._workingCopy = null; |
| + this._workingCopyGetter = null; |
| } |
| /** |
| @@ -407,10 +419,13 @@ Workspace.UISourceCode = class extends Common.Object { |
| */ |
| setWorkingCopy(newWorkingCopy) { |
| this._workingCopy = newWorkingCopy; |
| - delete this._workingCopyGetter; |
| + this._workingCopyGetter = null; |
| this._workingCopyChanged(); |
| } |
| + /** |
| + * @param {function(): string } workingCopyGetter |
| + */ |
|
einbinder
2016/12/19 21:34:16
Typing!
|
| setWorkingCopyGetter(workingCopyGetter) { |
| this._workingCopyGetter = workingCopyGetter; |
| this._workingCopyChanged(); |
| @@ -427,7 +442,7 @@ Workspace.UISourceCode = class extends Common.Object { |
| if (!this._workingCopyGetter) |
| return; |
| this._workingCopy = this._workingCopyGetter(); |
| - delete this._workingCopyGetter; |
| + this._workingCopyGetter = null; |
| } |
| commitWorkingCopy() { |
| @@ -439,7 +454,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 +497,6 @@ Workspace.UISourceCode = class extends Common.Object { |
| } |
| /** |
| - * @param {?string} content |
| - */ |
| - _fireContentAvailable(content) { |
|
einbinder
2016/12/19 21:34:16
This gets inlined.
|
| - this._contentLoaded = true; |
| - this._content = content; |
| - |
| - var callback = this._requestContentCallback; |
| - this._requestContentCallback = null; |
| - this._requestContentPromise = null; |
| - |
| - callback.call(null, content); |
| - } |
| - |
| - /** |
| * @return {boolean} |
| */ |
| contentLoaded() { |