-
Notifications
You must be signed in to change notification settings - Fork 1
feat: make applyDocumentActions more similar to the rest #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
9ebc4e0
to
8d9b001
Compare
{state}: StoreContext<DocumentStoreState>, | ||
{actions, transactionId = crypto.randomUUID(), disableBatching}: ApplyDocumentActionsOptions, | ||
): Promise<ActionsResult> { | ||
const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like moving these checks to the React package, useApplyDocumentActions
, would allow developers using the core package directly to pass invalid actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t actually validate the actions in core, though? If you’re using core methods you must pass data which matches the TypeScript definition or bad things happen.
I’ve just dropped support for having either an array or an object in core, but I don’t think there’s much difference from that.
`applyDocumentActions` was the only function in the `core` package which interpreted the `SanityInstance` as a tree, automatically traversing the tree to find a matching instance. This is inconsistent with the other stores (e.g. query store) which assumes that it's being called with the right instance. In addition, this changes `applyDocumentActions` to only accept actions as an array (so we don't have to check if it's an array or not) and also it places the `actions` as part of option. This is consistent with e.g. `getQueryState` which has a required `query` field in its options. This now means that all functions which are wrapped in `bindActionByDataset` are now consistently getting passed an object as their first argument. This is going to be key so that we later can modify this function to consider the options (instead of the instance). There should be no breaking changes in the React package.
8d9b001
to
606c73f
Compare
Description
applyDocumentActions
was the only function in thecore
package which interpreted theSanityInstance
as a tree, automatically traversing the tree to find a matching instance. This is inconsistent with the other stores (e.g. query store) which assumes that it's being called with the right instance.In addition, this changes
applyDocumentActions
to only accept actions as an array (so we don't have to check if it's an array or not) and also it places theactions
as part of option. This is consistent with e.g.getQueryState
which has a requiredquery
field in its options. This now means that all functions which are wrapped inbindActionByDataset
are now consistently getting passed an object as their first argument. This is going to be key so that we later can modify this function to consider the options (instead of the instance).There should be no breaking changes in the React package.
What to review
Testing
Fun gif