mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
add mock source
This commit is contained in:
committed by
Aiden McClelland
parent
a724d6ec6b
commit
678d7b3322
@@ -1,3 +1,4 @@
|
||||
export * from './lib/source/mock-source'
|
||||
export * from './lib/source/poll-source'
|
||||
export * from './lib/source/ws-source'
|
||||
export * from './lib/source/source'
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { PatchOp } from './types'
|
||||
|
||||
export interface Validator<T> {
|
||||
(operation: Operation, index: number, doc: T, existingPathFragment: string): void
|
||||
}
|
||||
@@ -7,16 +9,16 @@ export interface BaseOperation {
|
||||
}
|
||||
|
||||
export interface AddOperation<T> extends BaseOperation {
|
||||
op: 'add'
|
||||
op: PatchOp.ADD
|
||||
value: T
|
||||
}
|
||||
|
||||
export interface RemoveOperation extends BaseOperation {
|
||||
op: 'remove'
|
||||
op: PatchOp.REMOVE
|
||||
}
|
||||
|
||||
export interface ReplaceOperation<T> extends BaseOperation {
|
||||
op: 'replace'
|
||||
op: PatchOp.REPLACE
|
||||
value: T
|
||||
}
|
||||
|
||||
@@ -55,13 +57,13 @@ export function applyOperation (doc: Doc, op: Operation): Operation | null {
|
||||
node[key] = op.value
|
||||
if (curVal) {
|
||||
undo = {
|
||||
op: 'replace',
|
||||
op: PatchOp.REPLACE,
|
||||
path: op.path,
|
||||
value: curVal,
|
||||
}
|
||||
} else {
|
||||
undo = {
|
||||
op: 'remove',
|
||||
op: PatchOp.REMOVE,
|
||||
path: op.path,
|
||||
}
|
||||
}
|
||||
@@ -69,7 +71,7 @@ export function applyOperation (doc: Doc, op: Operation): Operation | null {
|
||||
delete node[key]
|
||||
if (curVal) {
|
||||
undo = {
|
||||
op: 'add',
|
||||
op: PatchOp.ADD,
|
||||
path: op.path,
|
||||
value: curVal,
|
||||
}
|
||||
|
||||
14
client/lib/source/mock-source.ts
Normal file
14
client/lib/source/mock-source.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { Update } from '../types'
|
||||
import { Source } from './source'
|
||||
|
||||
export class MockSource<T> implements Source<T> {
|
||||
|
||||
constructor (
|
||||
private readonly seed: Observable<Update<T>>,
|
||||
) { }
|
||||
|
||||
watch$ (): Observable<Update<T>> {
|
||||
return this.seed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user