Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Wrong change events for space-containing field names #1455

Closed
yaroslav-ulanovych opened this Issue · 8 comments

5 participants

Yaroslav Ulanovych wuxq Brad Dunbar Sam Hashemi Nick Gauthier
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 !

Brad Dunbar
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).

Sam Hashemi

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'])
Brad Dunbar braddunbar referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Brad Dunbar
Collaborator

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

Sam Hashemi

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

This happens to us a lot.

Brad Dunbar
Collaborator

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

Nick Gauthier

This issue appears resolved. Should we close it?

Brad Dunbar
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.