Skip to content

Instantly share code, notes, and snippets.

@ronen-e
Created October 10, 2016 14:18
Show Gist options
  • Save ronen-e/06da740fd6d8ee6664b8c25e4a6aaf31 to your computer and use it in GitHub Desktop.
Save ronen-e/06da740fd6d8ee6664b8c25e4a6aaf31 to your computer and use it in GitHub Desktop.
Search modules
var Modules = new Map();
function addModule(id, searchFn) {
if (Modules.has(id)) {
throw 'Error: module: ' + id + ' already exists.';
}
Modules.set(id, searchFn);
}
function searchFn(id, query) {
if (!Modules.has(id)) {
throw 'Error: unknown module: ' + id;
}
return new Promise((resolve) => {
Modules.get(id)(query, resolve);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment