jstransformers / jstransformer

Normalize the API of any JSTransformer.
http://npm.im/jstransformer
MIT License
153 stars 12 forks source link

When calling compileAsync(), fallback to renderAsync #175

Closed RobLoach closed 7 years ago

RobLoach commented 7 years ago

When calling compileAsync(), we should fallback to renderAsync(). Not sure if this is done right.

RyanZim commented 7 years ago

Not sure if this is done right.

renderAsync should be added to the list of fallbacks for compileAsync above.

The error should be the only statement inside if (!this.can('compileAsync')).

After if (this._hasMethod('compileAsync')), you should add an else if (this.can('renderAsync')) block, containing your call to renderAsync.

Hope this is clear enough.

RobLoach commented 7 years ago

@RyanZim Thanks for the feedback. Still not working :-( Added a test. Know what it's missing? Feel free to commit directly to the branch.

RyanZim commented 7 years ago

When calling compileAsync(), we should fallback to renderAsync()

We can't. compileAsync() has to return {fn: Function, dependencies: Array.<String>} and fn has to return a string. If we use renderAsync() under the hood, fn will return a promise, not a string.

I never thought of this before, but since there's no way to make something async return synchronously, we're out of options. It just won't work.

I guess close this. Is there a particular transformer that you need this for?

RyanZim commented 7 years ago

@RobLoach ping?

RobLoach commented 7 years ago

You're right, we can't do it unfortunately. Maybe best way to do it would be implementing both functions in the transformers... I'll close this for now. Thanks!