diff --git a/core/boot.js b/core/boot.js index b8f2c4b5e..1b3df9aec 100644 --- a/core/boot.js +++ b/core/boot.js @@ -2,11 +2,9 @@ title: $:/core/boot.js type: application/javascript -The main boot kernel for TiddlyWiki. This single file creates a barebones TW environment that is just -sufficient to bootstrap the modules containing the main logic of the application. +The main boot kernel for TiddlyWiki. This single file creates a barebones TW environment that is just sufficient to bootstrap the modules containing the main logic of the application. -On the server this file is executed directly to boot TiddlyWiki. In the browser, this file is packed -into a single HTML file along with other elements: +On the server this file is executed directly to boot TiddlyWiki. In the browser, this file is packed into a single HTML file along with other elements: # bootprefix.js # @@ -83,7 +81,7 @@ $tw.plugins = {}; // Modules store registers all the modules the system has seen $tw.modules = $tw.modules || {}; $tw.modules.titles = $tw.modules.titles || {}; // hashmap by module title of {fn:, exports:, moduleType:} -$tw.modules.types = $tw.modules.types || {}; // hashmap by module type of array of exports +$tw.modules.types = $tw.modules.types || {}; // hashmap by module type of hashmap of exports // Config object $tw.config = $tw.config || {}; @@ -300,9 +298,28 @@ Register the exports of a single module in the $tw.modules.types hashmap */ $tw.modules.registerModuleExports = function(name,moduleType,moduleExports) { if(!$tw.utils.hop($tw.modules.types,moduleType)) { - $tw.modules.types[moduleType] = []; + $tw.modules.types[moduleType] = {}; + } + if($tw.utils.hop($tw.modules.types[moduleType],name)) { + console.log("Warning: Reregistering module - " + name); + } + $tw.modules.types[moduleType][name] = moduleExports; +}; + +/* +Apply a callback to each module of a particular type + moduleType: type of modules to enumerate + callback: function called as callback(title,moduleExports) for each module +*/ +$tw.modules.forEachModuleOfType = function(moduleType,callback) { + var modules = $tw.modules.types[moduleType]; + if(modules) { + for(var title in modules) { + if($tw.utils.hop(modules,title)) { + callback(title,modules[title]); + } + } } - $tw.modules.types[moduleType].push(moduleExports); }; /* @@ -310,13 +327,10 @@ Get all the modules of a particular type in a hashmap by their `name` field */ $tw.modules.getModulesByTypeAsHashmap = function(moduleType,nameField) { nameField = nameField || "name"; - var modules = $tw.modules.types[moduleType], - results = {}; - if(modules) { - for(var t=0; t