hybridsjs / hybrids

Extraordinary JavaScript UI framework with unique declarative and functional architecture
https://hybrids.js.org
MIT License
3.03k stars 85 forks source link

lagging update glitch #265

Closed Qsppl closed 3 weeks ago

Qsppl commented 4 weeks ago

example: https://codepen.io/qsppl/pen/WNqXLGO

The observed behavior is not obvious. The first time library users encounter this behavior, it will be confusing.

smalluban commented 3 weeks ago

You must not use setters inside of the value function - as may create an endless loop of actions. You should use the observe method, to take action when one property change should influence another.

However, thanks for pointing it out, I made a fix and released a new version, which will throw for your example code.

Instead of setting a value while getting another, you should use observe:

{
  one: {
    value: 0,
    observe: (host, value) => { host.two = value },
  },
  two: 0,
}
Qsppl commented 3 weeks ago

Thank you, now it has become much easier to notice the error and understand why it occurred.