2014-09-18 13 views
5

से एम्बर _super विधि को कॉल करना मैं नियंत्रक कार्रवाई के अंदर एक वादे के हैंडलर में _super का उपयोग करने की कोशिश कर रहा हूं, लेकिन यह काम नहीं करता है क्योंकि ऐसा लगता है कि यह कार्य की सही श्रृंखला खो देता है।वादा हैंडलर

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() 

मैं else पर Mixin के डिफ़ॉल्ट व्यवहार को वापस करना चाहते, लेकिन मैं इससे पहले कि मैं एक सशर्त बयान कर सकते हैं एसिंक्रोनस रूप user को हल करने की जरूरत है। मैंने कोशिश की:

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() 

और

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(@)() 

न तो काम करता है।

This answer ने दावा किया कि यह 1.5.0 के रूप में काम करना चाहिए, लेकिन मैं 1.7.0-बीटा 5 का उपयोग कर रहा हूं और यह नहीं है। क्या इसे अलग करने के मामले में भी काम करने के लिए कोई रास्ता है?

उत्तर

3

एंबर वर्तमान में _super एसिंक्रोनस रूप से कॉल करने का समर्थन नहीं करता है। उस उदाहरण में मैं वास्तव में _super को असीमित रूप से कॉल नहीं कर रहा हूं, यह अभी भी तुल्यकालिक है।

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

0

बुलबुले को जारी रखने के लिए आपको कार्रवाई के नाम से this.target.send() पर कॉल करने की आवश्यकता है।

देखें: How can I bubble up an Ember action inside a callback function?

कुछ इस तरह काम करना चाहिए:

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') 
+0

हम्म, क्या वह काम करेगा जो मैं पूरा करना चाहता हूं? मैं 'अन्य' पर चलने वाले डिफ़ॉल्ट व्यवहार (मिक्सिन कोड में पाया) चाहता हूं, श्रृंखला में किसी भिन्न वर्ग में कार्रवाई को बुलबुला नहीं करना चाहता हूं। – neverfox

संबंधित मुद्दे