eschwartz / backbone.googlemaps

A Backbone JS extension for interacting with the Google Maps API (v3.10)
MIT License
139 stars 55 forks source link

refresh does not reconstruct marker views #36

Closed halcyonandon closed 10 years ago

halcyonandon commented 10 years ago

on refresh, it executes: this.closeChildren(); this.render();

This unbinds the events, but the issue I hit is with collection filtering.

When models are filtered in and out, everything works fine, except

      // Trigger 'selected' and 'deselected' events
      this.on("change:selected", function(model, isSelected) {
        var topic = isSelected ? "selected" : "deselected";
        this.trigger(topic, this);
      }, this);

This never emits the event because its unbound and the constructor never executes again when models are added or removed.

I've been trying to find a good solution to this issue, however no such luck yet.

eschwartz commented 10 years ago

I think the problem is that we're using on/off methods for event binding instead of listenTo, stopListening.

MarkerView#close calls model.off() on it's Location model. This unbinds all events from the model, not just the events which were relevant to the MarkerView

Would you be up for putting together a pull request that fixes this?

halcyonandon commented 10 years ago

@eschwartz yes, sure, that's something I actually began doing already. Question, maybe you know the answer, if not it will become clear when I fully implement. When using stopListening, it will unbind all events, but the behavior of listenTo should unbind without needing to call stopListening on destruction of the view. Is stopListening necessary in this case?

eschwartz commented 10 years ago

but the behavior of listenTo should unbind without needing to call stopListening on destruction of the view

Events bound with listenTo will only be unbound when you call stopListening -- I guess I'm not sure exactly what you mean.

eschwartz commented 10 years ago

I'm going to close this for inactivity. Let me know if you're still having problems.