Fix tests
This commit is contained in:
parent
79180bfac5
commit
f5e8ed6e37
|
@ -9,7 +9,7 @@ export const enum Operations {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Operator<T extends Document> {
|
interface Operator<T extends Document> {
|
||||||
id?: string
|
id?: number
|
||||||
type: Operations
|
type: Operations
|
||||||
doc: T
|
doc: T
|
||||||
forwardPatch?: jsonpatch.Operation[]
|
forwardPatch?: jsonpatch.Operation[]
|
||||||
|
@ -22,7 +22,7 @@ interface HistoryState<T extends Document> {
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: HistoryState<never> = {
|
export const initialState = {
|
||||||
history: [],
|
history: [],
|
||||||
position: 0,
|
position: 0,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -37,10 +37,10 @@ export interface HistoryStore<T extends Document>
|
||||||
> {
|
> {
|
||||||
wrapSaveDoc: (
|
wrapSaveDoc: (
|
||||||
fn: (doc: T) => Promise<T>
|
fn: (doc: T) => Promise<T>
|
||||||
) => (doc: T, operationId?: string) => Promise<T>
|
) => (doc: T, operationId?: number) => Promise<T>
|
||||||
wrapDeleteDoc: (
|
wrapDeleteDoc: (
|
||||||
fn: (doc: T) => Promise<void>
|
fn: (doc: T) => Promise<void>
|
||||||
) => (doc: T, operationId?: string) => Promise<void>
|
) => (doc: T, operationId?: number) => Promise<void>
|
||||||
|
|
||||||
reset: () => void
|
reset: () => void
|
||||||
undo: () => Promise<void>
|
undo: () => Promise<void>
|
||||||
|
@ -70,8 +70,8 @@ export const createHistoryStore = <T extends Document>({
|
||||||
|
|
||||||
// Wrapped versions of essential functions which we call ourselves when using
|
// Wrapped versions of essential functions which we call ourselves when using
|
||||||
// undo and redo
|
// undo and redo
|
||||||
let saveFn: (doc: T, operationId?: string) => Promise<T>
|
let saveFn: (doc: T, operationId?: number) => Promise<T>
|
||||||
let deleteFn: (doc: T, operationId?: string) => Promise<void>
|
let deleteFn: (doc: T, operationId?: number) => Promise<void>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal util to set the loading flag
|
* Internal util to set the loading flag
|
||||||
|
@ -112,7 +112,7 @@ export const createHistoryStore = <T extends Document>({
|
||||||
let position = state.position
|
let position = state.position
|
||||||
if (!operation.id) {
|
if (!operation.id) {
|
||||||
// Every time a new operation occurs we discard any redo potential
|
// Every time a new operation occurs we discard any redo potential
|
||||||
operation.id = Math.random().toString()
|
operation.id = Math.random()
|
||||||
history = [...history.slice(0, state.position), operation]
|
history = [...history.slice(0, state.position), operation]
|
||||||
position += 1
|
position += 1
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,7 +133,7 @@ export const createHistoryStore = <T extends Document>({
|
||||||
* @returns {function} a wrapped version of the save function
|
* @returns {function} a wrapped version of the save function
|
||||||
*/
|
*/
|
||||||
const wrapSaveDoc = (fn: (doc: T) => Promise<T>) => {
|
const wrapSaveDoc = (fn: (doc: T) => Promise<T>) => {
|
||||||
saveFn = async (doc: T, operationId?: string) => {
|
saveFn = async (doc: T, operationId?: number) => {
|
||||||
// Only works on a single doc at a time
|
// Only works on a single doc at a time
|
||||||
if (!doc || Array.isArray(doc)) {
|
if (!doc || Array.isArray(doc)) {
|
||||||
return
|
return
|
||||||
|
@ -181,7 +181,7 @@ export const createHistoryStore = <T extends Document>({
|
||||||
* @returns {function} a wrapped version of the delete function
|
* @returns {function} a wrapped version of the delete function
|
||||||
*/
|
*/
|
||||||
const wrapDeleteDoc = (fn: (doc: T) => Promise<void>) => {
|
const wrapDeleteDoc = (fn: (doc: T) => Promise<void>) => {
|
||||||
deleteFn = async (doc: T, operationId?: string) => {
|
deleteFn = async (doc: T, operationId?: number) => {
|
||||||
// Only works on a single doc at a time
|
// Only works on a single doc at a time
|
||||||
if (!doc || Array.isArray(doc)) {
|
if (!doc || Array.isArray(doc)) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue