feat: invocation option for Flecks.provide()

This commit is contained in:
cha0s 2022-03-12 20:02:19 -06:00
parent 071509223b
commit bbcf0d8798
2 changed files with 5 additions and 2 deletions

View File

@ -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,
}

View File

@ -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,
];
}),
)