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

Unified Diff: third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js

Issue 2585393003: DevTools: [Persistence] implement Persistence.subscribeForBindingEvents (Closed)
Patch Set: nit 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 | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8ecf83d5bcbaa8e205c2249b067f278813c19941..a9865fbd11238d6dbe4493789fbd7ea1eae71bd1 100644
--- a/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js
+++ b/third_party/WebKit/Source/devtools/front_end/persistence/Persistence.js
@@ -17,6 +17,9 @@ Persistence.Persistence = class extends Common.Object {
/** @type {!Map<string, number>} */
this._filePathPrefixesToBindingCount = new Map();
+ /** @type {!Multimap<!Workspace.UISourceCode, function()>} */
+ this._subscribedBindingEventListeners = new Multimap();
+
if (Runtime.experiments.isEnabled('persistence2')) {
var linkDecorator = new Persistence.PersistenceUtils.LinkDecorator(this);
Components.Linkifier.setLinkDecorator(linkDecorator);
@@ -94,6 +97,9 @@ Persistence.Persistence = class extends Common.Object {
this._addFilePathBindingPrefixes(binding.fileSystem.url());
this._moveBreakpoints(binding.fileSystem, binding.network);
+
+ this._notifyBindingEvent(binding.network);
+ this._notifyBindingEvent(binding.fileSystem);
this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding);
}
@@ -121,8 +127,10 @@ Persistence.Persistence = class extends Common.Object {
Workspace.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
this._removeFilePathBindingPrefixes(binding.fileSystem.url());
-
this._breakpointManager.copyBreakpoints(binding.network.url(), binding.fileSystem);
+
+ this._notifyBindingEvent(binding.network);
+ this._notifyBindingEvent(binding.fileSystem);
this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding);
}
@@ -268,6 +276,38 @@ Persistence.Persistence = class extends Common.Object {
/**
* @param {!Workspace.UISourceCode} uiSourceCode
+ * @param {function()} listener
+ * @param {!Object=} thisObject
+ */
+ subscribeForBindingEvent(uiSourceCode, listener, thisObject) {
lushnikov 2016/12/20 02:50:02 I called this "subscribeForBindingEvent" rather th
dgozman 2016/12/20 05:47:03 Let's not support thisObject - this will make code
lushnikov 2016/12/20 18:38:35 Done.
+ listener[Persistence.Persistence._listenerReciever] = thisObject || null;
+ this._subscribedBindingEventListeners.set(uiSourceCode, listener);
+ }
+
+ /**
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ * @param {function()} listener
+ */
+ unsubscribeFromBindingEvent(uiSourceCode, listener) {
dgozman 2016/12/20 05:47:03 ... otherwise you have to pass thisObject here as
lushnikov 2016/12/20 18:38:34 Done.
+ if (!this._subscribedBindingEventListeners.hasValue(uiSourceCode, listener))
+ return;
+ listener[Persistence.Persistence._listenerReciever] = null;
+ this._subscribedBindingEventListeners.remove(uiSourceCode, listener);
+ }
+
+ /**
+ * @param {!Workspace.UISourceCode} uiSourceCode
+ */
+ _notifyBindingEvent(uiSourceCode) {
+ if (!this._subscribedBindingEventListeners.has(uiSourceCode))
+ return;
+ var listeners = Array.from(this._subscribedBindingEventListeners.get(uiSourceCode));
+ for (var listener of listeners)
+ listener.call(listener[Persistence.Persistence._listenerReciever], uiSourceCode);
dgozman 2016/12/20 05:47:03 Declared listener type doesn't take UISourceCode a
lushnikov 2016/12/20 18:38:34 Done.
+ }
+
+ /**
+ * @param {!Workspace.UISourceCode} uiSourceCode
* @return {?Workspace.UISourceCode}
*/
fileSystem(uiSourceCode) {
@@ -320,6 +360,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._listenerReciever = Symbol('Persistence.ListenerReciever');
Persistence.Persistence._NodePrefix = '(function (exports, require, module, __filename, __dirname) { ';
Persistence.Persistence._NodeSuffix = '\n});';
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698