-
Notifications
You must be signed in to change notification settings - Fork 808
Fixed an xlet-settings issue causing invalid callback/signal triggers with some setting types #13199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… with some setting types
|
I think the method name should be changed to _isValueUnchanged or it's return value negated bc _isValueChanged sounds like it should return true if it has changed. I'm curious about a couple of things. Why does type need to be checked (although I guess it can't do any harm): Also, would JSON.stringify not work? |
|
Thanks for these suggestions. Checking if the old type is the same as new type is probably not necessary, its just a precaution, maybe too cautious. I figured its theoretically possible to manually change the type in the .json in between updates, which could result in potentially weird behavior.
|
|
I agree, stringify would likely be much slower. If oldValueType !== valueType then the comparison is done anyway right? : Maybe put: at the beginning? Also, maybe my idea of _isValueUnchanged wasn't so good bc it's a double negative (unchanged ... return false) which can be confusing xD. I prefer your original _isValueEqual |
|
I've changed the function name to: I did put |
|
Nice. Now that I think about it some more, I don't think that checking the type is necessary. I think only the xlet developer would need to change the type and they would do it in the settings-schema.json file in the xlet directory. In which case the current user settings file would be updated automatically in _ensureSettingsFiles() when the applet is restarted. |
|
You're probably right, I didn't consider |
|
Omg, I feel like I'm a bad influence on you now. 😂 undefined === undefined xD |
|
It's fine 😂. I feel like I've coded this poorly, you've given many good suggestions.
Isn't this fine? I'm not sure what's wrong here? We've established that I guess using |
|
You're absolutely right, it does work. I guess the only issue is that for the reader, it relies on their knowledge of the finer points of JS. In python or C for instance, trying to access an undefined property will throw an error. So although it works, it's perhaps less readable for those less familiar with JS's more subtle behaviours. |
|
That's fair. I've changed it to only check list types where length is definitely defined. |
|
looks good. |
Hello, this PR closes #13151. I fixed a problem described in the linked issue. I've also found that this problem comes up with the
listsetting type.Issue was caused by an improper condition checking whether the setting was changed or not. More specifically, for three setting types:
datechooser,timechooserandlistit would always evalute them as changed, because the conditionif (value == oldValue) continue;is always false for them. This causes these setting types to always fire their respective callbacks every time any other setting is changed.My solution implements a new function
_isValueChanged(), which checks whether the setting was actually changed. The implementation seems a bit too complex for what it does, but I don't think there's a different way. I'm pretty sure JS doesn't have a good, robust, builtin way of checking whether any two object have the same keys/values, so I think it's necessary to implement such functionality separately for every unique setting type.