5

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?

Community
  • 1
  • 1
neverfox
  • 6,680
  • 7
  • 31
  • 40

2 Answers2

3

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

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
0

In order to continue the bubbling you need to call this.target.send() with the name of the action.

see: How can I bubble up an Ember action inside a callback function?

Something like this should work:

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
          @target.send('sessionAuthenticationSucceeded')
Community
  • 1
  • 1
tikotzky
  • 2,542
  • 1
  • 17
  • 20
  • Hmm, will that work for what I want to accomplish? I want to have the default behavior (found in the Mixin code) run on an `else`, not to bubble the action to a different class in the chain. – neverfox Sep 18 '14 at 02:52