home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 752742669

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/issues/983#issuecomment-752742669 https://api.github.com/repos/simonw/datasette/issues/983 752742669 MDEyOklzc3VlQ29tbWVudDc1Mjc0MjY2OQ== 9599 2020-12-30T20:07:05Z 2020-12-30T20:07:18Z OWNER

Initial prototype: ```javascript window.datasette = {}; window.datasette.plugins = (function() { var registry = {};

function extractParameters(fn) {
    var match = /\((.*)\)/.exec(fn.toString());
    if (match && match[1].trim()) {
        return match[1].split(',').map(s => s.trim());
    } else {
        return [];
    }
}

function register(hook, fn, parameters) {
    parameters = parameters || extractParameters(fn);
    if (!registry[hook]) {
        registry[hook] = [];
    }
    registry[hook].push([fn, parameters]);
}

function call(hook, args) {
    args = args || {};
    var implementations = registry[hook] || [];
    var results = [];
    implementations.forEach(([fn, parameters]) => {
        /* Call with the correct arguments */
        var callWith = parameters.map(parameter => args[parameter]);
        var result = fn.apply(fn, callWith);
        if (result) {
            results.push(result);
        }
    });
    return results;
}
return {
    register: register,
    _registry: registry,
    call: call
};

})(); Usage example:javascript datasette.plugins.register('numbers', (a, b) => a + b) datasette.plugins.register('numbers', (a, b) => a * b) datasette.plugins.call('numbers', {a: 4, b: 6}) / Returns [10, 24] / ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
712260429  
Powered by Datasette · Queries took 0.908ms · About: github-to-sqlite