#How do I reload model periodically?

1 messages · Page 1 of 1 (latest)

waxen laurel
#

I see you have a later function that will run in a loop, but it only runs once... How can I make it run infinitely as long as the page is open?
later(myContext, function() {
// code here will execute within a RunLoop in about 500ms with this == myContext
}, 500);

mint belfry
#

Could use a setInterval

#

And registerDestructor

waxen laurel
#

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

waxen laurel
#

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

waxen laurel
#

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]

nocturne wolf
#

findAll shouldn’t be returning just one record ….

mint belfry
waxen laurel
waxen laurel
west charm
#

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}} />