Skip to content

Loading…

CollectionView.render() should renderAllItems by default #168

Closed
csmosx opened this Issue · 5 comments

4 participants

@csmosx

CollectionView.render() should renderAllItems by default.
Not sure why rendering all items only happens on initalize and collection reset.

Other times you have to call render() and then renderAllItems() manually?
I would guess that majority of the time calling render() you would expect the a CollectionView to also render its items.

To accomodate, maybe do

initialize: (options = {}) -> 
  @render(options.renderItems) if options.render

render(renderItems = true)
  @renderAllItems() unless renderItems is false
@molily
Chaplin – JavaScript Application Architecture Using Backbone.js member

Good catch! Yep, I agree, this is an inconsistency. By calling render, one would expect to also render the items.

Also there’s a little inconsistency regarding the render option. Normal views have an autoRender option, but CollectionView has render and renderItems which should be the standard autoRender and the special renderItems.

@csmosx

That's true too.
Should be more like this

autoRender: true
@render(options.renderItems) if @autoRender 

Do you know what's up with these "after" methods, like afterRender and afterInitialize?
I don't understand their usefulness, what with super being so super and all.

@csmosx

Actually, automatic rendering inconsistency is pretty confusing...

I don't know whether I'd prefer autoRender be true or false, but having CollectionViews autoRender by default and Views not isn't good.

I think I lean toward autoRender false as the default.

@molily
Chaplin – JavaScript Application Architecture Using Backbone.js member

afterInitialize and afterRender are necessary to implement automatic rendering (autoRender option) and automatic appending to the DOM (container option). The original initialize and render methods of a view class are wrapped so afterInitialize and afterRender are guaranteed to be called after the specific code (if any). This cannot be implemented using super calls alone because render should be called after all initialization code and appending to the DOM should happen after all rendering code has been processed (generally).

As a user, one shouldn’t need to override these methods in general. It’s possible, but it’s better to override initialize and render if necessary.

The upcoming documentation will explain this mechanism more deeply.

I think I lean toward autoRender false as the default.

Agree, they should behave the same (CollectionView is just a View anyway).

Thanks for the good feedback so far!

@paulmillr paulmillr was assigned
@paulmillr paulmillr closed this in 1ba8fb8
@Rendez

@paulmillr excellent. cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.