mithril.js
mithril.js copied to clipboard
Cleaning up code by making vnode.attrs always non-null
Commit f9e5163 made vnode.attrs always non-null, so there is no need for code to make vnode.attrs null or assume vnode.attrs is null.
Description
The following two processes have been removed
- Workaround for vnode of textarea when vnode.attrs is null
- Processing of key removal to set vnode.attrs to null
For the latter, the behavior will change when there is only key in attrs (key is not removed from attrs). Some tests have also been changed to ensure that the changes are appropriate.
Motivation and Context
There is still a not very useful code that assumes that vnode.attrs will be null. Removing that code will reduce the amount of code and improve the outlook of the process.
How Has This Been Tested?
Running "npm run test"
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation change
Checklist:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [ ] I have updated
docs/changelog.md
@dead-claudia we're ignoring "key" in setAttr(), and, after this patch, in order to not have it there would mean either
- deleting it from the user supplied object, or
- iterating over the attrs to make sure it is the only one and replace
attrswith an empty object.
When there are other props key is left on the attrs.
I'd rather avoid 1).
Regarding 2) I assume that setAttr() is inlined in setAttrs() and updateAttrs(), and "key" is the first check we make in there. So looking for a lone key in execSelector will not save anything perf-wise.
@pygy My concern wasn't perf, but in unnecessary breakage and ensuring it's only removing the truly redundant parts.
Any changes to the tests reduces my confidence in the removed parts being truly redundant, if it helps.
Understood but in this case I'm not sure the tests are right. If the intent was to filter key out of the attrs of DOM vnodes, the current logic is broken, and only partially tested. We don't test for m("x", {key, a}), and we keep the key in that scenario.
Thanks for the review.
I understand your motivation for not wanting to change the test, but please consider that the changed test is changed by the commit f9e5163 (which made attrs always non-null), too. https://github.com/mithriljs/mithril.js/commit/f9e51636d8d5be06b1d74254a7bb2b5d9b9a7d67#diff-048b8c57f4a13b5784f875e7a5c31e2c2a6502c38e64c31d619e0212e5586e74R274 https://github.com/mithriljs/mithril.js/commit/f9e51636d8d5be06b1d74254a7bb2b5d9b9a7d67#diff-048b8c57f4a13b5784f875e7a5c31e2c2a6502c38e64c31d619e0212e5586e74R346
iterating over the attrs to make sure it is the only one and replace attrs with an empty object.
As a result of removing just such a process, the test needed to be changed... https://github.com/MithrilJS/mithril.js/pull/2819/files#diff-60b8d5249940bc09c5a4d14138469f40b3def8e635b25fbd59ff61493ec10581L67
To make the purpose of this pr easier to understand, I have re-modified the code with minimal changes.
I have reverted back to the original logic for the following lines, but there seems to be a bug when sharing attrs, so I would like to issue a separate issue or pr. https://github.com/MithrilJS/mithril.js/pull/2819/files#diff-60b8d5249940bc09c5a4d14138469f40b3def8e635b25fbd59ff61493ec10581L41