Gas hosted scripts


In Color scheme explorer the main color processing scripts are hosted in Google Apps Script. There's particular no reason to do this, except that it means that I can ensure I use the same algorithms in JavaScript as I do in GAS. 

Building on Using Gas as a CDN, where I use the GAS publisher and content service to serve up JavaScript, here's how it works in the  Color scheme explorer

Asynchronous loading

When it starts up, you may notice this


Here's what's happening then...

loading GAS modules using promises


Called here, and moving on to load Data from parse.com once the load promise for each of the required apps script functions is fulfilled.

$('#status').text("...getting google apps script modules");
$.when.apply($,loadModules (["vEquivalents","hacks","usefulColors"],"mcpher")).then (
    function () {
        var randomColor = randomBar();
        // get the currently selected scheme, and if nothing entered yet, generate a random scheme
        getSelectedScheme($('#schemeselector').val())
            .done( function() {
                if (!$('#hexinput').val()) calculateColors (rgbToHTMLHex(randomColor),"random color");
               });
     },
     function (error) {
        console.log(JSON.stringify(error));
 });

Again, the use of promises simplifies and abstracts away the whole messy business of asynchronicity.



For help and more information join our forum,follow the blog or follow me on twitter .




Comments