

Rivets.js - Binding data to views - ansman
http://rivetsjs.com/

======
joshontheweb
I've never been able to get behind defining data relationships in the DOM. I
do like the idea of not having to re-render the entire view or explicitly
update individual elements on data change events, but i wish there was a
better way. Perhaps a view could contain a hash associating data change events
with element selectors. Then the view knows which element to update. That way
the html clean and ignorant of the underpinnings of the app.

~~~
amccloud
I'm had the same exact thought. That's why I created
<https://github.com/amccloud/backbone-bindings>

~~~
joshontheweb
Nice, This is cool, pretty much what I had in mind with some cool additional
features. It seems like you could just pass the template to bindModel, fire a
change, and have it do the initial render and cut out _.template altogether.

~~~
amccloud
Template markup is generally more complex than that and certainly more complex
than your bindings. The ability for designers to edit and change the markup
without having to look at code is a plus for using templates. Not to mention
as a backbone convention it is expected so it makes things more portable.

------
lylejohnson
Why would I choose Rivets over competing options, such as Knockout?

~~~
ansman
You're comparing apples and oranges, Knockout is a lib for structuring your
app while this is a small lib that doesn't do anything more than data binds.

This could be used with backbone or any other lib that doesn't have data
binds.

~~~
tptacek
I'm not sure that's true; KO is mostly data binds too, and doesn't impose much
of any structure on your application.

Since it would make no apparent sense to use _both_ KO and Rivet, the original
question seems germane.

Is the answer then "because Rivets does less"?

~~~
ansman
Well, they do have different goals. Rivets wants to be a small plugin that
works with any framework while knockout is also designed to bring structure to
the party. For me it's like comparing an engine with a car.

One big upside to knockout is that the lib is a little under 3KB minified
while knockout is 40KB minified.

I prefer having smaller libraries that are really good at what they do.

~~~
tptacek
What "structure" are we talking about with KO? I've been using it for a couple
weeks just to do binding, and I haven't noticed it introducing any particular
structure to my applications.

It is _nothing_ like Backbone, which really seems to want you to write a
"Backbone" app.

------
jashkenas
Take a peek at the implementation if you haven't already -- it's easy to
browse through in a minute or two:

[https://github.com/mikeric/rivets/blob/master/src/rivets.cof...](https://github.com/mikeric/rivets/blob/master/src/rivets.coffee)

... although one thing to note is that it looks like it doesn't currently
support IE (< 9).

------
nateabele
How is this different from/better than Angular?

------
pantsbird
Every time we move away from this ugly logic embedded in the view idea some
Rube Goldberg fan (probably with a java struts or other such messy room
coding) stacks this stuff back into the world. The fact of the matter is
program problems are never difficult enough to merit this kind of abstraction
and if in some future where this is necessary it certainly won't be this
version or in this syntax.

To summarize; Not only do I think this is excessive beyond MVC, but it is also
jumping the gun by a decade minimum. I don't need smarty templates, I don't
need overloaded HTML attributes and I don't need this. Good day to you.

~~~
ansman
So how would you solve updating a view after rendering? Do you want your view
to know about the markup in your template.

I'm really curious, is there a better way?

------
jarek-foksa
It would be great if we could just have Object.watch('property', callback) or
similar method defined in ES.next.

I don't want to wrap my models with ugly frameworks, all I need is a way to
fire a callback when my model changes.

There is a lot of talk on various MVC frameworks, but lets not forget that
manual syncing of views and models has some advantages, e.g. you can improve
performance by combining many subsequent DOM operations or by temporarily
detaching the parent from DOM tree.

------
nestlequ1k
Looks like a pretty nice little alternative to Handlebars/Ember.js for really
simple data bindings. I could see myself using this quite often.

------
netghost
Neat idea, I like that it's agnostic about the model layer. I have to admit
that I'm fiddling around with a very similar library (still a work in
progress):

<https://adamsanderson.github.com/ivy/>

Lots of people are looking for better ways to deal with data in their views :)

------
zimbatm
After a quick glance it seems that it doesn't support iterations. How would
you use it with a list of users ?

~~~
mgcross
Looks like it would be possible with a formatter and the data-html binding.

------
1qaz2wsx3edc
This is most similar to AngularJS. `data-hide` <=> `ng-hide`

------
swah
How do you work when you have two or more of those depending on each other?

Also, when a data value changes do you re-render the whole thing, of just the
affected node?

~~~
ansman
Don't think you can have dependencies.

It just updates the specified part (data-value updates the value, data-html
updates the innerHTML etc)

------
bdfh42
lots of knowledgeable comments being made here already so clearly this is an
interesting area but - what is the use case for this? I don't understand why I
might need it.

~~~
ansman
This is pretty much only useful for JS apps. The problem comes when you have
data changing after a view has been rendered.

Rendering the whole view again can be expensive. As well as this the user
might have interacted with the page in which would probably make the user
loose his changes.

------
arunoda
Great idea. I like it. I'm looking at this as a template engine? Or am I
missing something?

~~~
ansman
It template agnostic, once you've rendered your view you give rivets your DOM
element and it will find the data attributes. You could use handlebars, haml
or any other templating engine with rivets.

~~~
arunoda
okay. I got it. Actually this replaces separate templates (at least for some
cases) for your app. How about the browser compatibility? Have you tested?

------
arunoda
Can you please describe what is the use of the adapter? How can it be useful?

