werediver / StyleSheet

Reusable and composable UI styles
MIT License
23 stars 3 forks source link

Investigate on a way to order styles #10

Open werediver opened 6 years ago

werediver commented 6 years ago

The current implementation applies the styles in the order of definition. This is prone to errors (e.g. a style for a base class can override a style for a subclass, if the former is defined after the latter).

Investigate on a clean and reliable way to order styles depending on the subtype relationships of their targets and markers.

If a clean and reliable way to order styles is found, plan transition to a flat style list instead of the current tree-like structure (in a separate ticket).

cfilipov commented 6 years ago

One way, as mentioned in #6, is so constrain the target and the marker (protocol) to being objective c objects so that objc runtime methods can be used to introspect those types. Wondering what your opinion on this is. Unfortunately I was not able to find a way to do this in pure swift, even with Mirror.

werediver commented 6 years ago

I have also took a look at the Mirror API. The conclusion is same as yours: it doesn't show the superclass without an instance.

I don't like the idea to leverage the Objective-C runtime for this work. I'd rather wait till Swift Mirror API is developed enough to support this use case.

As an alternative, we can think of a way to diagnose wrong style ordering in run-time.