TylerGarlick / angular.flashr

Rails Flashing in AngularJS
12 stars 2 forks source link

Add UI Router support #2

Open bvaughn opened 9 years ago

bvaughn commented 9 years ago

First off, Flashr is nice. Thanks for creating it!

UI Router is also nice, so it'd be great if Flashr supported it out of the box. Supporting it would be as simple as responding to either $stateChangeSuccess or $routeChangeSuccess events, so for instance:

var displayLaterMessages = function() {
  for (var i = 0; i < _toasts.length; i++) {
    var object = _toasts[i];
    toast(object.type, object.msg);
    _toasts = _.difference(object, _toasts);
  }
});

$rootScope.$on('$stateChangeSuccess', displayLaterMessages);
$rootScope.$on('$routeChangeSuccess', displayLaterMessages);

Another small change I made locally (that you might consider making?) would be to clear current (now) messages when a state change is initiated, so:

$rootScope.$on('$routeChangeStart', function() {
  toastr.clear();
});
$rootScope.$on('$stateChangeStart', function() {
  toastr.clear();
});
TylerGarlick commented 9 years ago

I'll see what I can do to add it in. Thanks!

hgirish commented 9 years ago

Line 17: var toast = _toasts[i]; The variable name toast is conflicting with function toast defined towards the end.

bvaughn commented 9 years ago

D'oh. That's what I get for trying to do a quick clean-up before copying over my patch. Sorry about that. Updated my comment.