import * as lf from 'lovefield' ; import { Observable } from 'rxjs/Observable' ; import { ConnectableObservable } from 'rxjs/observable/ConnectableObservable' ; import { ReplaySubject } from 'rxjs/ReplaySubject' ; import { Observer } from 'rxjs/Observer' ; import { LfFactoryInit } from '../../interface' ; export const rawDb$ = new ReplaySubject < lf . raw . BackStore > ( 1 ) ; function onUpgrade ( rawDb ) { rawDb$ . next ( rawDb ) ; rawDb$ . complete ( ) ; return Promise . resolve ( ) ; } export const lfFactory = ( schemaBuilder , config ) : ConnectableObservable < lf . Database > => { return Observable . create ( ( observer ) => { ( config as any ) . onUpgrade = onUpgrade ; if ( config . storeType >= 3 ) { config . storeType = config . storeType + 1 ; } schemaBuilder . connect ( config as any ) . then ( db => { observer . next ( db ) ; observer . complete ( ) ; } ) . catch ( e => observer . error ( e ) ) ; } ) . publishReplay ( 1 ) ; } ;