robb / Swim

A DSL for writing HTML in Swift
312 stars 9 forks source link

Attributes as ExpressibleByDictionaryLiteral #34

Open chriseidhof opened 3 years ago

chriseidhof commented 3 years ago

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:

robb commented 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.