2016-07-11 1 views
1

를 해결 한 후 슈퍼 액션을 호출하고 내 하위 클래스에서 해당 작업을 잡으려면하는 전화 약속을 해결하고 약속이 해결되면 supers 조치를 실행하는 함수.EmberJS은 - 약속 내가 엠버 2.6.0</p> <p>나는 행동에서 정의 된 일부 기능이 타사 구성 요소를 확장하고 사용하고

import Ember from 'ember'; 

export default Ember.Component.extend({ 
    actions: { 
    theAction() { 
     this._somePrivateFunction(); 
     //do other stuff 
    } 
    } 
}); 

을 그리고 내 하위 클래스에서 내가 뭐하는 거지 :

그래서 타사 구성 요소는이 작업을 수행 약속 콜백에서 호출 할 때

import Ember from 'ember'; 
import ThirdPartyComponent from 'path/to/component' 

export default ThirdPartyComponent.extend({ 
    _funcThatReturnsPromise() { 
    return new Ember.RSVP.Promise(); 
    } 
    actions: { 
    theAction() { 
     const thePromise = this._funcThatReturnsPromise(); 
     thePromise.then(() => { 
      // undefined! 
      this._super(...arguments); 
     }) 
    } 
    } 
}); 

this._super()

는 상위 구성 요소의 행동에 해결되지 않습니다. I는 속성으로 수퍼 함수를 ​​저장하고 호출 시도했다 :

theAction() { 
      const thePromise = this._funcThatReturnsPromise(); 
      this.set('superFunc', this._super); 
      thePromise.then(() => { 
      // calls the super but "this" inside the supers action is undefined 
      this._super(...arguments); 
     }) 
    } 

을 더하여 추 것에는 수퍼 액션 내부 this 결과는 정의되지한다. 내가 왜 그런지 모르겠다. 일부 문서를보고있다.

또한 내 서브 클래스의 행동에 send()를 호출 할 수있는 옵션이 있습니다 :

theAction() { 
     const thePromise = this._funcThatReturnsPromise(); 
     this.set('superFunc', this._super); 
     thePromise.then(() => { 
      //infinite loop! 
      this.send('theAction'); 
     }); 
    } 

그러나 무한 루프에서이 과정의 결과 함수는 자신을 호출 끝 때문이다.

여기를 계속하는 방법을 모르겠습니다. 아무도 내가 여기에서하려고하는 것을 할 수있는 깨끗한 방법이 있다면 말해 줄 수 있습니까? 어떤 조언을 주시면 감사하겠습니다. 감사합니다! 하위 구성 요소에서

+0

'상자 밖으로 작동합니다. – Bergi

+0

@Bergi 예, 이상적인 경우가 될 것입니다. 그러나 Emberjs 구성 요소의 범위 내에서 작업하고 있습니다 .- ( – TheMethod

답변

0

이 좋아 할 : 당신이 진짜 ES6`class`,`super.theAction (...)와 함께 작업하는 경우

theAction() { 
     const thePromise = this._funcThatReturnsPromise(); 
     let parentAction = this._super; 
     let self = this; 
     thePromise.then(() => { 
      //parent usage 
      parentAction(); 

      // this usage 
      self.doSome(); 
     }); 
    } 
+0

@ Ebrahim Pasbani 위에서 질문 한 내용에서 이미 시도 했으므로 'this'는 부모 동작 내부에서 정의되지 않았습니다. 이 방법 – TheMethod

+0

@TheMethod 아니, 당신이 뭔가 다른 시도했다. 당신이 틀린 것입니다 구성 요소의 속성으로 설정 한 –

+0

답장을 보내 주셔서 감사합니다. this._super "속성 또는 함수 범위 변수에 할당 여부 – TheMethod

관련 문제