User talk:TedSwippet/BoglebotTable

Managing persistent values
''Re: "For convenience, the template always transcludes  to pull in the required javascript. Multiple definitions of this in a single page cause no problems, and no noticeable performance issues. Any unforeseen issues with this? (If necessary it could be suppressed, though perhaps only with another parameter; there appears to be no ready way to communicate between template transclusions?)." ''

I think it probably works from a user point of view but it might end up registering all event handlers twice - so hit the API twice and re-render the table twice. This could be mitigated by changing BoglebotTable code to only run once with some "init'd" variable in the javascript so the code only registers at most once - User:Glorat


 * I think you can communicate between template transclusions by passing a flag. For example, "firstLink = 1" and use the wikitext parser functions to control the flow. A general concept would be:




 * The first template on the page could have "firstLink = 1". Subsequent calls would have "firstLink = 0" or not include the parameter. --LadyGeek 15:31, 16 January 2021 (UTC)
 * Certainly possible, but a fair bit less user-friendly than User:Glorat's solution -- if that's feasible -- which is why I haven't already done it. Outside of this, Extension:Variables - MediaWiki might perhaps do the trick without pushing the responsibility onto the user, but it seems like most of the Wiki world has chosen not to add this extension, so maybe we don't want to go there. --TedSwippet 17:44, 16 January 2021 (UTC)
 * Addendum. In some simple testing, wrapping the entry point,, in the following seems to be enough to prevent multiple execution:
 * That leaves multiple (identical) function definitions in the rest of the javascript code, but these shouldn't hurt. At least, I think. Glorat, thoughts? --TedSwippet 20:49, 16 January 2021 (UTC)
 * This check has now been added to the BoglebotTable code. Multiple transclusions are now "safe". As discussed below, it can be made better if we think it needed - User:Glorat 19 January 2021
 * Definitely cleanest to solve this in javascript. The above flag trick is the right idea for the entry point. For the duplicating functions, that is easily solved with modern javascript (e.g. storing the functions as a global variable only once)... but if not, it is likely mostly harmless. Can just try. If nothing else at some point in the future (after I finish the wiki-like UI for the db) I can look more closely. --User:Glorat
 * Thanks, sounds good. Duplicate definitions will have no semantic effects. The only performance effect I can foresee is unnecessary parsing of duplicates. V8 uses lazy parsing, so we should be in pretty good shape there, even without global variable trickery. --TedSwippet 09:52, 17 January 2021 (UTC)
 * I'm having second thoughts... Indeed, no bad semantic effects, or even much noticeable performance effects in parsing, because CPUs are fast. But since the transclusion is done server side, that means that the backend is shipping an extra 2kb of js code **per table**, as opposed to once if the js is only included once. This can start to add up as I/O costs (which dwarfs any CPU concerns we were thinking about). It might be simpler to tell wiki authors they have to include that magic transclude once - and perhaps this template can throw an error if it detects the transclude didn't get used. --User:Glorat
 * To me, 2kb/table seems like peanuts. Currently, the most table-heavy candidate page for this is probably Investing from the UK. Eleven tables, and around 350kb of download. At 2kb overhead, an additional 22kb, so a 6% increase. By comparison, even simple flag images often exceed this. For example File:Flag_of_the_United_States.svg.png is 30kb, and is the sort of thing one would add to a page without a second thought. --TedSwippet 11:18, 18 January 2021 (UTC)
 * Using Lua to prevent multiple inclusion looks like a non-starter. For now, I've added a "secondary" argument, that suppresses javascript transclusion if set. Purely data transport optimization. Expected to be used rarely, if ever. --TedSwippet 12:18, 19 January 2021 (UTC)
 * Using Lua to prevent multiple inclusion looks like a non-starter. For now, I've added a "secondary" argument, that suppresses javascript transclusion if set. Purely data transport optimization. Expected to be used rarely, if ever. --TedSwippet 12:18, 19 January 2021 (UTC)

Template naming?
At the moment, both this wrapper template and the underlying javascript delivery/implementation template use the name "BoglebotTable". Clearly this has to change once both move to the Template namespace. Any preferences on naming? Merging the two seems undesirable, since it would stop non-html editors from modifying the wrapper (cosmetics, etc).

Mostly we'll want editors to use the wrapper template rather than the underlying javascript implementation template, so that sort-of suggests a simpler and clearer name for this template and a somewhat more obscure (or intimidating!) one for the javascript template. Thoughts? --TedSwippet 12:27, 19 January 2021 (UTC)


 * I think this is an easy one... if the template is agreed, yours should be the one with the official name in the right template. The Javascript code then doesn't even need to live in the Template namespace. It could just be BoglebotTableCode or whatever. - User:Glorat