-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Dependency updates - added jsdoc comments to all functions
- Loading branch information
Showing
8 changed files
with
3,270 additions
and
1,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
# Change Log | ||
|
||
## [Unreleased] | ||
|
||
## [0.6.0] - 2023-06-06 | ||
|
||
### Added | ||
|
||
- feat: update dependencies to latest versions | ||
- feat: add ChatGPT-generated JSDoc documentation | ||
|
||
## [0.5.0] - 2023-03-04 | ||
|
||
### Added | ||
- feat: mark internal atoms as private | ||
|
||
- feat: mark internal atoms as private | ||
|
||
## [0.4.0] - 2023-01-31 | ||
|
||
### Added | ||
|
||
- Migrate to Jotai v2 API #3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import { commitMutation } from 'relay-runtime'; | ||
import { atom, Getter, WritableAtom } from 'jotai/vanilla'; | ||
import type { | ||
Disposable, | ||
Environment, | ||
MutationConfig, | ||
MutationParameters, | ||
} from 'relay-runtime'; | ||
import { atom } from 'jotai/vanilla'; | ||
import type { Getter, WritableAtom } from 'jotai/vanilla'; | ||
import { commitMutation } from 'relay-runtime'; | ||
import { environmentAtom } from './environmentAtom'; | ||
|
||
/** | ||
* Creates a Jotai atom with a Relay mutation. | ||
* | ||
* @param getEnvironment - Function to retrieve the Relay environment. Defaults to using the environmentAtom. | ||
* @returns A Jotai writable atom that commits the mutation. | ||
*/ | ||
export function atomWithMutation<T extends MutationParameters>( | ||
getEnvironment: (get: Getter) => Environment = (get) => get(environmentAtom), | ||
): WritableAtom<undefined, [MutationConfig<T>], Disposable> { | ||
// Define a Jotai atom that performs a Relay mutation when set. | ||
const mutationAtom = atom( | ||
// Don't we have any valid value for this atom?? | ||
undefined, | ||
undefined, // Initial value of the atom is undefined. | ||
(get, _set, config: MutationConfig<T>) => { | ||
const environment = getEnvironment(get); | ||
return commitMutation(environment, config); | ||
}, | ||
); | ||
|
||
return mutationAtom; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.