express-hbs icon indicating copy to clipboard operation
express-hbs copied to clipboard

registerAsyncHelper does not consistently match registerHelper signature

Open allouis opened this issue 6 years ago • 0 comments

registerAsyncHelper has a limit of two arguments to the helper, which is confusing, and doesn't allow direct ports from a handlebars helper, to an express-hbs helper.

Here's an example of a helper that is impossible to make async with the current system:

// usage: {{someHelper "first" "second"}}
// usage: {{someHelper "first" "second" key="val"}}

hbs.registerHelper('someHelper', function (arg1, arg2, options) {
	// arg1 === "first"
	// arg2 === "second"
	// options.hash === {} || {key: "val"}
});


// usage: {{someAsyncHelper "first" "second"}}
// usage: {{someAsyncHelper "first" "second" key="val"}}
hbs.registerAsyncHelper('someAsyncHelper', function (arg1, arg2, options, done) {
	// this won't work
	// arg1 === "first"
	// arg2 === "second"
	// options === Function
	// done === undefined
	// `options` object will not be passed at all, meaning no access to the `hash`
});

This is particularly an issue with block helpers, as they almost always want access to the options object in order to call options.fn to render their "insides"

I think it would make sense for registerAsyncHelper to replicate the registerHelper signature, with an extra argument passed at the end - OR to replicate the registerHelper signature exactly, and allow returning of a Promise

Unfortuantely fixing this would be a major version bump.

allouis avatar Jun 10 '19 08:06 allouis