#this.args is static, not dynamic

1 messages ยท Page 1 of 1 (latest)

errant jay
#

what's your model method look like?

tawdry nova
#

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

errant jay
#

how are you verifying that this.args.data is static?

tawdry nova
#

In my .js file, I try to get the @data for example:

@action sendOpinion() { console.log(this.args.data); }

errant jay
#

when is sendOpinion called?

#

and to recap, you're saying that

  • {{log @data}} is up to date
  • but this.args.data is not

?

tawdry nova
#

<div {{did-insert (action this.sendOpinion)}}></div>

errant jay
#

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! ๐Ÿ’ช )

tawdry nova
#

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>`

errant jay
#

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

errant jay
tawdry nova
#

Amazing, the use of modifiers worked perfectly!