From 293294f2401f3dac6d07e9af65b5582ba893a777 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 9 Feb 2015 08:34:37 -0500 Subject: 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. --- js/utils.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'js/utils.js') 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(); + } + }; +}; -- cgit v1.2.3