ManuelDeLeon / viewmodel-react

Create your React components with view models.
MIT License
24 stars 3 forks source link

Viewmodel with Meteor throws an error when trying to render a meteor collection from server-side #26

Closed antoninadert closed 7 years ago

antoninadert commented 7 years ago

I wanted to load some state from a meteor (mongo) collection


import Ads from '../_Collections/Ads'

AdsList({
  ads: function () {
    if(Meteor.isClient) {
      return Ads.find({});
    }
    if(Meteor.isServer) {
      return []
    }
  }, 
render() {
    <ul>
      <li b="repeat: ads">
        <span b="text: repeatObject.title + ' ' +repeatObject.description"></span>
      </li>
    </ul>
  }
});

sadly I have to differentiate client and server-side with my if condition, because otherwise if I try to return the collection from the server, VM will throw this error (because of tracker): my-app-path/node_modules/viewmodel-react/dist/tracker.js:434 if (inCompute) throw new Error("Can't flush inside Tracker.autorun") at Timer.listOnTimeout (timers.js:92:15)

ManuelDeLeon commented 7 years ago

You probably need to set ViewModel.Tracker = Tracker; on the server as well.

antoninadert commented 7 years ago

so I tried that and no more error from VM, but I still have problems using a collection for SSR. I believe it has to do with meteor's promise system more than Viewmodel at this point, so I close the issue.