javascript - How can a component obtain a value synchronously from its parent? -


consider following ember component using semantic ui:

import ember 'ember';  export default ember.component.extend({   classnames: ['ui', 'mini', 'modal'],   didinsertelement() {     this.$().modal({       onapprove: () => {         let promise = // obtain promise parent... somehow         promise.then(() => {           this.$().modal('hide');         });         return false;       }     });   } }); 

the modal dialog initialized element accessible. onapprove option specifies callback invoked when user clicks "ok" in dialog. component's parent supplies ember.rsvp.promise, when resolved, closes dialog.

herein lies problem — how obtain promise parent? considered following possibilities:

  • the parent supply action invoked:

    {{modal-dialog action='getpromise'}} 

    however, actions cannot return values, although component invoke action, not use obtain promise.

  • the parent supply promise bound property:

    {{modal-dialog promise=promise}} 

    the problem approach didinsertelement() cannot obtain promise since component must wait promise property mutate.

is there way component ask parent value in synchronous manner?

closure action return value can return promise in closure action.

{{modal-dialog getpromise=(action 'getpromise'}} 

if getpromise method returning promise can let promise = this.get('getpromise')()


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -