{"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752729035", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752729035, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcyOTAzNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T19:15:56Z", "updated_at": "2020-12-30T19:16:44Z", "author_association": "OWNER", "body": "The `column_actions` hook is the obvious first place to try this out. What are some demo plugins I could build for it?\r\n\r\n- Word cloud for this column\r\n- Count values (essentially linking to the SQL query for that column, as an extended version of the facet counts) - would be great if this could include pagination somehow, via #856.\r\n- Extract this column into a separate table\r\n- Add an index to this column", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752722863", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752722863, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcyMjg2Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:52:39Z", "updated_at": "2020-12-30T18:52:39Z", "author_association": "OWNER", "body": "Then to call the plugins:\r\n```javascript\r\ndatasette.plugins.call('column_actions', {database: 'database', table: 'table'})\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752721840", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752721840, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcyMTg0MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:48:53Z", "updated_at": "2020-12-30T18:51:51Z", "author_association": "OWNER", "body": "Potential design:\r\n```javascript\r\ndatasette.plugins.register('column_actions', function(database, table, column, actor) {\r\n /* ... *l\r\n})\r\n```\r\nOr if you want to be explicit to survive minification:\r\n```javascript\r\ndatasette.plugins.register('column_actions', function(database, table, column, actor) {\r\n /* ... *l\r\n}, ['database', 'table', 'column', 'actor'])\r\n```\r\nI'm making that list of parameter names an optional third argument to the `register()` function. If that argument isn't passed, introspection will be used to figure out the parameter names.\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752721069", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752721069, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcyMTA2OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:46:10Z", "updated_at": "2020-12-30T18:46:10Z", "author_association": "OWNER", "body": "Pluggy does dependency injection by introspecting the named arguments to the Python function, which I really like.\r\n\r\nThat's tricker in JavaScript. It looks like the only way to introspect a function is to look at the `.toString()` representation of it and parse the `(parameter, list)` using a regular expression.\r\n\r\nEven more challenging: JavaScript developers love minifying their code, and minification can shorten the function parameter names.\r\n\r\nFrom https://code-maven.com/dependency-injection-in-angularjs it looks like Angular.js does dependency injection and solves this by letting you optionally provide a separate list of the arguments your function uses:\r\n\r\n```javascript\r\n angular.module('DemoApp', [])\r\n .controller('DemoController', ['$scope', '$log', function($scope, $log) {\r\n $scope.message = \"Hello World\";\r\n $log.debug('logging hello');\r\n }]);\r\n```\r\n\r\nI can copy that approach: I'll introspect by default, but provide a documented mechanism for explicitly listing your parameter names so that if you know your plugin code will be minified you can use that instead.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752715412", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752715412, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcxNTQxMg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:25:31Z", "updated_at": "2020-12-30T18:25:31Z", "author_association": "OWNER", "body": "I'm going to introduce a global `datasette` object which holds all the documented JavaScript API for plugin authors.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/983#issuecomment-752715236", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/983", "id": 752715236, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcxNTIzNg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:24:54Z", "updated_at": "2020-12-30T18:24:54Z", "author_association": "OWNER", "body": "I think I'm going to try building a very lightweight clone of the core API design of Pluggy - not the advanced features, just the idea that plugins can register and a call to `plugin.nameOfHook()` will return the concatenated results of all of the registered hooks.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 712260429, "label": "JavaScript plugin hooks mechanism similar to pluggy"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/987#issuecomment-752714747", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/987", "id": 752714747, "node_id": "MDEyOklzc3VlQ29tbWVudDc1MjcxNDc0Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-12-30T18:23:08Z", "updated_at": "2020-12-30T18:23:20Z", "author_association": "OWNER", "body": "In terms of \"places to put your plugin content\", the simplest solution I can think of is something like this:\r\n```html\r\n
\r\n```\r\nAlternative designs:\r\n\r\n- A documented JavaScript function that returns the CSS selector where plugins should put their content\r\n- A documented JavaScript function that returns a DOM node where plugins should put their content. This would allow the JavaScript to create the element if it does not already exist (though it wouldn't be obvious WHERE that element should be created)\r\n- Documented JavaScript functions for things like \"append this node/HTML to the place-where-plugins-go\"\r\n\r\nI think the original option - an empty `