Skip to content

Instantly share code, notes, and snippets.

@benkeen
Last active August 29, 2015 14:19
Show Gist options
  • Save benkeen/f4c37ac5b7b2340ad433 to your computer and use it in GitHub Desktop.
Save benkeen/f4c37ac5b7b2340ad433 to your computer and use it in GitHub Desktop.
Solution 2: FauxtonAPI functions
var registeredComponents = {};
// registers a new component. Requires the component name to be unique
FauxtonAPI.registerComponent = function (name, component) {
if (_.has(registeredComponents, name)) {
console.error("Error: a component with the name " + name + " has already been registered.");
return;
}
registeredComponents[name] = component;
};
// will return undefined if not found
FauxtonAPI.getComponent = function (name) {
return registeredComponents[name];
};
// overwrites the component in memory. N.B. I'll probably tweak this function a little to allow overriding a
// component *before* it's been loaded. I can well imagine a scenario where the dash code loads prior to Fauxton,
// so it may take a little juggling of this and the registerComponent method above to get it right (e.g. suppressing
// errors on registerComponent())
FauxtonAPI.updateComponent = function (name, component) {
registeredComponents[name] = component;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment