Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registerAsyncHelper does not consistently match registerHelper signature #160

Open
allouis opened this issue Jun 10, 2019 · 0 comments
Open

Comments

@allouis
Copy link
Collaborator

allouis commented Jun 10, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant