#async function to render text
1 messages · Page 1 of 1 (latest)
So the library that I'm using .. uses a webworker to generate the mathML markup to speech.. thats why it's in a async
getPromiseState is a nice utility for this sort of situation
https://reactive.nullvoxpopuli.com/functions/get-promise-state.getPromiseState.html
if you're already using warp-drive you can use it's implementation
https://warp-drive.io/api/@warp-drive/ember/functions/getPromiseState
or use <Await /> in the template
https://warp-drive.io/api/@warp-drive/ember/classes/Await
So i don't know if thats going to help me because I'm trying to output to a label
I mean attribute
actually how do I get the value from the state?
this.state.resolved doesn't print anything
export default class Demo extends Component {
get state() {
return getPromiseState(readFromSomewhere);
}
<template>
{{#if this.state.resolved}}
<input type="radio">
<label some-attr={{this.state.resolved}}>Label</label> <-- this is the value
{{/if}}
</template>
}
it should do :/
working?
well.. ran into another problem
I forgot that i was passing the value to the function as a paramter
How do I pass a value to the this.state function
should I create a {{ #let somevalue = answer.content}}
<div class="radio">
<label class="d-flex" for={{(concat "question-answer-text-" hi)}}>
{{#if (fn this.woof.resolved answer.content)}}
<Input @type="radio" class="form-check-input" name={{(concat "question-answer-text-" @data._id)}} id={{(concat "question-answer-text-" hi)}} {{on "change" (fn this.onSelectAnswer answer._id @data._id @data.domainId @catStartDate) }} aria-label={{this.woof.resolved}} />
{{/if}}
<div class="question-answer-text">
<RichRender @data={{answer.content}}></RichRender>
{{!-- <Questions::MathjaxContent @content={{(render-html answer.content) }} /> --}}
</div>
</label>
</div>
{{/each}}```
so my radio is in a each
I'm passing the value from the |answer| to this.woof
but this.woof.resolve is there
simplest way would be to turn it into a component with an arg
eg
export default class RadioOption extends Component {
@cached
get promise() {
return this.doAsyncThing(this.args.answer);
}
get state() {
return getPromiseState(this.promise);
}
<template>
<Input @type="radio" class="form-check-input" aria-label={{if this.state.resolved this.state.resolved ''}} ...attributes />
</template>
}
{{#each @data.possibleItemAnswers as |answer hi|}}
<div class="radio">
<label class="d-flex" for={{(concat "question-answer-text-" hi)}}>
<RadioOption @answer={{answer}} name={{(concat "question-answer-text-" @data._id)}} id={{(concat "question-answer-text-" hi)}} {{on "change" (fn this.onSelectAnswer answer._id @data._id @data.domainId @catStartDate) }} />
<div class="question-answer-text">
<RichRender @data={{answer.content}}></RichRender>
</div>
</label>
</div>
{{/each}}
I think I got it solved
You've gotten your self added to the end of the year Christmas gift list 
What library is @cached in ? I can't fidn it