diff options
Diffstat (limited to 'js/utils.js')
-rw-r--r-- | js/utils.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/js/utils.js b/js/utils.js index cfaa7fd..5359814 100644 --- a/js/utils.js +++ b/js/utils.js @@ -17,6 +17,9 @@ var guix = {}; +// Shorthand for Kefir module. +var K = Kefir; + // Here is a perfect example of why Scheme is better than JavaScript: // + is an operator, not a function. So if I want to, say, compute // the sum of an array of numbers, I need to write a wrapper function. @@ -41,3 +44,30 @@ guix.chunk = function(array, size) { return memo; }, []); }; + +// Mithril + Kefir integration +guix.withEmit = function(emitter) { + return emitter.emit.bind(emitter); +}; + +guix.withEmitAttr = function(attr, emitter) { + return m.withAttr(attr, guix.withEmit(emitter)); +}; + +guix.makeModule = function(controller) { + var view = m.prop([]); + + // Cheat the module system a bit. + return { + controller: function() { + controller().onValue(function(newView) { + m.startComputation(); + view(newView); + m.endComputation(); + }); + }, + view: function() { + return view(); + } + }; +}; |