Skip to content

Commit c753897

Browse files
authored
feat!: rename useActions → useDocumentActions and useActions → useDocumentActions (#362)
1 parent 014dc69 commit c753897

File tree

12 files changed

+150
-130
lines changed

12 files changed

+150
-130
lines changed

apps/kitchensink-react/src/DocumentCollection/DocumentEditorRoute.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
unpublishDocument,
1111
} from '@sanity/sdk'
1212
import {
13-
useApplyActions,
13+
useApplyDocumentActions,
1414
useDocument,
1515
useDocumentEvent,
1616
useDocumentSyncStatus,
@@ -36,7 +36,7 @@ const doc: DocumentHandle<Author> = {
3636
function Editor() {
3737
useDocumentEvent((e) => console.log(e), doc)
3838
const synced = useDocumentSyncStatus(doc)
39-
const apply = useApplyActions()
39+
const apply = useApplyDocumentActions()
4040

4141
const canEdit = usePermissions(editDocument(doc))
4242
const canCreate = usePermissions(createDocument(doc))

packages/core/src/_exports/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ export {
5252
unpublishDocument,
5353
type UnpublishDocumentAction,
5454
} from '../document/actions'
55-
export {type ActionsResult, applyActions, type ApplyActionsOptions} from '../document/applyActions'
55+
export {
56+
type ActionsResult,
57+
applyDocumentActions,
58+
type ApplyDocumentActionsOptions,
59+
} from '../document/applyDocumentActions'
5660
export {
5761
getDocumentState,
5862
getDocumentSyncStatus,

packages/core/src/document/applyActions.test.ts renamed to packages/core/src/document/applyDocumentActions.test.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// applyActions.test.ts
1+
// applyDocumentActions.test.ts
22
import {type SanityDocument} from '@sanity/types'
33
import {Subject} from 'rxjs'
44
import {describe, expect, it} from 'vitest'
@@ -7,7 +7,7 @@ import {createSanityInstance} from '../instance/sanityInstance'
77
import {type ActionContext} from '../resources/createAction'
88
import {createResourceState} from '../resources/createResource'
99
import {type DocumentAction} from './actions'
10-
import {applyActions} from './applyActions'
10+
import {applyDocumentActions} from './applyDocumentActions'
1111
import {type DocumentStoreState} from './documentStore'
1212
import {type DocumentEvent} from './events'
1313
import {type AppliedTransaction, type OutgoingTransaction} from './reducers'
@@ -25,7 +25,7 @@ const exampleDoc: SanityDocument = {
2525
_rev: 'txn0',
2626
}
2727

28-
describe('applyActions', () => {
28+
describe('applyDocumentActions', () => {
2929
it('resolves with a successful applied transaction and accepted event', async () => {
3030
const eventsSubject = new Subject<DocumentEvent>()
3131
const initialState: TestState = {
@@ -46,10 +46,14 @@ describe('applyActions', () => {
4646
patches: [{set: {foo: 'bar'}}],
4747
}
4848

49-
// Call applyActions with a fixed transactionId for reproducibility.
50-
const applyPromise = applyActions(context as ActionContext<DocumentStoreState>, action, {
51-
transactionId: 'txn-success',
52-
})
49+
// Call applyDocumentActions with a fixed transactionId for reproducibility.
50+
const applyPromise = applyDocumentActions(
51+
context as ActionContext<DocumentStoreState>,
52+
action,
53+
{
54+
transactionId: 'txn-success',
55+
},
56+
)
5357

5458
const appliedTx: AppliedTransaction = {
5559
transactionId: 'txn-success',
@@ -67,7 +71,7 @@ describe('applyActions', () => {
6771
// Update the state so that its "applied" array contains our applied transaction.
6872
state.set('simulateApplied', {applied: [appliedTx]})
6973

70-
// Await the resolution of applyActions. This should pick up the applied transaction.
74+
// Await the resolution of applyDocumentActions. This should pick up the applied transaction.
7175
const result = await applyPromise
7276

7377
// Check that the result fields match the simulated applied transaction.
@@ -114,10 +118,14 @@ describe('applyActions', () => {
114118
patches: [{set: {foo: 'error'}}],
115119
}
116120

117-
// Call applyActions with a fixed transactionId.
118-
const applyPromise = applyActions(context as ActionContext<DocumentStoreState>, action, {
119-
transactionId: 'txn-error',
120-
})
121+
// Call applyDocumentActions with a fixed transactionId.
122+
const applyPromise = applyDocumentActions(
123+
context as ActionContext<DocumentStoreState>,
124+
action,
125+
{
126+
transactionId: 'txn-error',
127+
},
128+
)
121129

122130
const errorEvent: DocumentEvent = {
123131
type: 'error',

packages/core/src/document/applyActions.ts renamed to packages/core/src/document/applyDocumentActions.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ActionsResult<TDocument extends SanityDocument = SanityDocument
2222
}
2323

2424
/** @beta */
25-
export interface ApplyActionsOptions {
25+
export interface ApplyDocumentActionsOptions {
2626
/**
2727
* Optionally provide an ID to be used as this transaction ID
2828
*/
@@ -34,30 +34,30 @@ export interface ApplyActionsOptions {
3434
}
3535

3636
/** @beta */
37-
export function applyActions<TDocument extends SanityDocument>(
37+
export function applyDocumentActions<TDocument extends SanityDocument>(
3838
instance: SanityInstance | ActionContext<DocumentStoreState>,
3939
action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
40-
options?: ApplyActionsOptions,
40+
options?: ApplyDocumentActionsOptions,
4141
): Promise<ActionsResult<TDocument>>
4242
/** @beta */
43-
export function applyActions(
43+
export function applyDocumentActions(
4444
instance: SanityInstance | ActionContext<DocumentStoreState>,
4545
action: DocumentAction | DocumentAction[],
46-
options?: ApplyActionsOptions,
46+
options?: ApplyDocumentActionsOptions,
4747
): Promise<ActionsResult>
4848
/** @beta */
49-
export function applyActions(
50-
...args: Parameters<typeof _applyActions>
51-
): ReturnType<typeof _applyActions> {
52-
return _applyActions(...args)
49+
export function applyDocumentActions(
50+
...args: Parameters<typeof _applyDocumentActions>
51+
): ReturnType<typeof _applyDocumentActions> {
52+
return _applyDocumentActions(...args)
5353
}
5454

55-
const _applyActions = createAction(documentStore, ({state}) => {
55+
const _applyDocumentActions = createAction(documentStore, ({state}) => {
5656
const {events} = state.get()
5757

5858
return async function (
5959
action: DocumentAction | DocumentAction[],
60-
{transactionId = crypto.randomUUID(), disableBatching}: ApplyActionsOptions = {},
60+
{transactionId = crypto.randomUUID(), disableBatching}: ApplyDocumentActionsOptions = {},
6161
): Promise<ActionsResult> {
6262
const actions = Array.isArray(action) ? action : [action]
6363

0 commit comments

Comments
 (0)