dont watch patch.data directly in TS (#371)

* dont watch patch.data directly in TS

* installs and uninstalls working

* minor repairs
This commit is contained in:
Matt Hill
2021-07-20 10:20:39 -06:00
committed by Aiden McClelland
parent e8bf254b91
commit 08e845228f
50 changed files with 444 additions and 340 deletions

View File

@@ -62,8 +62,8 @@ export interface InstallProgress {
'download-complete': boolean
validated: number
'validation-complete': boolean
read: number
'read-complete': boolean
unpacked: number
'unpack-complete': boolean
}
export interface InstalledPackageDataEntry {

View File

@@ -8,7 +8,7 @@ import { ApiService } from 'src/app/services/api/embassy/embassy-api.service'
export function PatchDbServiceFactory (
config: ConfigService,
bootstrapper: LocalStorageBootstrap,
apiService: ApiService,
embassyApi: ApiService,
): PatchDbService {
const { mocks, patchDb: { poll }, isConsulate } = config
@@ -17,13 +17,13 @@ export function PatchDbServiceFactory (
if (mocks.enabled) {
if (mocks.connection === 'poll') {
source = new PollSource({ ...poll }, apiService)
source = new PollSource({ ...poll }, embassyApi)
} else {
source = new WebsocketSource(`ws://localhost:${config.mocks.wsPort}/db`)
}
} else {
if (isConsulate) {
source = new PollSource({ ...poll }, apiService)
source = new PollSource({ ...poll }, embassyApi)
} else {
const protocol = window.location.protocol === 'http:' ? 'ws' : 'wss'
const host = window.location.host
@@ -31,5 +31,5 @@ export function PatchDbServiceFactory (
}
}
return new PatchDbService(source, apiService, bootstrapper)
return new PatchDbService(source, embassyApi, bootstrapper)
}

View File

@@ -20,10 +20,11 @@ export enum ConnectionStatus {
})
export class PatchDbService {
connectionStatus$ = new BehaviorSubject(ConnectionStatus.Initializing)
data: DataModel
private patchDb: PatchDB<DataModel>
private patchSub: Subscription
get data () { return this.patchDb.store.cache.data }
constructor (
@Inject(PATCH_SOURCE) private readonly source: Source<DataModel>,
@Inject(PATCH_HTTP) private readonly http: ApiService,
@@ -33,7 +34,6 @@ export class PatchDbService {
async init (): Promise<void> {
const cache = await this.bootstrapper.init()
this.patchDb = new PatchDB([this.source, this.http], this.http, cache)
this.data = this.patchDb.store.cache.data
}
start (): void {
@@ -44,7 +44,7 @@ export class PatchDbService {
.pipe(debounceTime(500))
.subscribe({
next: cache => {
console.log('saving cacheee: ', cache)
console.log('saving cacheee: ', JSON.parse(JSON.stringify(cache)))
this.connectionStatus$.next(ConnectionStatus.Connected)
this.bootstrapper.update(cache)
},
@@ -82,8 +82,9 @@ export class PatchDbService {
watch$: Store<DataModel>['watch$'] = (...args: (string | number)[]): Observable<DataModel> => {
console.log('WATCHING', ...args)
return this.patchDb.store.watch$(...(args as [])).pipe(
tap(cache => console.log('CHANGE IN STORE', cache)),
return this.patchDb.store.watch$(...(args as []))
.pipe(
tap(data => console.log('CHANGE IN STORE', data, ...args)),
catchError(e => {
console.error(e)
return of(e.message)