#How do I reload model periodically?
1 messages · Page 1 of 1 (latest)
Ah ok.. setInterval it is...
now do I have to clear the setInterval after the page loads to stop it from running ?
LOL i found it
wait even that it only running once LOL
setTimeout(async () => {
const data = await this.get_data();
controller.model =data;
controller.user_count = data.length;
}, 1000)```
This is the code I have in my setup controller function... it runs the first time and then doesn't run after that
wait lmfaoo
I am an idiot and used setTimeout instead of setInterval
Correct
Ok one question
I thought A([]) are tracked.
so if i remove an item it should rerender the page.. currently it's not doing that
nvm i think it was my data...
is there any thing in the docs that said that findAll ID needs to be the same or the data won't update? @nocturne wolf
Since the ID that I was passing back in the JSON payload was different it was just appeneding data to the Proxy array instead of updating ...
Also I have to do this to access the model that is passed back from the findAll call... is this normal ? data[0]
findAll shouldn’t be returning just one record ….
Use tracked array from tracked-built-ins instead
Ok I'm going to have to take a look at that and see what I'm doing wrong
yeah I changed it to tracked array and it worked
How I do it is to make my model an object with the actual model as a property and another refresh property
model() {
return {
model: …,
refresh: () => this.refresh(),
};
}
Then I make a helper which takes the refresh function as an argument. This helper starts a setInterval calling the refresh function. On teardown it will clearInterval
{{refresh-poller this.model.refresh}}
<DoSomethingWith @model={{this.model.model}} />