Correct place to run a function every time something happens

Hey all,

I’d like to get some design feedback. We need to implement a timeout checker on our app so that if they do something after the timeout, we can redirect them to the login page. I was trying to find the best place to run a small snippet of JS on every “action” - route transition, action, etc. It doesn’t need to happen on mouseup/down/move, just every time somebody does something real.

I was thinking of just putting some default code in Ember.View’s didInsertElement or similar, but that seems hacky. I looked at Ember.run.schedule(), but that only seemed to run once. I was hoping that might run something every time the Run Loop runs.

Any ideas on where best to place this would be most appreciated!

Thanks, Scott

This is probably appropriate for StackOverflow, but have a few options available to you

  • Observe the currentPath property on ApplicationController for changes (which happens after every route change)
  • Put logic in activate or deactivate in Ember.Route, which will fire when entering or exiting a route, respectively

And of course just enhancing your {{action}} handlers in your controllers or routes to do whatever you want makes sense;

1 Like

Observing currentPath will not work for ember-engine