Open chriseidhof opened 3 years ago
Just thinking out loud, would this Attribute
pave the way for typed attributes similar to how EnvironmentKey
works?
I've been thinking about whether typed attributes are worth the complexity.
We would have to define these types in a way that they are available in Generator
and Swim
and maybe have a fallback key associated with AnyHashable
for custom attributes.
That said, how do you find yourself using Swim? This diff should only matter to you if you use custom tags as the built-in ones in HTML
already have (arbitrarily) alphabetized attributes. So the order being maintained (for non-custom attributes) is the one at the function declaration site, not the call-site.
This PR is an experiment, not sure if it's a good idea.
I figured that it's nice to keep the declaration order of attributes.
Previously, we were sorting the attributes alphabetically during pretty printing so that they would at least always print in the same order.
Here are a few things to think about:
Tags.swift
compile is just a way to get this out without a large diff. But it also shows a problem: if people buildup their attributes using dictionaries, this approach is not nice. We could makeAttributes
conform to more protocols so that it feels just like an (ordered) dictionary.