New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic bindings for form events #49

Closed
mehcode opened this Issue Jan 15, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@mehcode

mehcode commented Jan 15, 2013

Looking at https://github.com/NYTimes/backbone.stickit/blob/master/backbone.stickit.js#L115-L136; I notice you're throwing events into this.events and then re-invoking this.delegateEvents.

Can we change that to invoking this.$el.on and then (on unstickit) calling this.$el.off?

The main problem is as follows:

List = Backbone.View.extend({

  bindings: {
    '.actions .selector': {
      observe: '$checked'
    }
  },

  events: {
    'change .selector': function(event) {
      // ...
    }
  }

);

I only want the manual event binding to be invoked when directly changing the checkbox via a click. However, I do want the the bindings hash to sync the state of the checkbox with the model.

@delambo

This comment has been minimized.

Show comment
Hide comment
@delambo

delambo Jan 16, 2013

Member

@mehcode - I'm not quite sure what the problem or use case is. The last couple of sentences read: "I want the manual event binding to be invoked ... I want the bindings hash to sync the state." That should be the case.

Member

delambo commented Jan 16, 2013

@mehcode - I'm not quite sure what the problem or use case is. The last couple of sentences read: "I want the manual event binding to be invoked ... I want the bindings hash to sync the state." That should be the case.

@mehcode

This comment has been minimized.

Show comment
Hide comment
@mehcode

mehcode Jan 16, 2013

Apologies if I'm not being clear.

The bindings hash is working great. All events surrounding it are good.

However; the additional event that is bound in the events hash is not being fired. After investigating the source I discovered that you're overwriting this.events with events generated from this.bindings. My suggestion is to use view.$el.on instead so this.events works and is not overwritten by the events from this.bindings.


Let me know if you need a full example.

mehcode commented Jan 16, 2013

Apologies if I'm not being clear.

The bindings hash is working great. All events surrounding it are good.

However; the additional event that is bound in the events hash is not being fired. After investigating the source I discovered that you're overwriting this.events with events generated from this.bindings. My suggestion is to use view.$el.on instead so this.events works and is not overwritten by the events from this.bindings.


Let me know if you need a full example.

@delambo

This comment has been minimized.

Show comment
Hide comment
@delambo

delambo Jan 17, 2013

Member

Ah, that's a bug. I fixed this by namespacing the event - I would like for Backbone to handle undelegating so that binding events can be released in the life cycle of other events. Let me know if you spot something wrong with that idea. Thanks, again!

Member

delambo commented Jan 17, 2013

Ah, that's a bug. I fixed this by namespacing the event - I would like for Backbone to handle undelegating so that binding events can be released in the life cycle of other events. Let me know if you spot something wrong with that idea. Thanks, again!

@delambo delambo closed this Jan 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment