diff --git a/client/index.ts b/client/index.ts index fbd3f98..582ffe4 100644 --- a/client/index.ts +++ b/client/index.ts @@ -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' diff --git a/client/lib/json-patch-lib.ts b/client/lib/json-patch-lib.ts index bd60cf1..a961aa0 100644 --- a/client/lib/json-patch-lib.ts +++ b/client/lib/json-patch-lib.ts @@ -1,3 +1,5 @@ +import { PatchOp } from './types' + export interface Validator { (operation: Operation, index: number, doc: T, existingPathFragment: string): void } @@ -7,16 +9,16 @@ export interface BaseOperation { } export interface AddOperation extends BaseOperation { - op: 'add' + op: PatchOp.ADD value: T } export interface RemoveOperation extends BaseOperation { - op: 'remove' + op: PatchOp.REMOVE } export interface ReplaceOperation 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, } diff --git a/client/lib/source/mock-source.ts b/client/lib/source/mock-source.ts new file mode 100644 index 0000000..f67398f --- /dev/null +++ b/client/lib/source/mock-source.ts @@ -0,0 +1,14 @@ +import { Observable } from 'rxjs' +import { Update } from '../types' +import { Source } from './source' + +export class MockSource implements Source { + + constructor ( + private readonly seed: Observable>, + ) { } + + watch$ (): Observable> { + return this.seed + } +}