> This raises a related question for me - why is it good practice for > plugins to check if they've already been loaded? (if > version.extensions.....) { } at the top of most plugins). I've never > seen one plugin include the entire source of another plugin, so why is > there a risk a plugin will be loaded twice?
In general, I don't include this check in my plugins. However, I *have* seen instances where people had two different versions of the same plugin code installed in one document, because one of the plugin tiddlers has been renamed. As a result, the newer revision doesn't *replace* the old one, and both tiddlers continue to be loaded at startup, so multiple loads *are* possible, even if it is unintended. Of course, for most plugins, being invoked multiple times doesn't really matter (except for the extra processing time), as they are typically just definining functions and variables that aren't actually *used* until after startup processing has finished (e.g., config.macros.something.handler, config.options.chkSomething, etc.) However, if a plugin hijacks a core function, or appends to the config.formatters[], or modifies shadow tiddler definitions, or is in any other way not *idempotent*, then multiple loads *might* result in a serious fail. For example, if a hijack is done twice, it will produce an infinite recursion, because the 2nd hijack will end up overriding and then subsequently invoking *itself* (rather than the original core function that was hijacked the first time). If the recursion gets trigger during startup (e.g., when rendering the initial PageTemplate display), then the browser just hangs (or gets a "too much recursion" error). Further, if we assume, however unlikely, that the user actually understands what is causing this problem, there's no way to correct it from within TW itself, and they have to resort to using an external text editor to find and disable the errant plugin, so that they can then open the document normally and really fix the error. Lastly, it is possible, using various plugin-defined features such RunTiddlerPlugin, or LoadTiddlersPlugin's "init" option, to invoke plugin code *after* startup. As noted above, any plugins that are not idempotent at load time need to ensure that they don't get invoked twice (or at least, detect that they were previously loaded so they can clean up any functions/data left behind before re-initializing). -e --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To post to this group, send email to tiddlywiki@googlegroups.com To unsubscribe from this group, send email to tiddlywiki+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/tiddlywiki?hl=en -~----------~----~----~----~------~----~------~--~---