feat(client): remove data mutation (#32)

* feat(client): remove data mutation

* chore: address comments and fix some other issues

* chore: send the most recent cache upon subscription
This commit is contained in:
Alex Inkin
2022-05-27 01:23:56 +03:00
committed by GitHub
parent 35973d7aef
commit 6f6c26acd4
8 changed files with 84 additions and 110 deletions

View File

@@ -1,13 +1,13 @@
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { Update } from "../types";
import { Source } from "./source";
import { RPCResponse } from "./ws-source";
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { Update } from '../types'
import { Source } from './source'
import { RPCResponse } from './ws-source'
export class MockSource<T> implements Source<T> {
constructor(private readonly seed: Observable<Update<T>>) {}
constructor (private readonly seed: Observable<Update<T>>) { }
watch$(): Observable<RPCResponse<Update<T>>> {
return this.seed.pipe(map((result) => ({ result, jsonrpc: "2.0" })));
watch$ (): Observable<RPCResponse<Update<T>>> {
return this.seed.pipe(map((result) => ({ result, jsonrpc: '2.0' })))
}
}

View File

@@ -1,4 +1,4 @@
import { BehaviorSubject, concat, from, Observable, of, Subject } from 'rxjs'
import { BehaviorSubject, concat, from, Observable, of } from 'rxjs'
import { concatMap, delay, map, skip, switchMap, take, tap } from 'rxjs/operators'
import { Store } from '../store'
import { Http, Update } from '../types'

View File

@@ -43,14 +43,6 @@ export interface RPCError extends RPCBase {
}
export type RPCResponse<T> = RPCSuccess<T> | RPCError
function isRpcError<Error, Result> (arg: { error: Error } | { result: Result}): arg is { error: Error } {
return !!(arg as any).error
}
function isRpcSuccess<Error, Result> (arg: { error: Error } | { result: Result}): arg is { result: Result } {
return !!(arg as any).result
}
class RpcError {
code: number
message: string
@@ -61,4 +53,4 @@ class RpcError {
this.message = e.message
this.details = e.data.details
}
}
}