cinemascience / cinema_components

A JavaScript library for building Cinema viewers
Other
2 stars 5 forks source link

[Refactoring] Create discrete "File handlers" for ImageSpread #16

Open camtauxe opened 6 years ago

camtauxe commented 6 years ago

To keep the code in ImageSpread.js from becoming too messy, there is some refactoring that I think should be done before adding support for viewing any additional filetypes. It revolves around introducing a new class to the codebase called a "FileHandler" or maybe a "FileViewer."

Instances of this class would have three important fields:

Then CinemaComponents should have three pre-built FileHandlers which will represent the kinds of files we are already able to display. There would be:

Then the ImageSpread component would keep a list of all of the file handlers that is has "registered." (The three handlers mentioned above will be registered by default). When the ImageSpread component builds the view for a file, it will search the list of registered handlers to see if there is one that supports the file's type. If there isn't one, it will just display some generic error ("Cannot display filetype .foo" or whatever). If there is a handler for that filetype, it will call that handler's getPreview function to get the image to display as the thumbnail. Then when the thumbnail is clicked on, it will call the handler's createView function which will create and display the view of the file.

The reason for this refactor is to prevent ImageSpread.js from becoming gigantic and unmanageable as we add support for more filetypes. It will also make it easier to add support for more filetypes in the future and even allow users of Cinema Components to create their own custom file handlers to suit their needs.