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

Manually add item to infinity.model #383

Closed
Redsandro opened this issue Jun 25, 2019 · 8 comments
Closed

Manually add item to infinity.model #383

Redsandro opened this issue Jun 25, 2019 · 8 comments

Comments

@Redsandro
Copy link
Contributor

I have a page that's polling the server for new items. They will be prepended to the list and marked as "new".

Now that I replaced my model with ember-infinity, I can't figure out how to do this (or if it's possible).

Can I manipulate the infinity-model and prepend an item?

Cursor-based pagination for older items when scrolling down will continue to work fine.

@snewcomer
Copy link
Collaborator

Do any of these methods help? https://github.com/ember-infinity/ember-infinity#service-methods

If you have any code examples, we could probably solve this with existing methods or improve the API here.

@LuisAverhoff
Copy link

LuisAverhoff commented Aug 15, 2019

@snewcomer I have similar situation to @Redsandro. I have a list of processes that I'm infinitely scrolling and at the top of the list there is a button that creates a new process by making an api call to the server when clicked. At the moment, I'm force to refresh the current route when the button is clicked so that ember infinity can load up the new item that was created on the server side. Can you suggest to me any other alternatives? The only other thing I can think of doing is model.pushObject(process) where model is the model returned in the model hook using this.infinity.model and process is the object that was returned from the api call. I don't know if this would cause problems later on when it comes to the infinity component fetching new items on the server side such as duplicate items in the list(once from manually creating it and appending it the infinity model and the other is from ember infinity fetching it when I scroll further down the list). Thanks for your time man.

@LuisAverhoff
Copy link

LuisAverhoff commented Aug 15, 2019

I saw that you had a section for cursor based pagination that deals with duplicated items based on an id and a timestamp when appending new items to the list(and removing previous items but that is not allowed yet in the application so not an issue at the moment). Based on what I said, do you think that is what I should go for?

@Redsandro
Copy link
Contributor Author

@snewcomer I'd like to try pushObjects or unshiftObjects, but they are not documented further than this. Is there API documentation on them?

@snewcomer
Copy link
Collaborator

@Redsandro yep! https://api.emberjs.com/ember/3.12/classes/MutableArray/methods/pushObjects?anchor=pushObjects

@Redsandro
Copy link
Contributor Author

Oh! It's an Ember-native method!

This makes me wonder if there is a way to keep a list of links to objects in the model, and when ember-infinity is loaded started because of a history event, automatically load those objects in stead of the default first page.

It would be a good start towards:

@snewcomer
Copy link
Collaborator

@Redsandro
Copy link
Contributor Author

I think unshift would work for prepending. I have not tried it yet because I went another way, but this specific issue is closed. For now. :)

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

3 participants