mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
backend mocking for reqs that alter state
This commit is contained in:
committed by
Aiden McClelland
parent
64b087a78e
commit
cf967706ae
@@ -1,11 +1,13 @@
|
||||
import { Inject, Injectable, InjectionToken } from '@angular/core'
|
||||
import { Bootstrapper, PatchDB, Source, Store } from 'patch-db-client'
|
||||
import { BehaviorSubject, Observable, of, Subscription } from 'rxjs'
|
||||
import { catchError, debounceTime, map, tap } from 'rxjs/operators'
|
||||
import { catchError, debounceTime, finalize, map, tap } from 'rxjs/operators'
|
||||
import { ApiService } from '../api/api.service'
|
||||
import { DataModel } from './data-model'
|
||||
|
||||
export const BOOTSTRAPPER = new InjectionToken<Bootstrapper<DataModel>>('app.config')
|
||||
export const PATCH_HTTP = new InjectionToken<Source<DataModel>>('app.config')
|
||||
export const PATCH_SOURCE = new InjectionToken<Source<DataModel>>('app.config')
|
||||
export const BOOTSTRAPPER = new InjectionToken<Bootstrapper<DataModel>>('app.config')
|
||||
|
||||
export enum ConnectionStatus {
|
||||
Initializing = 'initializing',
|
||||
@@ -24,13 +26,14 @@ export class PatchDbModel {
|
||||
private patchSub: Subscription
|
||||
|
||||
constructor (
|
||||
@Inject(PATCH_SOURCE) private readonly source: Source<DataModel>,
|
||||
@Inject(PATCH_HTTP) private readonly http: ApiService,
|
||||
@Inject(BOOTSTRAPPER) private readonly bootstrapper: Bootstrapper<DataModel>,
|
||||
@Inject(PATCH_SOURCE) private readonly sources: Source<DataModel>[],
|
||||
) { }
|
||||
|
||||
async init (): Promise<void> {
|
||||
const cache = await this.bootstrapper.init()
|
||||
this.patchDb = new PatchDB(this.sources, cache)
|
||||
this.patchDb = new PatchDB([this.source, this.http], this.http, cache)
|
||||
|
||||
this.sequence$ = this.patchDb.store.sequence$.asObservable()
|
||||
this.data = this.patchDb.store.cache.data
|
||||
@@ -81,14 +84,14 @@ export class PatchDbModel {
|
||||
}
|
||||
|
||||
watch$: Store<DataModel>['watch$'] = (...args: (string | number)[]): Observable<DataModel> => {
|
||||
// console.log('WATCHING')
|
||||
console.log('WATCHING', ...args)
|
||||
return this.patchDb.store.watch$(...(args as [])).pipe(
|
||||
tap(cache => console.log('CHANGE IN STORE', cache)),
|
||||
catchError(e => {
|
||||
console.error(e)
|
||||
return of(e.message)
|
||||
}),
|
||||
// finalize(() => console.log('unSUBSCRIBing')),
|
||||
finalize(() => console.log('UNSUBSCRIBING')),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user