title: How to resolve a Promise only after a state change
body: <p>I am trying to resolve a Promise only after a certain condition is met outside the promise:</p>
  
  <pre><code>class myClass extends ... {
  
      render() {
         ...
         this.fetch();
         ....
      }
  
      fetch(){
          Promise.all([
            ....,
            ....,
            ....
          ]).then( () =&gt; {
            // new Promise or somthing like that
            // wait for state changed to resolve it
          }
          ).then(
            // do something
          )
      }
  
      stateChanged(state){
          if(condition){
             // resolve promise from here
          }
      }
  
  }
  </code></pre>
  
  <p>I tried to implement it in similar way to this question 
  <a href="https://stackoverflow.com/questions/26150232/resolve-javascript-promise-outside-function-scope">Resolve Javascript Promise outside function scope</a>
  but I do not understand </p>
  
  <ol>
  <li>how we can call a variable</li>
  <li>how to make this work inside my Class
  I tried it with a <code>this.waitForPromise = null</code> variable, but when I call 
  it later <code>this.waitForPromise()</code> I get a is not a function Type error.</li>
  </ol>
  
  <pre><code>class myClass extends ... {
  
      render() {
         ...
         this.fetch();
         ....
      }
  
      constructor(){
          this._waitForPromise = null;
      }
  
      fetch(){
          Promise.all([
            ....,
            ....,
            ....
          ]).then( () =&gt; {
              new Promise(function(resolve, reject) { 
                this._waitForPromise = resolve; 
              });
          }
          ).then(
            // do something
          )
      }
  
      stateChanged(state){
          if(condition){
             this._waitForPromise();
          }
      }
  
  }
  </code></pre>
  
  <p>Any help and explanation is much appreciated.</p>