Skip to content

Commit d4539e0

Browse files
committed
feat: support source in document actions
1 parent 69a9b11 commit d4539e0

File tree

4 files changed

+116
-52
lines changed

4 files changed

+116
-52
lines changed

packages/core/src/document/applyDocumentActions.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {type SanityDocument} from '@sanity/types'
33
import {Subject} from 'rxjs'
44
import {describe, expect, it} from 'vitest'
55

6+
import {sourceFor} from '../config/sanityConfig'
67
import {bindActionByDataset} from '../store/createActionBinder'
78
import {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
89
import {} from '../store/createStateSourceAction'
@@ -31,6 +32,7 @@ const exampleDoc: SanityDocument = {
3132
}
3233

3334
describe('applyDocumentActions', () => {
35+
const source = sourceFor({projectId: 'p', dataset: 'd'})
3436
let state: StoreState<TestState>
3537
let instance: SanityInstance
3638
let eventsSubject: Subject<DocumentEvent>
@@ -75,6 +77,7 @@ describe('applyDocumentActions', () => {
7577
const applyPromise = applyDocumentActions(instance, {
7678
actions: [action],
7779
transactionId: 'txn-success',
80+
source,
7881
})
7982

8083
const appliedTx: AppliedTransaction = {
@@ -132,6 +135,7 @@ describe('applyDocumentActions', () => {
132135
const applyPromise = applyDocumentActions(instance, {
133136
actions: [action],
134137
transactionId: 'txn-error',
138+
source,
135139
})
136140

137141
const errorEvent: DocumentEvent = {
@@ -165,6 +169,7 @@ describe('applyDocumentActions', () => {
165169
const applyPromise = applyDocumentActions(childInstance, {
166170
actions: [action],
167171
transactionId: 'txn-child-match',
172+
source,
168173
})
169174

170175
// Simulate an applied transaction on the parent's instance

packages/core/src/document/applyDocumentActions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {type SanityClient} from '@sanity/client'
22
import {type SanityDocument} from 'groq'
33
import {distinctUntilChanged, filter, first, firstValueFrom, map, race} from 'rxjs'
44

5+
import {type DocumentSource} from '../config/sanityConfig'
56
import {bindActionByDataset} from '../store/createActionBinder'
67
import {type SanityInstance} from '../store/createSanityInstance'
78
import {type StoreContext} from '../store/defineStore'
@@ -37,6 +38,11 @@ export interface ApplyDocumentActionsOptions {
3738
* Set this to true to prevent this action from being batched with others.
3839
*/
3940
disableBatching?: boolean
41+
42+
/**
43+
* The source to apply to.
44+
*/
45+
source: DocumentSource
4046
}
4147

4248
/** @beta */

0 commit comments

Comments
 (0)