From a957efbceadcfe8c0a3296caf396b650933b8048 Mon Sep 17 00:00:00 2001 From: SomeKittens Date: Wed, 30 Sep 2015 19:30:23 -0700 Subject: [PATCH] feat: enforce unique names for node registration --- index.js | 6 +++++- index.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9ffa962..da23f6b 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,14 @@ var Gustav = (function () { // TODO: new type of registration that's just a singleton // Just calls NodeFactory and returns the symbol Gustav.prototype.register = function (type, name, factory) { - var _this = this; // TODO: Return some sort of object so this can be chained // let splitText = SplitText() // .addDep(fetchPageText); + var _this = this; + // Names must be unique + if (this.registeredNodes[type].indexOf(name)) { + throw new Error(name + ' already registered'); + } this.registeredNodes[type].push(name); return function () { var config = []; diff --git a/index.ts b/index.ts index d1fb0cc..d09594d 100644 --- a/index.ts +++ b/index.ts @@ -34,6 +34,11 @@ class Gustav { // TODO: Return some sort of object so this can be chained // let splitText = SplitText() // .addDep(fetchPageText); + + // Names must be unique + if (this.registeredNodes[type].indexOf(name)) { + throw new Error(name + ' already registered'); + } this.registeredNodes[type].push(name); return (...config) => {