summaryrefslogtreecommitdiff
path: root/src/client/rz_mesh.js
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2015-04-09 01:49:24 +0300
committerLV-426 <lv-426@taproot.org.il>2015-04-09 02:03:45 +0300
commit059428fdf0c613e92e84f7360558815f2e0c9dd9 (patch)
tree4399893c02dd6345990d73b4337ba1a92e7652ad /src/client/rz_mesh.js
parentb239c007f5b7dae085f732a2ce007643e758698c (diff)
rz_core.js, rz_mesh.js: we init/destroy
Diffstat (limited to 'src/client/rz_mesh.js')
-rw-r--r--src/client/rz_mesh.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/client/rz_mesh.js b/src/client/rz_mesh.js
index a3cb822c..1a93f554 100644
--- a/src/client/rz_mesh.js
+++ b/src/client/rz_mesh.js
@@ -13,6 +13,8 @@ define([ 'util', 'model/diff', 'model/util', 'socketio'], function(util, model_d
var rz_mesh_graph_ref;
/**
+ * [!] caller is responsible of calling destroy()
+ *
* @param init_spec: expected to contain a graph:graph mapping
*/
function init(init_spec) {
@@ -30,13 +32,11 @@ define([ 'util', 'model/diff', 'model/util', 'socketio'], function(util, model_d
socket.on('error', on_error);
socket.on('diff_commit__topo', ws_diff_merge__topo);
socket.on('diff_commit__attr', ws_diff_merge__attr);
+ }
- // attempt to actively disconnect on tab/window close
- // ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers.onbeforeunload
- window.addEventListener("beforeunload", function(e){
- socket.disconnect();
- console.log('ws: connection closed on \'beforeunload\' event'); // no one will ever see this but still
- });
+ function destroy(init_spec) {
+ socket.disconnect();
+ console.log('ws: connection closed on \'beforeunload\' event'); // no one will ever see this but still
}
function on_connect() {
@@ -102,7 +102,8 @@ define([ 'util', 'model/diff', 'model/util', 'socketio'], function(util, model_d
}
return {
- init : init
+ init : init,
+ destroy: destroy,
emit__rzdoc_subscribe: emit__rzdoc_subscribe,
emit__rzdoc_unsubscribe: emit__rzdoc_unsubscribe,
};