gfk-ba / meteor-notifications

Add reactive notifications to your meteor application
http://notifications-example.meteor.com/
MIT License
82 stars 21 forks source link

Using notifications inside an autorun #15

Open andylash opened 10 years ago

andylash commented 10 years ago

I'm not sure that there is a solution here, but I wanted to make an issue to get comments and then to help future people. I find I'm often creating a notification on error inside an autorun. Something like this might appear in a template's rendered function:

this.autorun(function() {
  var status = doOperation();
  if (!status) {
    Notifications.error("Status failed");
  }
});

The problem is that this is that the notification insert forces this method to rerun, which isn't desired. So instead I do this:

this.autorun(function() {
  var status = doOperation();
  if (!status) {
    Tracker.nonreactive(function() {
      Notifications.error("Status failed");
    });
  }
});

I'm not sure if the library could handle this case, but it would be nice for callers if it could. Maybe it's just a doc change?

marcodejongh commented 9 years ago

@andylash Sorry for the late response. The errors/succes/addNotification methods should probaply be made nonreactive.

The package only uses the client side collection to leverage Blaze for the rendering. So the reactivity is only used internally for drawing of templates