Skip to content

Commit

Permalink
[base] Allow passing initialValue to patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Feb 19, 2020
1 parent 87d9299 commit 407f675
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import {OperationArgs} from '../../types'
import {isLiveEditEnabled} from '../utils/isLiveEditEnabled'

// todo: we could also consider exposing 'mutate' directly
export const patch = {
disabled: (): false => false,
execute: ({snapshots, idPair, draft, published, typeName}: OperationArgs, patches = []): void => {
execute: (
{snapshots, idPair, draft, published, typeName}: OperationArgs,
patches = [],
initialValue
): void => {
if (isLiveEditEnabled(typeName)) {
// No drafting, so patch and commit the published document
published.mutate([
published.createIfNotExists({
_type: typeName
_type: typeName,
...initialValue
}),
...published.patch(patches)
])
} else {
draft.mutate([
draft.createIfNotExists({
...initialValue,
...snapshots.published,
_id: idPair.draftId,
_type: typeName
Expand Down

0 comments on commit 407f675

Please sign in to comment.