vexflow
vexflow copied to clipboard
We need to explicitly define the object lifecycle
Two major problems:
- VexFlow has no clearly defined object lifecycle
- VexFlow provides no support in assembling objects the right way
This is something that that tests get really wrong. They all construct, setup, and draw things in different order. It's incredibly inconsistent. We're always telling people to look at the tests to learn how to use VexFlow's more obscure parts, but as I'm looking through them now. It's chaos. We can't expect people to look at the tests to get any clarity on how to use this library.
I'm bringing this up because I was trying to make a very reasonable change to StaveNote:
Currently, a StaveNote sets the x value for it's Noteheads and Stem in it's render() method. But this is clearly the wrong place. We shouldn't be mutating anything in render(). So I moved that logic into .postFormat(). Since that's clearly the the place to set the x values. However, doing so broke tons of tests because lots of them are doing things in the wrong order. But that fact would have never been apparent when the tests were written.
Another related question: when should Glyph's be initialized? I think, ideally, all Glyph based Elements would construct their glyphs at the same point in the Element lifecycle.
Provided that Elements have methods used for configuration after construction, I think they should be initialized right before formatting (ie: after the object has been been fully configured).
Right now I think there's too much initialization in the constructor, causing a lot of issues with configuration after construction. I think as much as possible should be pushed out to the preformatting stage.