pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

Support getters on methods #150

Closed natew closed 7 years ago

natew commented 7 years ago

Case

Bug

Issue

Getters not working for methods

Info

Chrome

Code

Rx.collection({ methods: {  get url() { return this.getUrl() } } })

Error:

image

pubkey commented 7 years ago

Getters will not work, only functions are supported. The problem is, when you call sth like this:

Rx.collection({ methods: {  get foobar() { return 'xxx'; } } })

Then the getter is assigned to the methods object. When RxDB reads all parameters from methods it will also call the getter there instead of looking up the function.

natew commented 7 years ago

Forgive my naivety, could you do:

Object.getPropertyDescriptors(methods).forEach(descriptor => {
  if (typeof descriptor.get == 'function') { ... }
  // or just Object.defineProperty(RxDatabase, propName, descriptor)
})