#this.args is static, not dynamic
1 messages ยท Page 1 of 1 (latest)
In my controller I have this method computed:
@computed('model.orders.histogram') get ordersHistogram() { return this.model.orders.histogram }
And I receive it in my component, as follows:
<TotalOrders @data={{this.ordersHistogram}}>
In the child component, when doing {{log @data}} the data returns correctly and if the data coming from the model is updated, it shows the log. However, the data is static if I call this @data in my JS file. the page needs to be reloaded to reflect the updated data
how are you verifying that this.args.data is static?
In my .js file, I try to get the @data for example:
@action sendOpinion() { console.log(this.args.data); }
when is sendOpinion called?
and to recap, you're saying that
{{log @data}}is up to date- but
this.args.datais not
?
<div {{did-insert (action this.sendOpinion)}}></div>
Exactly
did-insert is only going to run once, so you're not going to get any updates
highly recommend not using did-insert at all, tbh
it was meant for a transitional period around 4 or so years ago
you can prove that JS does update by using a getter
for example:
get dataFromJS() {
return this.args.data;
}
and then access it in the template somehow, maybe via log:
{{log this.dataFromJS}}
also! (action) is no longer needed
(need for it went away around 4 years ago as well! ๐ช )
woow, the problem is not this.args.data, it is being updated. What alternative to did-insert?
The code I showed before was an example, but I use did-insert in this context to render a chart:
`<div
class="qa-chart"
{{did-insert (action this.setupApexChart loader.apex)}}
</div>`
use a custom modifier
custom modifier sare reactive
you'll need to define update behavior for your chart
and here is an example, because I did this very thing recently!
I seems I also use the arg name @data ๐
apologies for the lack of highlighting, gts highlighting has been lagging a bit behind compared to gjs
ok, I just refactored it so the file is less overwhelming: https://github.com/NullVoxPopuli/package-majors/blob/main/app/components/data/index.gts#L38
the modifier is focused on setup and cleanup: https://github.com/NullVoxPopuli/package-majors/blob/main/app/components/data/index.gts#L15-L25
Amazing, the use of modifiers worked perfectly!