From bbcf0d8798d1af3b3946e76f96b28135851681a6 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 12 Mar 2022 20:02:19 -0600 Subject: [PATCH] feat: invocation option for Flecks.provide() --- packages/core/build/dox/concepts/hooks.md | 2 ++ packages/core/src/flecks.js | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/core/build/dox/concepts/hooks.md b/packages/core/build/dox/concepts/hooks.md index 8fbba97..7042a98 100755 --- a/packages/core/build/dox/concepts/hooks.md +++ b/packages/core/build/dox/concepts/hooks.md @@ -198,6 +198,8 @@ is *exactly equivalent* to the gather example above. By default, `Flecks.provide ```javascript { + // Whether to invoke the default export as a function. + invoke = true, // The transformation used on the class path. transformer = camelCase, } diff --git a/packages/core/src/flecks.js b/packages/core/src/flecks.js index 4cafd23..3433424 100644 --- a/packages/core/src/flecks.js +++ b/packages/core/src/flecks.js @@ -365,6 +365,7 @@ export default class Flecks { static provide( context, { + invoke = true, transformer = camelCase, } = {}, ) { @@ -373,7 +374,7 @@ export default class Flecks { context.keys() .map((path) => { const {default: M} = context(path); - if ('function' !== typeof M) { + if (invoke && 'function' !== typeof M) { throw new ReferenceError( `Flecks.provide(): require(${ path @@ -384,7 +385,7 @@ export default class Flecks { } return [ transformer(this.symbolizePath(path)), - M(flecks), + invoke ? M(flecks) : M, ]; }), )