Skip to content

Commit

Permalink
[desk-tool] chunker: Pass along draft/publishedState properly
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and rexxars committed Oct 6, 2020
1 parent 979176c commit 3fe03dc
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ export function mergeChunk(left: Chunk, right: Chunk): Chunk | [Chunk, Chunk] {

// TODO: How to detect first squash/create

if (left.type === 'delete' && right.type === 'editDraft') {
return [left, {...right, type: 'create'}]
}

const draftState = combineState(left.draftState, right.draftState)
const publishedState = combineState(left.publishedState, right.publishedState)

if (left.type === 'delete' && right.type === 'editDraft') {
return [left, {...right, type: 'create', draftState, publishedState}]
}

// Convert deletes into either discardDraft or unpublish depending on what's been deleted.
if (right.type === 'delete') {
if (draftState === 'missing' && publishedState === 'present') {
return [left, {...right, type: 'discardDraft'}]
return [left, {...right, type: 'discardDraft', draftState, publishedState}]
}

if (draftState === 'present' && publishedState === 'missing') {
return [left, {...right, type: 'unpublish'}]
return [left, {...right, type: 'unpublish', draftState, publishedState}]
}
}

Expand All @@ -62,7 +62,7 @@ export function mergeChunk(left: Chunk, right: Chunk): Chunk | [Chunk, Chunk] {
}
}

return [left, right]
return [left, {...right, draftState, publishedState}]
}

export function chunkFromTransaction(transaction: Transaction): Chunk {
Expand Down

0 comments on commit 3fe03dc

Please sign in to comment.