PackRuble / cardoteka

The best type-safe wrapper over SharedPreferences. ⭐ Why so? -> strongly typed cards for access to storage -> don't think about type, use get|set -> can work with nullable values -> callback based updates
https://t.me/+AkGV73kZi_Q1YTMy
Apache License 2.0
3 stars 0 forks source link

General config attached to `Card` implementation? #3

Open PackRuble opened 1 year ago

PackRuble commented 1 year ago

It will be extremely convenient, as for me. Related things in one place

PackRuble commented 10 months ago

At this point, I've come to the conclusion that it's best to leave it up to the user) I do it this way myself:

enum CardImpl<T> implements Card<T> {
  myColor<Color>(DataType.int, Color(0xFF00BFFD)),
  mySleepDuration<Duration>(DataType.int, Duration(hours: 7)),
  ;

  const CardImpl(this.type, this.defaultValue);

  // ...type, defaultValue, key 

  static const converters = {
    myColor: Converters.colorAsInt,
    mySleepDuration: Converters.durationAsInt,
  };
}

// ... and then
  CardConfig(
    name: '$CardImpl',
    cards: CardImpl.values,
    converters: CardImpl.converters,
  ),

This eliminates boilerplate in converters (not writing CardImpl unnecessarily) and still allows the config to be dynamic and live wherever it wants)

PackRuble commented 10 months ago

There are probably other interesting mechanics and therefore this issue remains open for discussion

PackRuble commented 9 months ago

Important clarification: CardConfig has been renamed to CardotekaConfig 0c77651bd6def492e7206744924b7621758a6011