In the spirit of the Modal View topic let’s continue with pagination. It’s been discussed over and over that we need to somehow standardize this, but I think it would be a good idea to make this discussion public, and not just something on gtalk/campfire
I don’t think this is a question that belongs to SO, because what I’m looking for is a discussion of how different approaches to the problem and which one should be made a standardized solution.
The option people seem to be taking these days is to return metadata about the collection with the data itself, which may look something like this
{
"meta": { "total": 10, "page": 2 },
"posts": [
{ "title": "Post 1", "body": "Hello!" },
{ "title": "Post 2", "body": "Goodbye!" }
]
}
The result of doing let’s say App.Post.query({ page: 2 })
should be a RecordArray
which already knows about the current page and total number of records.
From what I’ve heard the correct approach here would be to use the undocumented extractMeta
on the JSON Serializer and do something with it. For example this SO answer sets a global metaDataForLastRequest
.
Looking at the implementation for extractMeta
, it calls onto the sinceForType
on store, which is yet another undocumented method
extractMeta: function(loader, type, json) {
var meta = json[this.configOption(type, 'meta')], since;
if (!meta) { return; }
if (since = meta[this.configOption(type, 'since')]) {
loader.sinceForType(type, since);
}
}
this makes me wonder if it’s even a good idea to override this method in a custom serializer? Are there any implications to this?
This also seems to be directly related to this PR which makes sideloading ignore anything that isn’t an array, which we probably want for pagination metadata. Should the alternative solution here be to just override the sideload
method and ignore the metadata key?