rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 312 forks source link

On client-load, _block subviews don't get their passed-in model. #501

Closed michaelarick closed 8 years ago

michaelarick commented 8 years ago

I have a view with the following template:

.todo-list
  == _block

And the view does this in postRender:

postRender: function() {
    _.each(this.childViews, function(childView) {
      this.listenTo(childView, 'ch:completed', this.handleCompletedItem);
    }.bind(this));
  },

So where that view is used, I should be able to put subviews in and have them be child views of the view, and have my top-level view, the todo-list, know when a subview triggers ch:completed:

For example:

 = view 'components/todo_list'
        = view 'petitions/manage/components/todo_list/fake_item' model=_model

This code works fine as long as the view is server-side rendered. When it is client-side rendered, the todo_list/fake_item doesn't know about its model.

Any suggestions on how to solve or workaround this would be appreciated.

bigethan commented 8 years ago

I think the issue here is a client side async race condition. I'm a bit fuzzy on the details of how we worked around it, but we had to listen to something that'd wait for the child views to be ready. @ingiulio might better remember...

saponifi3d commented 8 years ago

@michaelarick it's because of the way you're passing the scopes around - set the model variable on the view to explicitly pass it in.

= view 'components/todo_list' model=_model
  = view '/petition/manage/components/todo_list/fake_item' model=model

also, for general questions please post to the stackoverflow questions http://stackoverflow.com/questions/tagged/rendr ideally would like to keep the issues to be issues w/ rendr and bug reporting and questions on stackoverflow :)