summaryrefslogtreecommitdiff
path: root/src/client/view
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-12-30 10:31:39 +0200
committerAlon Levy <alon@pobox.com>2015-01-05 13:23:57 +0200
commit54aa65a3dab029f28741875eb11a40adb06aff51 (patch)
tree872e9c2723644795d5ac633ec9ae7820f8e3f69d /src/client/view
parente1203339003c32eb646b199d2ae69b7082228cc9 (diff)
introduce commit_and_tx_diff__topo & commit_diff__topo
Multiple fixes / changes. _bugs introduced_ Changes: graph has two change functions (i.e. the internal API): - commit_and_tx_diff_topo This currently transmits, later will optimistically apply first - commit_diff__topo This only applies. Used on the ajax success path for commit_and_tx_diff__topo and when changes are only local. It signals on the diffBus - diffBus - a Bacon.Bus that all UI listens to - selection UI - node/link dialogs - main view (rz_core/update_view__graph) Small changes: whitespace rename filer->filter Completely broken: - text entry. should use commit_diff__topo Problems introduced: selection doesn't work correctly. editing not verified yet
Diffstat (limited to 'src/client/view')
-rw-r--r--src/client/view/selection.js39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/client/view/selection.js b/src/client/view/selection.js
index 27842e11..9a87494a 100644
--- a/src/client/view/selection.js
+++ b/src/client/view/selection.js
@@ -1,17 +1,31 @@
-define(['rz_core'],
-function(rz_core) {
+define(['rz_core', 'Bacon'],
+function(rz_core, Bacon) {
function get_rz_core()
{
// circular dependency on rz_core, so require.js cannot solve it.
if (rz_core === undefined) {
rz_core = require('rz_core');
- rz_core.graph.diffBus.onValue(updateSelectionOnDiff);
+ listen_on_diff_bus(rz_core.graph.diffBus);
}
return rz_core;
}
-var selected_nodes = [];
+var selected_nodes = [],
+ selectionChangedBus = new Bacon.Bus();
+
+function listen_on_diff_bus(diffBus)
+{
+ diffBus
+ .filter(".node_set_rm")
+ .onValue(function (diff) {
+ var node_node_cmp = (function (a, b) { return a.id > b.id; }),
+ node_id_cmp = (function (a, b) { return a.id === b ? 0 : (a.id > b ? 1 : -1); });
+
+ updateSelectedNodesBus(sortedArrayDiff(selected_nodes.sort(node_node_cmp),
+ diff.node_set_rm.sort(), node_id_cmp));
+ });
+}
function sortedArrayDiff(a, b, a_cmp_b)
{
@@ -38,18 +52,10 @@ function sortedArrayDiff(a, b, a_cmp_b)
return ret;
}
-function updateSelectionOnDiff(diff)
+function updateSelectedNodesBus(new_selected_nodes)
{
- var node_node_cmp = (function (a, b) { return a.id > b.id; }),
- node_id_cmp = (function (a, b) { return a.id === b ? 0 : (a.id > b ? 1 : -1); });
-
- if (diff.nodes.removed === undefined || selected_nodes.length == 0) {
- return;
- }
- console.log("selection enter: " + String(selected_nodes.map(function(x) { return x.id; })));
- console.log("removed nodes enter: " + String(diff.nodes.removed));
- selected_nodes = sortedArrayDiff(selected_nodes.sort(node_node_cmp), diff.nodes.removed.sort(), node_id_cmp);
- console.log("selection exit: " + String(selected_nodes.map(function(x) { return x.id; })));
+ selected_nodes = new_selected_nodes;
+ selectionChangedBus.push(selected_nodes);
}
function byVisitors(node_selector, link_selector) {
@@ -66,7 +72,7 @@ function connectedComponent(nodes) {
link,
data;
- selected_nodes = nodes.map(function(x) { return x; });
+ updateSelectedNodesBus(nodes.map(function(x) { return x; }));
for (i = 0 ; i < connected.nodes.length ; ++i) {
data = connected.nodes[i];
@@ -137,6 +143,7 @@ return {
update: update,
selected_class: selected_class,
node_selected: node_selected,
+ selectionChangedBus: selectionChangedBus,
};
});