Skip to content

Latest commit

 

History

History
30 lines (27 loc) · 1.31 KB

electron_store.md

File metadata and controls

30 lines (27 loc) · 1.31 KB

Similar to our IPC system, we also type-check our Electron Stores. If you want to use its functionality in your code, remember:

  • Use TypeCheckedStoreBackend and TypeCheckedStoreFrontend
  • Modifying our list of stores (adding new ones, changing the structure) can be done in src/common/types/electron_store.ts
    Note that you'll have to be very careful when changing an existing store's structure, as the old structure does not get converted to your new format automatically (to facilitate this, you can use migrations)
  • When accessing elements, use <store>.get with a default value, or <store>.get_nodefault if you can't/don't want to provide a default

Specific store structure notes:

  • If you have a store with pre-set keys, you can just add those keys into the interface:
    interface StoreStructure {
      // ...
      myStoreName: {
        myKey: boolean /* or any other type here */
      }
    }
  • If your store's keys are set dynamically (for example, a store that uses AppNames as keys), you can use Index Signatures instead:
    interface StoreStructure {
      // ...
      myStoreName: {
        [key: string]: boolean /* or any other type here */
      }
    }