likely.js
likely.js copied to clipboard
Conditional inline attrubutes
Hi bastiste.
I really like this library. Awesome work. I've been looking for a library like this, one which doesn't watch for changes to the model, virtual dom based and didn't force any base class requirement on the model or view.
I'd near given up looking when I stumbled upon this. It dovetails nicely with an entity library I have developed called supermodels.js. I'm currently doing some testing between the two and they work really well together so far.
One use case that I can't seem to work out is conditional, inline attributes. E.g. let's say I need an button tag to have a 'disabled' attribute when a form is in an invalid state. Sure, I could use if/else control flow and define the button tag twice but it would be nice to be able to write this inline.
Am I missing a trick. If not, do you see a way it could be introduced?
Cheers
Dave
Hello Dave! Thanks for the kind words.
If fact this is rather easy to do already with likely.js
input disabled={{ false }}
input disabled={{ any variable or expression that evaluate to false }}
When an attribute is strictly equal to false then the attribute is simply not rendered. Being "falsy" like 0 or null is not enough. It has to be strictly the value false.
https://github.com/batiste/likely.js/blob/master/template.js#L326
I hope that helps.
Cheers, Batiste
Brilliant!
I actually looked over that file - not sure how I missed it!
I'll let you know how the integration with my library goes, but so far they seem to compliment each other very well.
I really like the approach of likely.js - it really deserves much more attention (I realise this isn't an easy thing to achieve in open source though).
Can I ask if/would you use it in any of your sites? I read that you built it as a learning exercise but I'm interested to hear if you have used it in production and if so, how you found it.
Also, is it something you are still interested in or has your focus shifted to new things?
Thanks for your help,
Dave
Hi Dave,
It is indeed quite hard to get any traction in Open Source considering the plethoras of libraries. Big companies release libraries have a better luck (Angular.js) although the foundation behind them can be quite bad and the support behind them can also be dropped at any time.
Likely.js as a template language for generating/diff HTML should be more than enough and I don't plan to evolve or work on it unless some major flaws appear. I never used it myself for nothing more than the TODOMVC example and a couple of small projects here and there.
My focus has indeed focused on new things like lately. Maybe have a look at https://github.com/batiste/CokeScript
This is a language which has the similar features to likely.js (although no events or data binding)
This is the natural evolution in some way... If I create a new template language why not creating a whole new language which has template/diff capabilities? A bit like what React is doing but a step further.