walmartlabs / thorax

Strengthening your Backbone
http://thoraxjs.org/
Other
1.32k stars 129 forks source link

The "itemView" property can now take a function. #385

Closed izaakschroeder closed 9 years ago

izaakschroeder commented 9 years ago

NB: Tests need to be written for this yet.

Normally the itemView property of a Thorax.CollectionView expects either a string or a Thorax.View constructor. We just tweak the checks in getViewInstance to be smarter about detecting whether the function is a constructor of a Thorax.View or not; if it is a constructor it behaves just as before, and if not we attempt to invoke it as a method of the parent view (by passing this through).

izaakschroeder commented 9 years ago

Also your CI is broken. Can't find module graceful-fs

kpdecker commented 9 years ago

Humm. This is counter to some of the performance changes we just made due to the .call usage that we are now trying to avoid and also impacts the API a bit. What if we instead added a 3rd parameter to getViewInstance that would allow the context to be passed?

Something like:

Thorax.Util.getViewInstance(this.itemView, viewOptions, this)

This would remain backwards compatible and require little overhead vs. the current implementation.