hybridsjs / hybrids

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

Why do you remove the lastValue? #261

Closed AnnaFrom19 closed 3 months ago

AnnaFrom19 commented 3 months ago

Hi! Excuse me, can you explain why do you remove lastValue for setter and getter? In 8.* version we have smth like this:

const OldComponentDefinition = {
    tag: 'my-component',
    param: {
        get: (host, lastValue) => { lastValue ?? 9 },
        set: (host, value, lastValue) => { lastValue > value ? lastValue : value },
    }
}

But now only:

const NewComponentDefinition = {
    tag: 'my-component',
    param: {
        value: (host, value) => {
            // ???
        }
    }
}

Is there any way to get current value of param?

smalluban commented 3 months ago

The value is the lastValue from the getter. The missing is only the third argument, which was removed for several reasons:

Your example is a very good case for the above reasons. Your param is a strange value, as it only allows you to increase the value, and silently skip if the new value is lower. What should be a callback in the first place, you put into the property calculation (it was just fine before v9):

I am not sure what is the structure, and how the value is passed to your component, but instead of applying this logic inside of the property definition, it should be applied outside of it.

define({
  tag: 'my-component',
  input: {
    value: 0,
    observe(host, value) {
      if (value > host.param) host.param = value;
    },
  },
  param: 9,
});
AnnaFrom19 commented 3 months ago

Thanks for the answer. Then I will change my application logic. I think it will be even clearer in the new version.