peerlibrary / meteor-blaze-components

Reusable components for Blaze
http://components.meteorapp.com/
BSD 3-Clause "New" or "Revised" License
354 stars 26 forks source link

How to get outer context within `currentData`? #116

Closed AlexFrazer closed 8 years ago

AlexFrazer commented 8 years ago

I want to get the outer context within an each loop

each orders
  // some stuff goes here
  each products
    with line
      | {{ total }}

The line helper would look as follows

line() {
  return this.currentData('../').lines.find(line => line.productId === this.currentData()._id);
}

Logically, it feels like it should work to get the outer order and get the lines field, but it does not work. How do you do this with this library?

mitar commented 8 years ago

So I was reluctant to introduce this because it leads to code which is tightly coupled with current HTML template. And can easily break. So the proposed approach for this is that you create another component for each line. And then you navigate to parent component instance and use data() there. So instead of having unclear hierarchy of data contexts, you have clear hierarchy of components, where each one has its own data context and you can access it. Something like parentComponent().data().

AlexFrazer commented 8 years ago

I see, that makes a lot of sense, thank you for the quick response!