-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Ensure works with JSONAPI pagination requirements #97
Comments
Link for reference. It is fuzzy for me what the response looks like because there are no examples. |
Yeah was actually just thinking about this... The spree_api_v2 gem is all JSONAPI, and I'm looking to get it working with Spree Ember (and Ember Infinity!) will think on it also! |
Agreed, would be awesome if Ember Infinity supported the new JSON API format. I'd be happy to help if you're interested @hhff. |
@dpatz I think a first step would be to extract the response parsing into an overridable function if it isn't already. That would mean an already built server with a paging api could use ember-infinity if you override the response handling function. The function would take a raw response body and return a object we expect. This would make for an easy transition to JSON API. You could start there if you have the time 😄 |
👍 |
Seems like the model's serializer's extractMeta hook could be leveraged for
|
Definitely agree with @davidgoli that the right place to do the parsing is in the I think the biggest problem right now is that Ember Data doesn't natively support pagination yet. There is no mention of the Btw @kellyselden:
Here's a link to clear it up: http://jsonapi.org/examples/#pagination |
@dpatz Thanks for the example. |
This is the homepage example of how links should work. Is there a way to implement this manually currently or does |
@IsaiahJTurner - I don't currently know a way to do it - but supporting JSONAPI is a priority. I'm actually going to be tackling this in an app I'm working within a couple weeks. If you'd like to take a stab at it - please do! Failing that - it should be done before christmas 👍 |
+1 |
@hhff did you end up working on this? |
@seanrucker no sir - it's on my list but keeps getting pushed off! |
thanks @hhff it would be super cool if ember-infinity works with jsonapi pagination requirements. nice work tho |
I see It can work with jsonapi pagination.
total pages was calculated and sent with the metadata as
And it works smooth |
@andela-eashikodi That's awesome! |
sweet yeah - I've been seeing two different pagination styles in JSONAPI - one via like a Great you got it working @andela-eashikodi ! |
I ran into a situation where I have an API that's using the links object, and had to hack together a solution... Here's the way I did it:
Honestly, it wasn't as messy as I thought, although setting the params values from the serializer wasn't great... |
I tried the approach that @andela-eashikodi mentioned, but it didn't work for me. The initial request happens correctly, so I receive the first page, but when I scroll to the bottom, I only see "Loading Infinite Model...", but there is never any AJAX request for the second page. |
This is how I currently use Ember Data/EmberInfinity out of the box with JSONAPI resources using paged pagination:
|
Thanks @utilityboy. As far as I can tell, my approach is identical. My template: {{#each model as |notification|}}
{{my-component notification=notification}}
{{else}}
<p>No Notifications</p>
{{/each}}
{{infinity-loader infinityModel=model}} My route (in CoffeeScript): `import Ember from 'ember'`
`import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'`
`import InfinityRoute from "ember-infinity/mixins/route"`
FeedRoute = Ember.Route.extend AuthenticatedRouteMixin, InfinityRoute,
pageParam : "page[number]"
perPageParam : "page[size]"
totalPagesParam : "meta.total"
model: ->
@infinityModel 'notification', perPage: 10, startingPage: 1
actions:
infinityModelUpdated: (totalPages) ->
Ember.Logger.debug('updated with more items', totalPages)
infinityModelLoaded: (lastPageLoaded, totalPages, infinityModel) ->
Ember.Logger.info('no more items to load', lastPageLoaded, totalPages, infinityModel)
`export default FeedRoute` The initial AJAX request is correct. The results are displayed and the payload includes |
Ah, I think I figured out two things:
|
@andrewhavens, can you show me resource? |
@utilityboy Sorry, I don't understand. What do you mean by resource? |
@andrewhavens, your JSONAPI Resource. |
I got it working. Turns out my problem didn't have anything to do with JSON API, and everything to do with the loader not triggering the loadMoreAction when coming into the viewport. See my solution here: #82 (comment) |
@utilityboy this works for me as well, however, Ember Infinity doesn't seem to know when to stop loading more resources (although I can confirm it is properly getting the totalPagesParam) |
We're not scrolling the window (which is the default behavior), manually specifying a scrollable just loads everything, and rolling our own with ember-in-viewport doesn't work in Ember 2.9 for now. I'll just leave this half-baked branch here. Maybe we can add a button to manually load more until the dust settles? Maybe we should just fully roll our own? And reminder: "total pages" in ember-infinity seems to actually mean "total records". adopted-ember-addons/ember-infinity#97 adopted-ember-addons/ember-infinity#82 (comment) DockYard/ember-in-viewport#95
Has there been any activity on this issue? Is the best solution available to do it custom? |
@superjova - the best solution is to do it via a I'd love to support this but I've not actually yet seen how to access the |
If no JSON API links yet, how would you recommend this example with ember infinity?
Both endpoints can be paginated and return the same post model. It seems with ember infinity I can either infinite /posts or /user/posts from the 'post' model, but not both. |
Hi @superjova ! That's not really a problem fixed by JSONAPI - as even with JSONAPI the links property needs to "link" to another part of the same collection (meaning you still have two separately paginated collections). I'd recommend having two separate infinity models. There's more complicated ways to do it, but in a lot of cases it's an over-optimization. |
Creating separate infinity models is the road I've started heading down. Conceptually, I was thinking a 'user' model would link to an articles relationship at '/api/users/1/articles'. After the first request, the articles end point would return pagination for ember infinity to plug into. |
Cool! Sounds good @superjova |
Got this working in our implementation. The only gotcha in our implementation was that we did not expose the total pages count to the client, probably a similar issue to what @allthesignals was having. Ember Inifinity would only request one page, or keep requesting pages until I would kill the ember server. We had to explicitly allow the page count in the meta field like so: top_level_meta_include_page_count The ember route looks like so: import BaseRoute from 'shared-components/routes/base';
import InfinityRoute from 'ember-infinity/mixins/route';
export default BaseRoute.extend(InfinityRoute, {
perPageParam: 'page[size]',
pageParam: 'page[number]',
totalPagesParam: 'meta.page-count',
model() {
return this.infinityModel('media-item', {
perPage: 20,
startingPage: 1,
});
},
}); works great! good job Ember Infinity team. Since jsonapi seems to the the preferred format for ember and the default for ember-data, I think something alluding to this should be in the readme. My opinion. |
I'm a bit new to JSONAPI, but it looks like the
meta
key goes away and becomes thelinks
key. I tried the new JSONAPIAdapter and doesn't look like this addon plays well with it. Perhaps we can first make the response format overridable, to make the user handle thelinks
key themselves and transform it into something we expect. We could also sniff the adapter and try to pick the response format automatically.Comments welcome because this is just the beginning of my thoughts.
The text was updated successfully, but these errors were encountered: