Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Server Polling #335

Open
maprules1000 opened this issue Nov 5, 2018 · 2 comments
Open

Support Server Polling #335

maprules1000 opened this issue Nov 5, 2018 · 2 comments

Comments

@maprules1000
Copy link

maprules1000 commented Nov 5, 2018

Hi!

I ran into a situation where I want my page to be infinitely scrollable but also populate the top of the page with new objects that come in from the server.

So right now I have an infinity model that successfully loads data, but I have a polling event that refreshes some of the loaded data, which breaks data relationships in the infinity model.

I was able to fix it for my use case, but it would be ideal to incorporate an update option that doesn't break relationships of non-updated objects.

It would be great if I could ask the infinity model to basically make the first call again and have it update the store with new objects, or any objects that have been updated.

Here's the polling code (which is managed by ember-concurrency):

this.get('item').reload().then(item => {
    item.get('allOrders').reload()
});

And the infinity model is loaded through a model hook on a route.

I should also note that I'm using cursor based pagination, and the results coming back from the server are already ordered.

@johncalvinyoung
Copy link

Perhaps I'm misunderstanding, but how does it 'break data relationships' in the model?

Also, if you implement some logic to determine your delta, would unshiftObjects be of any use?

@maprules1000
Copy link
Author

maprules1000 commented Nov 12, 2018

To be honest, I'm not really sure how it breaks some data relationships, but there are several hasMany/belongsTo relationships that no longer exist after attempting to reload the allOrders relationship.

In the template I have:

{{#each allOrders as |order|}}
  <!-- html stuff -->
  {{order.item.name}}
{{/each}}

Where item is another model that hasMany orders.

This properly renders when the infinity model is called, but as soon as alllOrders.reload() is run the relationship disappears from the template. The data for the orders is still in the template, and the item data still exists in the store, but it looks like the reloaded data no longer has a working hasMany/belongsTo relationship and the item data disappears from the template without an error. It seems like using the vanilla Ember Data reload() call overwrites and breaks something with the infinityModel.

I'm still digging into the cause, but it would be great if the ember-infinity service had an "in-house" way to poll for new data and update the existing infinity models that have been already loaded, or even just re-run the initial server call. However, it might be tricky to merge the updated data into the existing infinityModel array.

I think unshiftObjects might be useful to solving the problem, but I'll have to investigate it more since it's not really documented in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants