rethinkdbdash icon indicating copy to clipboard operation
rethinkdbdash copied to clipboard

Investigate using ES6 Proxy with `r.row`

Open marshall007 opened this issue 10 years ago • 2 comments

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!

marshall007 avatar Jun 05 '15 03:06 marshall007

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 :)

neumino avatar Jun 05 '15 06:06 neumino

Cool!!

thelinuxlich avatar Jun 06 '15 03:06 thelinuxlich