Created
October 10, 2016 14:18
-
-
Save ronen-e/06da740fd6d8ee6664b8c25e4a6aaf31 to your computer and use it in GitHub Desktop.
Search modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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