montagejs/montage — pull request #1228 by kriskowal (2013-07-19 04:57:34+00:00)
Title: Fix repetition inside substitution

This is a fix created in collaboration with @aadsm to address a race
condition in setting up a repetition that exists inside a substitution.
The repetition must not set up its iteration template until it has an
`_ownerDocumentPart`.

Because this requirement increases the already mounting complexity of
detecting when all the requirements of setting up an iteration template
have been met, this commit refactors that process. With this change,
all of the logic for detecting when all the requirements have been met
has been condensed into a path change listener that will become true
when ready. This is a sufficient "rising edge" detector for setting up
the iteration template and also blocks subsequent reconstructions if
requirements are no longer satisfied. Detecting that `innerTemplate`
has changed is sufficient for detecting a "falling edge", where the
iteration template must be immediately torn down, but not necessarily
immediately recreated.