canjs / can-observe

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

Support observable class properties #70

Open christopherjbaker opened 6 years ago

christopherjbaker commented 6 years ago

Instance properties are observed properly, but class properties are not. Using the decorators does not work. I think fixing the observability of class properties would make the decorators work too.

It would be very nice if this could be supported. =]

export class Product extends ObserveObject {
    static foo = 'foo';
}
justinbmeyer commented 6 years ago

This works with the constructor function pattern. It doesn’t work with classes because there’s no hook to proxy the returned class.

christopherjbaker commented 6 years ago

Oh, that makes sense. Would it be as simple as observing the class itself then?

class Foo extends ObserveObject {}
export default observe(Foo)

Would this create a conflict on the instances? If so, would this be better?

class Foo {}
export default observe(Foo);
justinbmeyer commented 6 years ago

It might work both ways. I know classes have some weird restrictions like you can't change their prototype object.