Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Wrong change events for space-containing field names #1455

Closed
yaroslav-ulanovych opened this Issue · 8 comments

5 participants

@yaroslav-ulanovych

When I set the following field to a model {"a b" : 1}, two events are triggered: change:a and b, which, I believe, is neither expected nor correct behaviour.

var model = new Backbone.Model();
model.bind("change:a", function() {console.log("change:a")});
model.bind("b", function() {console.log("b")});
model.set("a b", 5);

I know that:

  • real programmers don't use spaces
  • shit in shit out

but throw exceptions or document this at least.

@wuxq

everything is posible !

@braddunbar
Collaborator

Heya @yaroslav-ulanovych, thanks for your issue! This is definitely a result of the fact that trigger now accepts space separated events. Further, I can't find any documentation that says you shouldn't use attribute names with spaces (though I wouldn't recommend it).

@samhashemi

We've run into this same issue, and debugging it was no fun. Space separated events seems like a strange design choice. Why not just use an array, avoiding ambiguity?

object.trigger(['a b', 'another event with a space'])
@braddunbar braddunbar referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@braddunbar
Collaborator

Since the trigger api is not likely to change, I've added some documentation in #1459. Thanks for pointing this out!

@samhashemi

Any recommendation on what to do when 3rd party services are using spaces in their attribute names?

This happens to us a lot.

@braddunbar
Collaborator

Sure, I would definitely translate them in model.parse.

@ngauthier

This issue appears resolved. Should we close it?

@braddunbar
Collaborator

Yep, I think so. :)

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.