Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xilem_web: Rewrite modifiers (
Attributes
, Classes
and Styles
), …
…and cleanup/extend docs (#699) Previously the modifier systems had design issues i.e. bugs (non-deleted styles/classes/attributes), and were unnecessary complex. This aims to solve this (partly) by not using separate traits, but concrete types and a different mechanism that is closer to how `ElementSplice` works. There's a few fundamental properties that composable type-based modifiers need to support to avoid surprising/buggy behavior: * Minimize actual changes to the underlying element, as DOM traffic is expensive. * Be compatible to memoization: e.g. a `Rotate` view should still be applicable to possibly memoized transform values of the underlying element. * Recreation when the underlying element has changed (e.g. with a change of variants of a `OneOf`). To support all this, the modifier system needs to retain modifiers for each modifier-view, and track its changes of the corresponding view. Previously all elements were directly written and separated with markers into a `Vec` to limit the boundaries of such views, but this had issues, when e.g. all modifiers were deleted (e.g. clearing a `Vec` of classes), by not reacting to this (I noticed that issue in the todomvc example with the footer). With this PR, the count of modifiers of a modifier-view are directly stored either (hardcoded) in the view impl or its view state, which cleans up the concrete modifier elements (such as `AttributeModifier`, not including a separate `Marker` variant), and makes it less prone for errors (and is slightly less memory-intensive). The API to use these modifiers in modifier-views was also redesigned to hopefully be more straight-forward/idiomatic. But as mentioned above there's still challenges, which introduce complexity (which I'd like to hide at least for simpler cases than these modifiers, likely in a future PR). All of this should now be documented in the new `modifier` module, where now the modifiers `Attributes`, `Classes` and `Styles` reside. Other views (like events) may also end up there... One interesting aspect compared to the previous system is the use of a new trait `With` for modifiers. Instead of (roughly) `Element: WithStyle`, it works with `Element: With<Styles>`. This prevents all kinds of reimplementations of something like `WithStyle` for elements. This gets especially visible in the `one_of` module, which now can be covered by a single blanket implementation. Further the cargo-feature "hydration" was deleted, as it causes more headaches to maintain than it really brings benefits (minimally less binary size), depending on the future, it may or may not make sense to reintroduce this.
- Loading branch information