tc33/EpochX

Template values are not available by auto-update

Opened this issue · 0 comments

tc33 commented

The problem is that when a Template is set, the config event that's fired is for the Template.KEY ConfigKey. So any class using the auto-update idiom will not update their values for config keys within the template. If the template hasn't already been set before the object (that's using the idiom) is constructed, then the object won't be configured with the template values. This leaves them unset even when there's a value set in the template.

It's not sufficient to just use a convention where the template is set before any other configuration to make sure the template is available. This is because some of the objects created in the template may themselves be dependent on other things in the template (e.g. Initialiser component and Initialiser.METHOD).

One (imperfect) solution is to always add Template.KEY to the fields that trigger a reconfiguration in the auto-update idiom, like this:

public void onEvent(ConfigEvent event) {
if (event.isKindOf(Template.KEY, RandomSequence.RANDOM_SEQUENCE)) {
setup();
}
}