| 228 | ((): RowValue => defaultCellValue ?? (EMPTY_STRING as any as RowValue))); |
| 229 | |
| 230 | export const getCreateFunction = < |
| 231 | Thing extends |
| 232 | Metrics | Middleware | Indexes | Relationships | Checkpoints | Queries, |
| 233 | >( |
| 234 | getFunction: (store: Store) => Thing, |
| 235 | initFunction?: (thing: Thing) => void, |
| 236 | ): ((store: Store) => Thing) => { |
| 237 | const thingsByStore: WeakMap<Store, Thing> = new WeakMap(); |
| 238 | return (store: Store): Thing => { |
| 239 | if (!thingsByStore.has(store)) { |
| 240 | thingsByStore.set(store, getFunction(store)); |
| 241 | } |
| 242 | const thing = thingsByStore.get(store) as Thing; |
| 243 | initFunction?.(thing); |
| 244 | return thing; |
| 245 | }; |
| 246 | }; |