rethinkdbdash
rethinkdbdash copied to clipboard
Investigate using ES6 Proxy with `r.row`
The ES6 Proxy object allows you to capture getter and setter calls on an object. I haven't had a chance to use these much yet, but I was thinking it could provide some nice syntactic sugar when using r.row. For example:
r.row = new Proxy(r.row, {
get: function (row, prop) {
if (prop in row) {
return row[prop]; // existing ReQL term
}
return row(prop); // get field
}
});
r.row.foo.bar === r.row('foo')('bar')
Similar to the behavior of other drivers, this would allow you to access document properties as if they were defined on r.row at runtime, which is pretty cool!
That would be neat. I wonder how much confusion that will throw though. It's a bit harder to know what is executed in the client site, what is on the server site.
But yea, it's definitively a cool stuff :)
Cool!!