Closed billychan closed 10 years ago
Yes you can. Read the readme file. You can override parseLinks if you don't want your server to return a links header.
@wyuenho , thank you for so quick reply. I read the readme and am not very sure what "Facebook Paging object" looks like. Is it the same as "state" object?
Well, what's your metadata for server mode look like now?
The current meta format is exactly what server mode need, like
{meta: {totalRecords: 100, sortKey: 'update', ....},
data: [{id:1, title: "foo"}, {id:2, title:"bar"}]}
In server mode I use parseState
to prepare such data for Pageable collection, like
parseState: (response, queryParams, state, options) ->
totalRecords: response.meta.total_records
sortKey : response.meta.sort_by
I checked the source and found parseLinks
method expect return of links, not data. It would be better to allow data as Pageable is able to process it, no need to repeat the work.
parseRecords
deals with the return of data, not parseLinks
. parseLinks
is only called for infinite mode to return the metadata needed to fetch the next page. Furthermore, the input for parseLinks
is the deserialized resp
and options
. You can grab your metadata the exact same way as you already do with parseState
. You just need to return different metadata from the server or construct your links object on the client side.
Did you mean I still need to prepare the links in server and then ship them in JSON within meta
for parsing in parseLinks
? I know that but just don't want to repeat such work in server.
Make your links object completely on the client side then. total_records
should give you enough info to know whether you have more links or not.
@wyuenho , please check if this logic makes sense in infinite mode
Given such JSON response
{meta: {totalRecords: 100, sortKey: 'update', ....},
data: [{id:1, title: "foo"}, {id:2, title:"bar"}]}
Override parseState in collection
parseState: (resp) ->
totalRecords = resp.meta.total_records
sortKey = resp.meta.sortKey
@links = {}
@contructLinks()
links
object manuallyconstructLinks: ->
@links.next = @getLinks("next")
#....
This arrangement would totally skip parseLinks
in infinite mode. Do you think this makes sense?
Only parseLinks will be called under infinite mode. parseState will not be called because there's no state to speak of. This is written down clearly in the API doc and the README.
Okay, I'll prepare the links in server. Thanks for your time.
I used server mode before and am quite happy with it. Today I want to add infinite mode to other models in same project and found that I need to prepare link header in backend.
I'm not saying link header is not good. I just wonder why can't we supply data as well in infinite mode to save unnecessary work when front-end is fully capable of processing such data.