It feels like I'm facing the same thing the same problems writing the API of these components. In particular:
- A component might have several distinct modes. As in, an
<x-gif speed="1.0">has a very different playback mode from<x-gif bpm="120">, so you shouldn't be allowed to have bothspeedandbpm. But it doesn't seem right to break them into separate components, so either one takes precedence or having both present causes an explosion. - A component might require more than one attribute to be valid. As in,
<x-beat midi channel="0" note="65">. Until you have both thechannelandnoteyou can't make connection to the midi signal. But if you're driving the component with a framework like angular, it will first render incompletely (as<x-beat midi channel="{{ channel }}" note="{{ note }}">), then after a$digestwill insert the right values. So a component may need to permit being in an invalid state temporarily, then when all attributes are set go and get set up.
The first bit feels like command-line options-parsing, but the second one is trickier. You have this stateful lifecycle of these components and tracking all the potential changes is really hard. Thoughts?
Feels like we need a declarative way of describing a component API that understands the different kinds of attributes, to reduce some of this complexity. Unless... some work like this has already been done. Like within x-tag or something?
As am I, that's just where my thinking was leading me down, and so I needed to pop my head up and consider alternatives :)
I agree that it does make more sense in a HTML environment to fail silently, so yes, let's just say that
speedtakes precedence overbpm. That I think solves #1.Do you have some examples of this state-change-based attribute handling? Coming from Polymer, the way I ended up doing this is a method for each attribute change, and different amounts of work needed for each one. But it feels messy, like each attribute needs far too much knowledge of its relationship with the rest of the component. Example here: https://github.com/geelen/x-gif/blob/gh-pages/src/x-gif.js#L23-L50