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 waitpromiseproperty 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
Post a Comment