canjs / can-observe

Observable objects
https://canjs.com/doc/can-observe.html
MIT License
20 stars 2 forks source link

simple solution for lack of decorators #69

Closed christopherjbaker closed 4 years ago

christopherjbaker commented 6 years ago

With this minor change file, we can allow one to call the function with the prototype and key, for environments where decorators are unavailable.

export class Product extends ObserveObject {
    get details() {
        return Promise.resolve({});
    }
}

async(Product, 'details'); // <--
justinbmeyer commented 5 years ago

Is there anything in this preventing the following from working too:

export class Product extends ObserveObject {

}

async(Product.prototype, 'details', function(){
  return Promise.resolve();
});

I could see this being another desirable signature.

christopherjbaker commented 5 years ago

@justinbmeyer not without a bunch of type checking. In the decorator, the third parameter is the descriptor; this is just looking up what the descriptor is if it's not provided. It's not meant to be an alternative to decorators, it's just an alternative way to trigger them if you don't have decorator syntax support.

BigAB commented 5 years ago

So with the new-new decorator standard, you can't just call a decorator like a function anymore, so I think we need to go back to the drawing board on this one