Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 43x 43x 43x 253x 251x 251x 252x 252x 13x 12x 127x 126x 126x 6x 126x 126x | import { EMPTY, Observable, of } from 'rxjs';
import { InMemoryCollectionStore } from './InMemoryCollectionStore';
import { KeyValueCollection, KeyValueStore } from '../types';
export class InMemoryKeyValueStore<K, V>
extends InMemoryCollectionStore<KeyValueCollection<K, V>>
implements KeyValueStore<K, V>
{
getValues(keys: K[]): Observable<V[]> {
if (this.destroyed || keys.length === 0) return EMPTY;
const result: V[] = [];
for (const key of keys) {
const value = this.docs.find((doc) => doc.key === key)?.value;
if (!value) return EMPTY;
result.push(value);
}
return of(result);
}
setValue(key: K, value: V): Observable<void> {
if (this.destroyed) return EMPTY;
const storedDocIndex = this.docs.findIndex((doc) => doc.key === key);
if (storedDocIndex >= 0) {
this.docs.splice(storedDocIndex, 1);
}
this.docs.push({ key, value });
return of(void 0);
}
}
|