Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js b/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js |
| index 0a0bd178b62cd8b9dd369500c53d07d7b7e8d650..e8cd1d1b03decbd1b3931cd3ebb58e78efbe7749 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js |
| @@ -49,6 +49,10 @@ Persistence.Persistence = class extends Common.Object { |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this); |
| binding.fileSystem.addEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this); |
| + binding.network.addEventListener( |
| + Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this); |
| + binding.fileSystem.addEventListener( |
| + Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this); |
| this._addFilePathBindingPrefixes(binding.fileSystem.url()); |
| @@ -70,6 +74,10 @@ Persistence.Persistence = class extends Common.Object { |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this); |
| binding.fileSystem.removeEventListener( |
| Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this); |
| + binding.network.removeEventListener( |
| + Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this); |
| + binding.fileSystem.removeEventListener( |
| + Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this); |
| this._removeFilePathBindingPrefixes(binding.fileSystem.url()); |
| @@ -80,6 +88,38 @@ Persistence.Persistence = class extends Common.Object { |
| /** |
| * @param {!Common.Event} event |
| */ |
| + _onWorkingCopyChanged(event) { |
| + var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| + var binding = uiSourceCode[Persistence.Persistence._binding]; |
| + if (!binding || binding[Persistence.Persistence._muteWorkingCopy]) |
| + return; |
| + var other = binding.network === uiSourceCode ? binding.fileSystem : binding.network; |
| + var target = Bindings.NetworkProject.targetForUISourceCode(binding.network); |
| + if (target.isNodeJS()) { |
| + var newContent = uiSourceCode.workingCopy(); |
| + other.requestContent() |
| + .then(currentContent => this._rewrapNodeJSContent(binding, other, currentContent, newContent)) |
|
dgozman
2016/12/01 21:58:12
Use workingCopy() instead of currentContent.
lushnikov
2016/12/02 02:51:36
Done.
|
| + .then(newContent => setWorkingCopy.call(this, () => newContent)); |
| + return; |
| + } |
| + |
| + setWorkingCopy.call(this, () => uiSourceCode.workingCopy()); |
| + |
| + /** |
| + * @param {function():string} workingCopyGetter |
| + * @this {Persistence.Persistence} |
| + */ |
| + function setWorkingCopy(workingCopyGetter) { |
| + binding[Persistence.Persistence._muteWorkingCopy] = true; |
| + other.setWorkingCopyGetter(() => uiSourceCode.workingCopy()); |
|
dgozman
2016/12/01 21:58:12
workingCopyGetter
lushnikov
2016/12/02 02:51:36
Done.
|
| + binding[Persistence.Persistence._muteWorkingCopy] = false; |
| + this._contentSyncedForTest(); |
| + } |
| + } |
| + |
| + /** |
| + * @param {!Common.Event} event |
| + */ |
| _onWorkingCopyCommitted(event) { |
| var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| var binding = uiSourceCode[Persistence.Persistence._binding]; |
| @@ -89,14 +129,23 @@ Persistence.Persistence = class extends Common.Object { |
| var other = binding.network === uiSourceCode ? binding.fileSystem : binding.network; |
| var target = Bindings.NetworkProject.targetForUISourceCode(binding.network); |
| if (target.isNodeJS()) { |
| - other.requestContent().then( |
| - currentContent => this._syncNodeJSContent(binding, other, currentContent, newContent)); |
| + other.requestContent() |
| + .then(currentContent => this._rewrapNodeJSContent(binding, other, currentContent, newContent)) |
| + .then(newContent => setContent.call(this, newContent)); |
|
dgozman
2016/12/01 21:58:12
Let's not chain sync calls.
lushnikov
2016/12/02 02:51:36
Done.
|
| return; |
| } |
| - binding[Persistence.Persistence._muteCommit] = true; |
| - other.addRevision(newContent); |
| - binding[Persistence.Persistence._muteCommit] = false; |
| - this._contentSyncedForTest(); |
| + setContent.call(this, newContent); |
| + |
| + /** |
| + * @param {string} newContent |
| + * @this {Persistence.Persistence} |
| + */ |
| + function setContent(newContent) { |
| + binding[Persistence.Persistence._muteCommit] = true; |
| + other.addRevision(newContent); |
| + binding[Persistence.Persistence._muteCommit] = false; |
| + this._contentSyncedForTest(); |
| + } |
| } |
| /** |
| @@ -104,8 +153,9 @@ Persistence.Persistence = class extends Common.Object { |
| * @param {!Workspace.UISourceCode} uiSourceCode |
| * @param {string} currentContent |
| * @param {string} newContent |
| + * @return {string} |
| */ |
| - _syncNodeJSContent(binding, uiSourceCode, currentContent, newContent) { |
| + _rewrapNodeJSContent(binding, uiSourceCode, currentContent, newContent) { |
| if (uiSourceCode === binding.fileSystem) { |
| if (newContent.startsWith(Persistence.Persistence._NodePrefix) && |
| newContent.endsWith(Persistence.Persistence._NodeSuffix)) { |
| @@ -121,10 +171,7 @@ Persistence.Persistence = class extends Common.Object { |
| currentContent.endsWith(Persistence.Persistence._NodeSuffix)) |
| newContent = Persistence.Persistence._NodePrefix + newContent + Persistence.Persistence._NodeSuffix; |
| } |
| - binding[Persistence.Persistence._muteCommit] = true; |
| - uiSourceCode.addRevision(newContent); |
| - binding[Persistence.Persistence._muteCommit] = false; |
| - this._contentSyncedForTest(); |
| + return newContent; |
| } |
| _contentSyncedForTest() { |
| @@ -220,6 +267,7 @@ Persistence.Persistence = class extends Common.Object { |
| Persistence.Persistence._binding = Symbol('Persistence.Binding'); |
| Persistence.Persistence._muteCommit = Symbol('Persistence.MuteCommit'); |
| +Persistence.Persistence._muteWorkingCopy = Symbol('Persistence.MuteWorkingCopy'); |
| Persistence.Persistence._NodePrefix = '(function (exports, require, module, __filename, __dirname) { '; |
| Persistence.Persistence._NodeSuffix = '\n});'; |