How to design app to be modular / support plugins
- by Lee
I'm currently in the process of refactoring my webplayer so that we'll be more easily able to run it on our other internet radio stations. Much of the setup between these players will be very similar, however, some will need to have different UI plugins / other plugins.
Currently in the webplayer I do something like this in it's init():
_this.ui = new UI();
_this.ui.playlist = new Playlist();
_this.ui.channelDropdown = new ChannelDropdown();
_this.ui.timecode = ne Timecode();
etc etc
This works fine but that blocks me into requiring those objects at run time. What I'd like to do is be able to add those based on the stations needs. Basically my question is, do I need to add some kind of "addPlugin()" functionality here? And if I do that, do I need to constantly check from my WebPlayer object if that plugin exists before it attempts to use it? Like...
if (_hasPlugin('playlist')) this.plugins.playlist.add(track);
I apologize if some of this might not be clear... really trying to get my head wrapped around all of this. I feel I'm closer but I'm still stuck. Any advice on how I should proceed with this would be greatly appreciated.
Thanks in advance,
Lee