Skip to content

Commit

Permalink
Merge branch 'main' into feat/experimental-version-object
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Dec 28, 2021
2 parents 9091d5e + 5e6da03 commit 685ae4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
38 changes: 19 additions & 19 deletions docs/api/utils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,79 @@ This is an overview over atom creators/hooks utilities that can found under `jot

## Overview

1. [atomWithStorage](../utils/atom-with-storage)
1. [atomWithStorage](../utils/atom-with-storage.mdx)

The `atomWithStorage` function creates an atom with a value persisted in `localStorage` or `sessionStorage` for React or `AsyncStorage` for React Native.

2. [atomWithObservable](../utils/atom-with-observable)
2. [atomWithObservable](../utils/atom-with-observable.mdx)

The `atomWithObservable` function creates an atom from a rxjs (or similar) `subject` or `observable`. Its value will be last value emitted from the stream.

3. [useUpdateAtom](../utils/use-update-atom)
3. [useUpdateAtom](../utils/use-update-atom.mdx)

Use `useUpdateAtom` and write-only atoms to avoid re-render.

4. [useAtomValue](../utils/use-atom-value)
4. [useAtomValue](../utils/use-atom-value.mdx)

Returns the value of the given atom.

5. [atomWithReset](../utils/atom-with-reset)
5. [atomWithReset](../utils/atom-with-reset.mdx)

Creates an atom that could be reset to its `initialValue` with `useResetAtom` hook.

6. [useResetAtom](../utils/use-reset-atom)
6. [useResetAtom](../utils/use-reset-atom.mdx)

Resets a Resettable atom to its initial value.

7. [RESET](../utils/reset)
7. [RESET](../utils/reset.mdx)

Special value that is accepted by Resettable atoms created with `atomWithReset`, `atomWithDefault` or writable atom created with atom if it accepts `RESET` symbol.

8. [useReducerAtom](../utils/use-reducer-atom)
8. [useReducerAtom](../utils/use-reducer-atom.mdx)

Use this hook to update an atom value with a reducer function.

9. [atomWithReducer](../utils/atom-with-reducer)
9. [atomWithReducer](../utils/atom-with-reducer.mdx)

This is a function to create an atom with an embeded reducer function to update the value.

10. [atomWithDefault](../utils/atom-with-default)
10. [atomWithDefault](../utils/atom-with-default.mdx)

This is a function to create an overwritable primitive atom. Its default value can be specified with a read function instead of a static initial value.

11. [atomWithHash](../utils/atom-with-hash)
11. [atomWithHash](../utils/atom-with-hash.mdx)

This creates a new atom that is connected with URL hash.

12. [atomFamily](../utils/atom-family)
12. [atomFamily](../utils/atom-family.mdx)

This will create a function that takes param and returns an atom.

13. [selectAtom](../utils/select-atom)
13. [selectAtom](../utils/select-atom.mdx)

This function creates a derived atom whose value is a function of the original atom's value, determined by `selector`.

14. [useAtomCallback](../utils/use-atom-callback)
14. [useAtomCallback](../utils/use-atom-callback.mdx)

This hook allows to interact with atoms imperatively.

15. [freezeAtom](../utils/freeze-atom)
15. [freezeAtom](../utils/freeze-atom.mdx)

The `freezeAtom` takes an existing atom and returns a new derived atom. The value with the new derived atom will be frozen (= not mutable).

16. [freezeAtomCreator](../utils/freeze-atom-creator)
16. [freezeAtomCreator](../utils/freeze-atom-creator.mdx)

Instead of create a frozen atom from an existing atom, `freezeAtomCreator` takes an atom creator function and returns a new function.

17. [splitAtom](../utils/split-atom)
17. [splitAtom](../utils/split-atom.mdx)

The `splitAtom` utility is useful for when you want to get an atom for each element in a list.

18. [waitForAll](../utils/wait-for-all)
18. [waitForAll](../utils/wait-for-all.mdx)

The `waitForAll` utility is a concurrency helper, which allows us to evaluate multiple async atoms.

19. [useHydrateAtoms](../utils/use-hydrate-atoms)
19. [useHydrateAtoms](../utils/use-hydrate-atoms.mdx)

The primary use case for `useHydrateAtoms` are SSR apps like Next.js, where an initial value is e.g. fetched on the server, which can be passed to a component by props.

Expand Down
4 changes: 0 additions & 4 deletions src/core/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ type OnMount<Update, Result extends void | Promise<void>> = <
export type Atom<Value> = {
toString: () => string
debugLabel?: string
/**
* @deprecated Instead use `useAtom(atom, scope)`
*/
scope?: Scope
read: Read<Value>
}

Expand Down
18 changes: 1 addition & 17 deletions src/utils/atomFamily.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Atom, WritableAtom } from 'jotai'
import type { Atom } from 'jotai'

type ShouldRemove<Param> = (createdAt: number, param: Param) => boolean

Expand All @@ -13,22 +13,6 @@ export function atomFamily<Param, AtomType extends Atom<unknown>>(
areEqual?: (a: Param, b: Param) => boolean
): AtomFamily<Param, AtomType>

/**
* @deprecated type (use atomFamily<Param, AtomType extends Atom<unknown>>)
*/
export function atomFamily<Param, Value, Update>(
initializeAtom: (param: Param) => WritableAtom<Value, Update>,
areEqual?: (a: Param, b: Param) => boolean
): AtomFamily<Param, WritableAtom<Value, Update>>

/**
* @deprecated type (use atomFamily<Param, AtomType extends Atom<unknown>>)
*/
export function atomFamily<Param, Value>(
initializeAtom: (param: Param) => Atom<Value>,
areEqual?: (a: Param, b: Param) => boolean
): AtomFamily<Param, Atom<Value>>

export function atomFamily<Param, AtomType extends Atom<unknown>>(
initializeAtom: (param: Param) => AtomType,
areEqual?: (a: Param, b: Param) => boolean
Expand Down

0 comments on commit 685ae4e

Please sign in to comment.