diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-02-09 08:34:37 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-02-09 08:34:37 -0500 |
commit | 293294f2401f3dac6d07e9af65b5582ba893a777 (patch) | |
tree | 3f2b64f314d692e2359a613e3f0e2c5dd99e7f71 /js/utils.js | |
parent | 6546b8cae1aead78da45dd269d13219257af04ab (diff) |
js: Overhaul UI with FRP!
* css/guix.css: New loading spinner.
* js/lib/kefir.js: New file.
* js/model/packages.js (guix.packages.Packages): Cache result.
(guix.packages.Sorter, guix.packages.Pager): Delete.
(guix.packages.installPackage): New function.
* js/utils.js (K): New variable.
(guix.withEmit, guix.withEmitAttr, guix.makeModule): New functions.
* js/view/ui.js (guix.ui.paginate, guix.ui.spinUntil): New functions.
(guix.ui.spinner): New variable.
* js/controller/generations.js: Rewrite.
* js/controller/packageInfo.js: Rewrite
* js/controller/packages.js: Rewrite.
* js/view/packages.js: Rewrite.
* js/view/generations.js: Delete.
* js/view/packageInfo.js: Delete.
* js/routes.js: Use new modules.
* guix/web/view/html.scm (javascripts): Update list.
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(); + } + }; +}; |