summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-26 22:25:29 +0200
committerAlon Levy <alon@pobox.com>2014-10-26 22:25:33 +0200
commitb3f96efb33d7fc99500147d336ead1536b6b24e9 (patch)
treedea2c8bd7fe345a50b048d792a2a3de4430a7b9a /scripts
parenta31a32e4ea03771986192c536141c9f276a41d08 (diff)
introduce signal, start using in history; use consts for signal name
introduces two new modules: scripts/consts.js scripts/signal.js signal is a thin wrapper for jquery('window').on and jquery('window').trigger, which seems like an adaquete signal library - there are faster things around, but why introduce another dependency.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/consts.js5
-rw-r--r--scripts/history.js7
-rw-r--r--scripts/rhizicore.js8
-rw-r--r--scripts/signal.js22
4 files changed, 36 insertions, 6 deletions
diff --git a/scripts/consts.js b/scripts/consts.js
new file mode 100644
index 00000000..927a30d3
--- /dev/null
+++ b/scripts/consts.js
@@ -0,0 +1,5 @@
+define('consts', function() {
+ return {
+ RECORD_LINKS: 'record_links',
+ };
+});
diff --git a/scripts/history.js b/scripts/history.js
index a3127c75..e99cbb08 100644
--- a/scripts/history.js
+++ b/scripts/history.js
@@ -15,11 +15,16 @@
// ReferenceError: __commandLineAPI is not defined
//var ActionEnum = Enum();
-define('history', ['FileSaver'], function(saveAs) {
+define('history', ['jquery', 'FileSaver', 'consts', 'signal'],
+ function($, saveAs, consts, signal) {
function History(user) {
+ var that = this;
this.records = [];
this.user = user;
+ signal.slot(consts.RECORD_LINKS, function(obj) {
+ return that.record_links(obj)
+ });
}
var ACTION_KEYSTROKES = 'ACTION_KEYSTROKES';
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js
index cdffde64..1b4bcbb3 100644
--- a/scripts/rhizicore.js
+++ b/scripts/rhizicore.js
@@ -1,8 +1,8 @@
"use strict"
define('rhizicore',
-['jquery', 'd3', 'util', 'history', 'textanalysis'],
-function($, d3, util, history, textanalysis) {
+['jquery', 'd3', 'consts', 'signal', 'util', 'history', 'textanalysis'],
+function($, d3, consts, signal, util, history, textanalysis) {
var History = history.History;
var addednodes = [];
@@ -260,9 +260,7 @@ function myGraph(el) {
"state": state
};
links.push(link);
- if (this.history !== undefined) {
- this.history.record_links([link]);
- }
+ signal.signal(consts.RECORD_LINKS, [[link]]);
} else {
found.name = name;
found.state = state;
diff --git a/scripts/signal.js b/scripts/signal.js
new file mode 100644
index 00000000..49c5afd3
--- /dev/null
+++ b/scripts/signal.js
@@ -0,0 +1,22 @@
+/*
+ * Signal/slot (i.e. blackboard pattern) for rhizi.
+ *
+ * This is a thin wrapper over jquery right now.
+ * But just keeping it here to make any future change of implementation slightly
+ * easier.
+ */
+
+define('signal', ['jquery'], function($) {
+ function slot(name, handler) {
+ $(window).on(name, function(e, args) {
+ handler(args);
+ });
+ };
+ function signal(name, obj) {
+ $(window).trigger(name, obj);
+ }
+ return {
+ 'slot': slot,
+ 'signal': signal
+ };
+})