polymer-dart / polymer_autonotify

auto notifier support for polymer 1.0.
Other
6 stars 2 forks source link

@observable computed properties cause exception #8

Open montyr75 opened 8 years ago

montyr75 commented 8 years ago

When doing something like this:

@observable @Property(computed: 'computeUserMessage(user, isHappy)')
String userMessage;

computeUserMessage() does run, but then an unhandled exception is thrown. Something like 'undefined' is not a function

dam0vm3nt commented 8 years ago

I think the real problem is that polymer forbid to explicitly notify a computed property. Annotating it with @observe will throw because autonotify will try to do that.

In your example the same happens if you try call a notifyPath('userMessage','something') (infact what it is supposed to be passed as a value argument if the value is computed?).

Removing the @observe annotation will make everything work as expected even if user and isHappy are normal properties annotated with @observe.

I'll close the issue, reopen it if you don't agree.

eloypastor commented 8 years ago

I think this issue is not solved. If you want the computed property to be @observable fires an V8 Exception

Example code:

@observable @property num width;
@observable @property num heigth;
@observable @Property(computed: 'computeArea(width, height)') num area;

@reflectable
num computeArea(width, heigth) => width * height;

A possible work around is:

@observable @property num width;
@observable @property num heigth;
@observable @property num area;

@Observe(width, height)
num computeArea(width, heigth) => area = width * height;
dam0vm3nt commented 8 years ago

Hi, I was considering patching the transformer to ignore the @observable annotation on computed properties.

Infact polymer will automatically notify computed properties everytimes they are recalculated, so there isn't actually any need for "observing" them.

Do you think this solution could be acceptable ?

eloypastor commented 8 years ago

I think yes