thinky
thinky copied to clipboard
Implement ordered ranges
For
Users.orderBy({index: "score"}).limit(10).changes()
We should return an array of 10 documents and maintain it up to date. This is pending some changes on the server: https://github.com/rethinkdb/rethinkdb/issues/3714
If the changes don't make it for 2.0, I'll implement a work around (a bit less efficient than if the feeds return the positions of the changes).
That's technically possible now.
The question is how to expose it. Here's what I have in mind
io.on('connection', function(socket){
Users.orderBy({index: "score"}).limit(10).changes({includeStates: true}).run().then(function(range) {
socket.broadcast.emit(JSON.stringify(range.toArray()));
range.each(function(patch) { // equivalent to range.on("change", function(patch) {
socket.broadcast(patch)
})
})
});
A few things to note:
-
toArray
is synchronous here - patch would be a JSON patch as described here: http://jsonpatch.com/
The main idea is that you can get the sequence at any time with toArray
on your Node.js app, and you can easily send it to your user (without sending the whole array).
Thoughts anyone?
I would prefer it if range
was just an array by default and .toPatch()
implemented the JSON patch behavior you described. I think the more common case is that people will just emit the entire array to the client each time.
any chance this feature gonna make it?
Hum the API hasn't been quite nailed down so there's more work needed here.