Skip to content
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

can.Observe binds for nested object. First time event trigger is only on top level object instead of nested one. #280

Closed
schovi opened this issue Feb 12, 2013 · 5 comments
Assignees
Labels
Milestone

Comments

@schovi
Copy link
Contributor

schovi commented Feb 12, 2013

When bind for notifications.users and sets {notifications: {users: 10}} event will be triggered on notifications and new value is {users:10}. But when removing notifications.users or sets it again it trigger event correctly with value 10
Fiddle there http://jsfiddle.net/EJBqw/
Example with bind change http://jsfiddle.net/EJBqw/1/

@justinbmeyer
Copy link
Contributor

Interesting, I'm surprised that the first

observe.attr({notifications: {users: 10}})

triggers a notifications.users event at all. I would assume it would only trigger a notification event. It seems like it was, but being called notifications.users.

@justinbmeyer
Copy link
Contributor

I just looked into this. I'm not sure what to do about this. Here's the central issue:

var foo = {}
$(foo).bind("one.two", function(){ console.log('1.2')})
$(foo).bind("one", function(){ console.log('1')})
$(foo).trigger("one")
// -> 1.2
// -> 1

The problem is that jQuery's event system will dispatch a "one" event to listeners "one" and "one.two".

We use this functionality in a few places (for observe's bubbling), but not enough so we need it.

We can either ...

  1. Use our own trigger that does not do this and
    remove where we depend on this behavior
    • Faster dispatching
    • slightly bigger download
    • might not work perfectly with jQuery's event system. Say a component
      triggers events on an object, can we listen to them. We might be able to
      get around this by having an extra param on can.bind that says only match
      the full event name. This param would be used by Observe's bind.
  2. Wrap all observe binds in some magic that doesn't call the original callback
  • another function !

@schovi
Copy link
Contributor Author

schovi commented Mar 22, 2013

Finally I had time to understand this a little bit more.

Solutions like another function or extra param are pretty obvious, but API will be complicated. Now there is bind and delegate and sometimes i am confused :) And secod problem i see in using it inside a control "{observer} one.two" how to tell Can there what bind to use.

@justinbmeyer
Copy link
Contributor

I say we leave jQuery's event system for can.Map in 1.2.

@ghost ghost assigned justinbmeyer Sep 20, 2013
justinbmeyer added a commit that referenced this issue Oct 28, 2013
avoids jQuery's event system when binding on observes which fixes #280
@schovi
Copy link
Contributor Author

schovi commented Oct 28, 2013

sweet :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants