Relying on object property order for a styling API. Good or bad? eg. styles({ backgroundBlue: true, backgroundRed: true, }); In this case the background would be `red` as it appears last. Relying on property order feels gross but can't think of a better API?
-
-
It is! Object order has been guaranteed in JS since ES2015. Just feels like an odd API.
- 3 more replies
New conversation -
-
-
So I guess that leaves: are your keys actual classnames or inline-styles to be applied? Because if they're classnames on the same element, the order in the classname list is irrelevant, but if they're styles the outcome could be different.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I think this pattern is fine. If there are things that directly conflict like <Comp red blue /> for "background: blue" and "background: red", I would throw an error if both are applied, but it's more about how the implementation is meant to be used.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
if default you always need it, only depend on isActive. IMO then instead of object, you'd need properly inherit from CSS rules, where active css rule rewrite some default rule.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
maybe it'd be clear if it was something like `styles({default: true, overrideStyles: {active: isActive}})`
-
This gets tricky when there're more than two styles.
End of conversation
New conversation -
-
-
IMHO, this specific case is idiomatic enough that people will assume that order DOES matter even when they would otherwise argue to their death that it doesn't. People are funny like that
So I'm changing my vote to YES :D
Thanks for the specific example. Details matter.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
This example looks and feels a lot better.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 