Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/document/applyDocumentActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {type SanityDocument} from '@sanity/types'
import {Subject} from 'rxjs'
import {describe, expect, it} from 'vitest'

import {sourceFor} from '../config/sanityConfig'
import {bindActionByDataset} from '../store/createActionBinder'
import {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
import {} from '../store/createStateSourceAction'
Expand Down Expand Up @@ -31,6 +32,7 @@ const exampleDoc: SanityDocument = {
}

describe('applyDocumentActions', () => {
const source = sourceFor({projectId: 'p', dataset: 'd'})
let state: StoreState<TestState>
let instance: SanityInstance
let eventsSubject: Subject<DocumentEvent>
Expand Down Expand Up @@ -75,6 +77,7 @@ describe('applyDocumentActions', () => {
const applyPromise = applyDocumentActions(instance, {
actions: [action],
transactionId: 'txn-success',
source,
})

const appliedTx: AppliedTransaction = {
Expand Down Expand Up @@ -132,6 +135,7 @@ describe('applyDocumentActions', () => {
const applyPromise = applyDocumentActions(instance, {
actions: [action],
transactionId: 'txn-error',
source,
})

const errorEvent: DocumentEvent = {
Expand Down Expand Up @@ -165,6 +169,7 @@ describe('applyDocumentActions', () => {
const applyPromise = applyDocumentActions(childInstance, {
actions: [action],
transactionId: 'txn-child-match',
source,
})

// Simulate an applied transaction on the parent's instance
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/document/applyDocumentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {type SanityClient} from '@sanity/client'
import {type SanityDocument} from 'groq'
import {distinctUntilChanged, filter, first, firstValueFrom, map, race} from 'rxjs'

import {type DocumentSource} from '../config/sanityConfig'
import {bindActionByDataset} from '../store/createActionBinder'
import {type SanityInstance} from '../store/createSanityInstance'
import {type StoreContext} from '../store/defineStore'
Expand Down Expand Up @@ -37,6 +38,11 @@ export interface ApplyDocumentActionsOptions {
* Set this to true to prevent this action from being batched with others.
*/
disableBatching?: boolean

/**
* The source to apply to.
*/
source: DocumentSource
}

/** @beta */
Expand Down
Loading
Loading