You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// State needs to be updated each time updateState is called
87
88
$.extend(state,params);// Consider using deep merge by adding true as the first parameter. However, deep merging does not work with bookmarking of expanded and collapsed dendrogram nodes since they are passed as arrays
88
-
89
-
// Store bookmark and update the bid
90
-
if(req)
91
-
req.abort();
92
-
93
-
req=$.ajax({
94
-
type : "POST",
95
-
url : api_root+"projects/"+pid+"/bookmarks",
96
-
contentType : "application/json",
97
-
data: JSON.stringify(state),
98
-
processData: false,
99
-
success: function(result)
100
-
{
101
-
bid=result.id;
102
-
updateURL(bid);
103
-
// Store latest bid in local storage
104
-
if(mid!=null)
105
-
localStorage[mid]=bid;
106
-
req=null;
107
-
},
108
-
});
89
+
90
+
// But we don't have to post the bookmark each time, so calling a seaparte postBookmark
91
+
// function that is debounced (or throttled in the future?) to limit number of POSTs to the backend
92
+
manager.postBookmark();
109
93
}
110
94
95
+
// Using debounce to only POST bookmark every 1/3 second (333 ms) so we don't
96
+
// inundate the server with dozens of requests per second when user does something
97
+
// that updates state often, like drag a pin around the screen.
98
+
manager.postBookmark=_.debounce(
99
+
// This is the function that POSTs a bookmark to the server
100
+
function(params)
101
+
{
102
+
// Store bookmark and update the bid
103
+
if(req)
104
+
req.abort();
105
+
106
+
req=$.ajax({
107
+
type : "POST",
108
+
url : api_root+"projects/"+pid+"/bookmarks",
109
+
contentType : "application/json",
110
+
data: JSON.stringify(state),
111
+
processData: false,
112
+
success: function(result)
113
+
{
114
+
bid=result.id;
115
+
updateURL(bid);
116
+
// Store latest bid in local storage
117
+
if(mid!=null)
118
+
localStorage[mid]=bid;
119
+
req=null;
120
+
},
121
+
});
122
+
},
123
+
// How long to wait before actually running that function.
124
+
// Debounce just waits this long and then executes the last call to postBookmark.
125
+
// But in the future we might want to use throttle function instead, which
126
+
// would call postBookmark every 333 seconds.
127
+
333
128
+
);
129
+
111
130
// Retrieves the state for the current bookmark id (asynchronous)
0 commit comments