lega911 / angular-light

Alight is a library for building interactive MVVM web interfaces/applications. (project is deprecated)
MIT License
274 stars 43 forks source link

Should watch be called initially #161

Closed djkunkel closed 8 years ago

djkunkel commented 8 years ago

Hello! Thank you for providing this great framework. I have a question. When looking at this example: http://jsfiddle.net/lega911/o1qvt257/ the watch callback is called after the initial load even when no changes have happened to the 'filter' scope value. Is this normal behavior? Is there a way to prevent a watch from being called initially?

Thanks.

lega911 commented 8 years ago

Hello! Yes, it's normal behavior, Angular.js works similar, old versions didn't fire callback initially, but it's used in 90% cases. examples how to avoid it: 1) http://jsfiddle.net/lega911/umcheq8q/ 2) http://jsfiddle.net/lega911/6dae9hxm/ (prevValue === undefined at start) 3) http://jsfiddle.net/lega911/3xkp7qxc/ (w.refresh() - updates inner value, that $digest uses for comparing, you can use it any time)

djkunkel commented 8 years ago

Wow. Thank you for this! I had implemented something like #1 for my use case, but I didn't know about the refresh() method.

Is it acceptable to ask another question on the Issue tracker or is there another place where the community is active that is preferred?

Thanks for taking the time to answer me!

lega911 commented 8 years ago

Any place is ok. I observe github, G+ and email.

You're welcome!