All files / src/store/factories store.factory.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 1/1
100% Lines 10/10

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      3x 3x 3x   3x     3x 6x   6x 4x 3x   3x  
'use strict';
 
import AStore from '../a.store';
import CountStore from '../count.store';
import DocumentStore from '../document.store';
import CollectionStore from '../collection.store';
import type StoreScopeType from '../../types/store.scope.type';
import BackendRegistry from '../../backend/backend.registry';
import IObservableBackend from '../../backend/i.observable.backend';
 
const storeFactory = (scope: StoreScopeType, observe: string, target: string): AStore => {
	const backend: IObservableBackend = BackendRegistry.get(observe);
 
	if (scope === 'many') return new CollectionStore(backend, target);
	if (scope === 'count') return new CountStore(backend, target);
	return new DocumentStore(backend, target);
};
export default storeFactory;