-
Notifications
You must be signed in to change notification settings - Fork 310
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
Rivets function auto-execution in expressions #571
Comments
This solution could replace what's called With this issue we could replace <span rv-text="event.duration < start end"></span> by <span rv-text="event.duration | call event.start event.end"></span> There is not much coding difference but now the view doesn't know the internals of @Leeds-eBooks @Duder-onomy @blikblum If you have time to take look at this issue, your opinion would be welcome |
I have used a custom formatter of my own called EDIT: just want to add that initially I was resistant to this but the more I think about it the more sense it makes. Rivets to me is all about having as little "magic" as possible. Leaving it to the dev to execute their functions via a normal formatter fits this very well. |
A specific syntax would be great, but a "simple" formatter would be so easy to implement, with no risk of regression |
What do you think about introducing built-in formatters, including |
I agree, in our projects we have included these formatters (exactly the ones you mentionned and some more like |
Ok so just to clarify/summarise (sorry for repeating): what I think might be the right approach is:
Does that fit your thinking? |
FYI, I took a scan through a few of our projects and asked the other teams during standup if they were using functions in the sense described here. Everyone said that they were not doing it, also, most people thought that this was a bad idea anyway and were surprised it was possible. So, to chime in on behalf of me and all my coworkers, 👍 As far as including more formatters, I think a few would be good but def not too many. The ones you mentioned also appear in all of our projects. This will probably be a task for me as I am updating the docs right meow for the 0.9 release. This will essentially render the 'computed properties' feature useless. |
Aren't rivets.configure({
'autoExecuteFunctions': true/false // I'm not good in parameter naming, so if you have a better idea...
}) Not the prettiest way, but it would give an option to those who want And for formatters, actually there is already something here |
FYI semver allows to add breaking changes in 0.x versions |
@Duder-onomy i'm really surprised that none of your colleagues use functions that get called by rivets, it's so useful! But – it is sometimes necessary to refer back to the model while you're reading your jade/html/whatever to work out if a property is a function or a value, and having However, I'm a little concerned about the computed properties issue. I use this feature a lot across my projects, here's a quick example: <button rv-class-highlight="ready < user.password user.confirm">Submit</button> It should be self-explanatory but essentially it applies the The only way I can think of doing this without computed properties is: <button rv-class-highlight="user.password | checkPasswordAndConfirmation user.confirm">Submit</button> This actually seems less clear to me, and requires a formatter that is overly specific, rather than keeping the checking logic within the view-model where it probably should be. Couldn't we just say that if a binding has Although semver says we can break everything whenever we like, I think it's debatable whether Rivets should actually be at |
@Leeds-eBooks i missed you message
That fits my thinking 👍 |
it's a possibility, as |
@jccazeaux Ok I can live with that. Do you agree that in the example I showed above, computed properties are a good solution? Or is there a better way? |
I suggest to create some snippets with the use cases. And implement them using both Approaches. With computed and with call. |
Well my example wouldn't use <button rv-class-highlight="user.password | checkPasswordAndConfirmation user.confirm">Submit</button> How would you make this be evaluated when either I think rivets needs a way to evaluate x when y changes, and the only way to do that currently is computed properties. Unless I'm missing something obvious? I think keeping the computed property feature, and only auto-executing functions when the computed property feature is used, is a good compromise. Alternatively, and I haven't thought about this in depth because I've only just thought of it, perhaps we could keep the computed property feature but not auto-execute, so it would be something like: <button rv-class-highlight="ready < user.password user.confirm | call">Submit</button> |
@Leeds-eBooks For you example i would have done <button rv-class-highlight="ready | call user.password user.confirm">Submit</button> This means the function
For your idea about writing <button rv-class-highlight="ready < user.password user.confirm | call">Submit</button> It will work. @blikblum @Leeds-eBooks |
Ah, my apologies. I did not know that <button rv-class-highlight="ready | call user.password user.confirm">Submit</button> would re-call In which case, my use-case for computed properties is completely fulfilled by the If you submit a PR I think we can merge it, personally. |
OK I'll submit the PR ASAP |
Probably this may be closed |
In this issue, I would like to discuss the auto-execution of functions in Rivets expressions
If
myFunction
is a function, Rivets will execute it and send the result in the template.I think we should turn off this feature. It would allow us to manually call the function with parameters. This would be a powerfull feature for a very small cost. The manual execution would be handled by a formatter like
For backward compatibility reasons we could have a parameter in Rivets configuration
I know it's less user friendly than a JS expression. But it's in the rivets template syntax and would totally benefit of the existing databinding mecanism without any additional work.
I like rivets expression syntax, because it's very easy to learn but very powerful.
The text was updated successfully, but these errors were encountered: