Search code examples
ember.jscoffeescriptpromisersvp.js

Calling an Ember _super method from Promise handler


I'm trying to make use of _super in the handler of a Promise inside of a Controller action, but it doesn't work because it seems to lose the correct chain of functions.

ApplicationRoute = Ember.Route.extend SimpleAuth.ApplicationRouteMixin,
  actions:
    sessionAuthenticationSucceeded: ->
      @get("session.user").then (user) =>
        if @get("session.isTemporaryPassword") or not user.get "lastLogin"
          @transitionTo "temp-password"
        else
          @_super()

I want to revert to the Mixin's default behavior on the else but I need to resolve user asynchronously before I can do a conditional statement. I tried:

ApplicationRoute = Ember.Route.extend SimpleAuth.ApplicationRouteMixin,
  actions:
    sessionAuthenticationSucceeded: ->
      _super = @_super
      @get("session.user").then (user) =>
        if @get("session.isTemporaryPassword") or not user.get "lastLogin"
          @transitionTo "temp-password"
        else
          _super()

and

ApplicationRoute = Ember.Route.extend SimpleAuth.ApplicationRouteMixin,
  actions:
    sessionAuthenticationSucceeded: ->
      @get("session.user").then (user) =>
        if @get("session.isTemporaryPassword") or not user.get "lastLogin"
          @transitionTo "temp-password"
        else
          @_super.bind(@)()

Neither works.

This answer claimed this should work as of 1.5.0, but I'm using 1.7.0-beta.5 and it's no go. Is there a way to get this to work, even in terms of approaching this differently?


Solution

  • Ember currently doesn't support calling _super asynchronously. In that example I'm not actually calling _super asynchronously, it's synchronous still.

    http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html#toc_ever-present-_super-breaking-bugfix