diff options
| author | Alon Levy <alon@pobox.com> | 2014-11-29 22:28:29 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-11-29 22:33:44 +0200 |
| commit | 42eacd877b5564961c2dcc491f5d4b7d62f4e753 (patch) | |
| tree | 6fce918b89bc0093671db978a26d5821036e1ade /src/model | |
| parent | 372aac3fafedbd517cf26501ef70015f47feb7f9 (diff) | |
use Bacon instead of signal
See https://github.com/baconjs/bacon.js
Usage right now:
we have rz_bus to hold global busses:
- names: for autosuggest
- ui busses:
- ui_key
- ui_input
The events are objects with {where: from consts, keys/input}
(could maybe just use the events and rely on the target element
class/id)
And graph has it's own bus:
graph.diffBus
(camelcase probably not the right style - will fix in later commit)
To publish to a bus you use push.
To insert another stream to a bus you use plug.
To listen to a bus you use onValue (you can use subscribe too to get
errors and end of stream event, but we don't use that yet).
This allows usage of map, filter, flatMap, see github repo for cool
examples.
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/graph.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/model/graph.js b/src/model/graph.js index 9123b669..6a299b5e 100644 --- a/src/model/graph.js +++ b/src/model/graph.js @@ -1,14 +1,17 @@ "use strict" -define(['signal', 'consts', 'util', 'model/core', 'model/util', 'rz_api_backend', 'rz_api_mesh'], -function (signal, consts, util, model_core, model_util, rz_api_backend, rz_api_mesh) { +define(['Bacon', 'consts', 'util', 'model/core', 'model/util', 'rz_api_backend', 'rz_api_mesh', 'history'], +function (Bacon, consts, util, model_core, model_util, rz_api_backend, rz_api_mesh, history) { var debug = false; function Graph() { var nodes = [], - links = []; + links = [], + diffBus = new Bacon.Bus(); + + this.diffBus = diffBus; /** * add node if no previous node is present whose id equals that of the node being added @@ -59,7 +62,7 @@ function Graph() { nodes.push(node); if (notify) { - signal.signal(consts.APPLIED_GRAPH_DIFF, [{nodes: {add: [node]}}]); + diffBus.push({nodes: {add: [node]}}); } return node; @@ -76,7 +79,7 @@ function Graph() { if (index !== undefined) { nodes.splice(index, 1); } - signal.signal(consts.APPLIED_GRAPH_DIFF, [{nodes: {removed: [id]}}]); + diffBus.push({nodes: {removed: [id]}}); } this.removeNodes = function(state) { @@ -95,7 +98,7 @@ function Graph() { } } if (ns.length > 0) { - signal.signal(consts.APPLIED_GRAPH_DIFF, [{nodes: {removed: ns.map(function(n) { return n.id; })}}]); + diffBus.push({nodes: {removed: ns.map(function(n) { return n.id; })}}); } } @@ -283,7 +286,7 @@ function Graph() { if (!found) { var link = model_core.create_link__set_random_id(src, dst, { name: name, state: state }); links.push(link); - signal.signal(consts.APPLIED_GRAPH_DIFF, [{links: {add: [link]}}]); + diffBus.push({links: {add: [link]}}); } else { found.name = name; found.state = state; @@ -585,7 +588,7 @@ function Graph() { data.links.forEach(function(link) { that.addLink(link.__src, link.__dst, link.name, "perm"); }); - signal.signal(consts.SUGGESTED_NAME_ADD, [added_names]); + rz_bus.names.push(added_names); this.clear_history(); } |
