diff --git a/dist/index.d.ts b/dist/index.d.ts index 1fe100d..503f0f9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -7,7 +7,7 @@ export default class Flummpress { private middleware; router: Router; constructor(); - use(nameOrRouter: string | Router, factory?: () => T): this; + use(plugin: string | Router | Handler, factory?: () => T): this; resolve(name: string): T; private processPipeline; listen(...args: any[]): this; diff --git a/dist/index.js b/dist/index.js index 2f4182e..55a16c7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -20,11 +20,13 @@ export default class Flummpress { this.router = new Router(); this.middleware = []; } - use(nameOrRouter, factory) { - if (typeof nameOrRouter === "string" && factory) - this.container.register(nameOrRouter, factory); - else if (nameOrRouter instanceof Router) - this.router.use(nameOrRouter); + use(plugin, factory) { + if (typeof plugin === "string" && factory) + this.container.register(plugin, factory); + else if (plugin instanceof Router) + this.router.use(plugin); + else if (typeof plugin === "function") + this.middleware.push(plugin); else throw new TypeError("Invalid arguments provided to use()"); return this; diff --git a/src/index.ts b/src/index.ts index 9dba11c..6f7cb61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,19 +20,13 @@ export default class Flummpress { this.middleware = []; } - /*public use(plugin: Router | Handler): this { - if(plugin instanceof Router) + public use(plugin: string | Router | Handler, factory?: () => T): this { + if(typeof plugin === "string" && factory) + this.container.register(plugin, factory); + else if(plugin instanceof Router) this.router.use(plugin); else if(typeof plugin === "function") this.middleware.push(plugin); - return this; - }*/ - - public use(nameOrRouter: string | Router, factory?: () => T): this { - if(typeof nameOrRouter === "string" && factory) - this.container.register(nameOrRouter, factory); - else if(nameOrRouter instanceof Router) - this.router.use(nameOrRouter); else throw new TypeError("Invalid arguments provided to use()"); return this;