Description
I'm doing something admittedly weird in a side project and I ran into an issue that I managed to get around, but I don't understand the intent of custom LogicBuilder
s given the issue.
I have a multi-page, branching workflow that collects data in different ways depending on the path that you're on. You can think of the workflow as a directed, acyclic graph.
In order to support this, I have a top-level logic (let's call it SuperLogic) and then a couple of lower-level logics that are for a diverged path of the workflow (let's call them LogicA-LogicZ). I then wrote a function that returns a LogicBuilder
calling other "core" builders (connect, listeners, etc) so that I could wire SuperLogic into each of LogicA-LogicZ via kea([connectSuperLogic({listenTo: "myAction", transformValues: transform})])
without SuperLogic needing to know anything about the dependent logics.
All of this seemed pretty straight-forward until I checked the UI and it seemed that my SuperLogic was never being connected to or updated. With only a little debugging, I realized that I could just directly invoke the core builders with the logic passed into the logic builder. Is this the expected way to handle this? Alternatively, I could do something like return an array of core builder calls instead of returning a LogicBuilder
, but that seemed like it "isn't the kea way".
Example (simplified):
export function connectSuperLogic<T extends Logic = Logic>({listenTo, transformValues}: ConnectionConfig) {
return (logic) => {
connect(superLogic)(logic);
listeners(({values}) => (
{[listenTo]: superLogic.actions.grabSubForm(transformValues(values))}
))(logic);
};
}