builder icon indicating copy to clipboard operation
builder copied to clipboard

Refactor: Remove toLowerCase from indexById on Bridge

Open nicosantangelo opened this issue 2 years ago • 0 comments

It shouldn't really change anything and it should allow us to rewrite the indexById as

  static indexById<T extends { id: string }>(
    list: (T | undefined)[]
  ): Record<string, T> {
    return this.indexBy(list, 'id')
  }

  static indexBy<T extends Record<K, string>, K extends string>(
    list: (T | undefined)[],
    prop: K
  ): Record<string, T> {
    return list.reduce((obj, result) => {
      if (result) {
        const key = result[prop]
        obj[key as string] = result
      }
      return obj
    }, {} as Record<string, T>)
  }

nicosantangelo avatar Feb 21 '22 19:02 nicosantangelo