-
Notifications
You must be signed in to change notification settings - Fork 639
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
WebUI fix change detection of input elements #1986
Conversation
- use setOriginalsFromValues function right after elements had changed and **only** with those elements - add checkbox handling to setOriginalsFromValues to match hasChanged - apply hasChanged after value is set to refresh originals after saving - change parts that already set 'original' attribute manually
I guess the is_group could be removed. Since we receive all of the data, @Tofandel If you have some spare time, any problems here / shorter approach to track 'original'? Line 364 in c4500a3
Printing values -> {"modules":{},"version":{},"device":{"hostname":"ESPURNA","desc":"","now":1573372283,"uptime":22,"lastUpdate":22},"relay":{}}"
|
Are you trying to send only the modified data but need to send the full arrays? I would change the approach, get the entire data then do an object diff (non deep) between the original and that data, that's what I'm gonna do in vue |
Yes. Not-yet-pushed version just adds index to the name when creating elements, avoiding arrays on the way back to the device and using flat object as in settings.
|
So you should get full arrays or new value if modified and null if deleted and nothing if not changed |
Okay so you need to do a deep object diff and then just flatten the result and send it, dead simple |
Ok. I'll get back with the code in a bit
Effectively, the ws keyCheck things are filtering unsupported data keys instead of UI. Since haschanged now actually does something I hope this means some code shrinkage on that front and the config parser block
|
No and yes. A deep diff should basically tell you what was modified, added or deleted and then you do what you need to do (eg flatten each one individually and merge all of them) Or simpler to use the data https://www.npmjs.com/package/deep-object-diff |
But that means you need the exact and entire state of the previous data to compare it with the entire new state |
Thank you for the link, that makes it more clearer. idk though how much code I am willing to add to the existing webui at this point. edit: aand I have tried the deep-object-diff and looked at your's example in the Vuejs pr. It does pretty much the thing that I wanted to do. But, scheduler uses a lot of keys, so it is unclear whether this actually saves anything. WiFi objects a bit different since the most common case is just 2 keys. Easiest are Rules, just a single string. Other things are fixed size based on relay / magnitude association. I guess the other problem is having html element's original=... storing the old state? One approach I could try is to hide them instead of removing right away, allowing Save to actually commit the resulting state. Then it is just a matter of either sending things as is, or adding special handlers like |
General npm / babel / browserify question. Looking at deep-object-diff package, there are bunch of modules that are exported through the src/index.js. I was under the impression that I would need to compress + mangle everything into a single file to make it work with the existing htmlmin // ...somewhere in the package.json...
"browserify": {
"transform": [["babelify", {"presets": ["@babel/preset-env"]}]]
}, But how come nothing gets added to the edit: Or via webpack analogue:
I guess it is expecting some app as an entrypoint instead of barebones module? |
Because it's the default behaviour of webpack to build as an app with an entry point and nothing accessible in the outer scope, so yes what you're doing is effectively creating a library so you either need to specify the output library or to set the imported function on |
I think the simplest way to fix the issue is the best, so if with DOM/events only works well enough without complicating too much the process, it's fine and go for it All this is handled quite easily with the new data state in the vue ui, I'll work on it this weekend and should get it ready soon, the PWA is taking shape I might need some help getting the public API built though |
True, but I hope I am not overthinking it. At least it will be some baseline to compare to. Looking forward to Vue :) sidenote: |
0bac908
to
cfad3e3
Compare
only with those elements
This was sort-of broken, because nothing really bad happens besides sending all of the available key-values to the device.
And I am not really sure what is up with theschSwitch: [0xff]
. Need to look at it again and then I will commit thisupd: This part is reworked by using empty array when there are no schedules, scheduler code on the device uses 0xff as the default anyway. Similar code is added for the wifi objects.
Sending as arrays instead of plain keys (see comments bellow about deep-object-diff) to allow clean-up methods to work. Diff library is ~1.5KB additional code, so more things need to change.
fix #2035