ripplejs / ripple

A tiny foundation for building reactive views
http://ripplejs.github.io
1.28k stars 66 forks source link

how does data flow to children? #35

Closed matthewmueller closed 10 years ago

matthewmueller commented 10 years ago

Starting to play with ripple and reading the composition docs. It says that the parents pass the data to the children. I'm a bit confused on what you give the parents to render the children correctly. Is it an array of objects? Example:

[
  {
    username: "anthony",
    ...
  },
  {
    username: "matt",
    ...
  }
]
anthonyshort commented 10 years ago

Do you mean iteration or just sending data to children?

When you compose another view like .compose('foo', MyView) you use it in your templates like a custom element.

<foo></foo>

It'll just create an instance of MyView and replace that element. Then you can send data and keep it in sync using attributes

<foo name="{{bar}}"></foo>

This will set the name property of the MyView instance to whatever the bar value is on the parent.

It's really just an abstraction so you don't need to create sub-views in the class and the render them yourself and keep properties in sync.

For lists of views things are a bit trickier. I'm working on this plugin to make it easier or there's the each plugin for that. The second one just creates views for you on the fly using the template.

anthonyshort commented 10 years ago

https://github.com/ripplejs/ripple/blob/master/lib/bindings/child.js#L22

In the child-binding that's where it's send through the data. That's the binding that handles the "custom" elements and keeps properties in sync between the parent and child.

matthewmueller commented 10 years ago

Ahh yup, that answers my question. I was wondering about how ripple would render lists or any one-to-many view relationship. Thanks!

anthonyshort commented 10 years ago

No probs, lists are a pain in the ass. I want to try and avoid as much magic as possible for them as well.

matthewmueller commented 10 years ago

hahaha yah.. i've spent too much time thinking about list views. they're awful. sounds good though!