event icon indicating copy to clipboard operation
event copied to clipboard

Refactor proposal regarding model classes

Open myxmaster opened this issue 1 year ago • 0 comments

Many (all?) model classes use BaseModel as base class which assigns all properties of the given data object to the model object. This creates some problems:

  1. Currently the model classes don't have all the properties declared although they are used. Example: In Invoice.ts, the properties amount_received_msat and amount_msat are used but not declared. It took me a while to find out how this could work.
  2. The data object might have properties which have the same name as functions in the model class. In this case, the function would be overwritten with the data object value.
  3. The data objects seem to be coming directly from the various backends. This explains why there are sometimes multiple properties with the same meaning (like in Invoice: expiry/expires_atexpire_time).

To solve these problems I suggest the following approach:

Create interfaces for the data objects for every backend describing exactly what properties are provided by the regarding backend. Then, remove duplicated properties from the model classes and create converters for every backend which create the model objects and fill the properties from the data objects.

myxmaster avatar Sep 07 '23 19:09 myxmaster