Backbone.ModelBinder icon indicating copy to clipboard operation
Backbone.ModelBinder copied to clipboard

ModelBinder requires non-standard and non-documented close() function in views

Open Derbeth opened this issue 11 years ago • 7 comments

I regularly come across the following warning in JS logs:

warning, you should implement a close() function for your view, you might end up with zombies

ModelBinder emits this from removeEl() function.

The official Backbone documentation does not mention any function named close(), specifically not for views. Also ModelBinder's Readme does not mention close() anywhere. However, Backbone 0.9.6 introduced View#remove, which correctly unbinds events in addition to removing element from DOM. I think you should expect and call remove() instead of close().

Derbeth avatar Apr 21 '13 09:04 Derbeth

Agreed.

I've already adopted this tact by adding a function to my standard wrapper on View:

close:  function() { this.remove(); }

katowulf avatar Apr 21 '13 18:04 katowulf

Agree :+1:

lastquestion avatar May 02 '13 07:05 lastquestion

At some point in the near future, I will just add a check to see if the remove function is defined on the view and call that. I need to keep close around for a large code base.

theironcook avatar May 02 '13 13:05 theironcook

Remove is always defined as it's part of the API. I suppose it could call both for backwards compatibility?

katowulf avatar May 02 '13 15:05 katowulf

katowulf is right. Every class derived from Backbone.View has the remove() function.

Since ModelBinder 1.0.0 the required version of Backbone is 1.0.0, so I think there is no point having any checks for "backward compatibility" for features introduced already in Backbone 0.9.6.

Derbeth avatar May 06 '13 11:05 Derbeth

@Derberth right, my point in backwards compatibility was with ModelBinder, not Backbone--some people could be relying on the existence of the close function. So maybe it should continue to check for that, or maybe not, that's a tough call.

katowulf avatar May 06 '13 13:05 katowulf

As an aside, it would be nice to be able to specify what that function should be. At my company, we have a pattern where we implement a dispose() function which does pretty much exactly the same thing, and it's somewhat annoying that this one relies on close(). Maybe if it were an optional thing (in a new release, since that's backwards-compatible), then the view factory could simply use whatever function name is passed in as an option. Much more flexible!

platinumazure avatar Feb 09 '15 02:02 platinumazure