jstransformers / jstransformer

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

Rename `compile()`s .fn to `.render`? #91

Open tunnckoCore opened 9 years ago

tunnckoCore commented 9 years ago

It's more natural and logical for me. Talking about .fn which is (in object) returned from compile method.

var handlebars = require('jstransformer')(require('jstransformer-handlebars'));

var render = handlebars.compile('Hello {{name}} and welcome!').render;
//var render = handlebars.compile('Hello {{name}} and welcome!').fn; // currently
render({name: 'John'}); //=> 'Hello world'
TimothyGu commented 9 years ago

I agree with the fact that render is a better name for the function; but, fn accurately distinguishes itself with the other property in the object, dependencies. (What I'm saying is that you can totally tell dependencies is an array, and fn is the compiled function, since well, it came from the compile function and is named after function.)

Another thing to keep in mind is that even though jstransformer is still @<1 (albeit for quite some time), a few people have started using it so it wouldn't be nice to just break it without a technical reason for such.

tunnckoCore commented 9 years ago

Another thing to keep in mind is that even though jstransformer is still @<1

exactly, because of that, this change shouldn't be a problem.

ForbesLindesay commented 9 years ago

Actually, I think this change would be a really good idea. We could have it return both render and renderAsync (which we would polyfill for synchronous FNs). We could also add the fn property for backwards compatibility, but deprecate it.

tunnckoCore commented 9 years ago

We could have it return both render and renderAsync (which we would polyfill for synchronous FNs)

:+1:

We could also add the fn property for backwards compatibility, but deprecate it.

we can just bump major. JSTransformer is baby, it's normal to have changes and dont have notices as per 0.0.x. There's would have too much things in the returned object and may goes more complicated.

TimothyGu commented 9 years ago

Sounds good. If we were to do this, I'd just remove fn as @tunnckoCore said.