Decouple subcircuit view from internal logic
ialokim opened this issue · comments
Currently, displaying popups with subcircuits is handled in the Circuit class; the popup for memories is handled in the view. Ideally, these things should be handled externally. Some users might not want the popups; others might want something different (tabs, side panels, etc.).
I'm not sure what would be considered best practice for such kind of things in Javascript: Some sort of callback function / backbone event that one would need to react to (e.g. inside digitaljs_online)? Or perhaps pass some external function that would be called from within digitaljs on opening subcircuits? Some externally given function that produces and returns a html div where the subcircuit would be rendered into?
Also, should some default handling still remain in the core digitaljs logic such that if e.g. the event is not responded to the subcircuit is still showed in a popup window as done currently?
A Backbone event is probably the way to go. I'm currently abusing the double-click event for subcircuits.
A sensible default, which can be overridden, seems like a good idea. The only downside is that the dependency on JQueryUI cannot be then removed from DigitalJS.
Backbone event
Would the event then provide the subcircuit as an argument and the website using digitaljs would be expected to call the subcircuit.displayOn()
function?
I think it would make sense to have two different events for subcircuits and memory content right?
I've investigated further and it seems there is no way to check whether a backbone event has been handled or not, thus the library wouldn't know whether it has to display subcircuits by it's default way or not.
I would therefore prefer to expect an optional callback function when calling displayOn
that should return a div
element on which the subcircuits should be shown. Would you be okay with this idea too?