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

Ractive set events not firing #423

Closed
quangv opened this issue Feb 2, 2014 · 2 comments
Closed

Ractive set events not firing #423

quangv opened this issue Feb 2, 2014 · 2 comments

Comments

@quangv
Copy link
Contributor

quangv commented Feb 2, 2014

If I read https://github.com/RactiveJS/Ractive/wiki/Events correctly, the following should work?

var ractive = new Ractive({})

ractive.on('set', function(){
    console.log('this should fire on set');
});

ractive.set('foo', 'bar');

http://jsfiddle.net/Lq3sL/

@Rich-Harris
Copy link
Member

The documentation is out of date, sorry about that. I've just raised an issue on the docs repo. There is a change event you can listen to - this will only fire when data changes, as opposed to when the set() method is called.

I found a combination of ractive.on('change', changeHandler) and ractive.observe('foo', fooObserver) to be much more useful than listening for set events, but I'm open to persuasion if this is something that should be included. Though you can add the event fairly easily:

Ractive = Ractive.extend({
  set: function ( keypath, value, callback ) {
    this.fire( 'set', keypath, value );
    return this._super( keypath, value, callback );
  }
});

@quangv
Copy link
Contributor Author

quangv commented Mar 2, 2014

thanks for the explanation Rich.

@quangv quangv closed this as completed Mar 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants