editor-js / image

Image Block for Editor.js
MIT License
234 stars 282 forks source link

Provide generics for Image class #254

Open dependentmadani opened 2 months ago

dependentmadani commented 2 months ago

Problem

The current design of the Image class doesn't make it easily extendable so that users can define their actions and additional fields in the upload response. This also limits class extensions for use cases where custom data and actions must be implemented.

Cause

The Image class was first designed with types fixed for the actions and upload response data, which is a very concrete design, and it limited the flexibility with different kinds of requirements. The approach taken in designing thus becomes relatively narrow and does not allow an extension of the user's custom properties during the creation of Image object.

Solution

Generic types should be used to re-implement the Image class to fix this problem. The definition of the class should change into class ImageTool<CustomActions = {}, AdditionalUploadResponse = {}>, such that while the object of it is created, users can provide their custom actions and additional upload response types. This makes the Image class flexible and more usable and leaves the ability to respond to almost any scenario and requirements.