Skip to content

Commit

Permalink
breaking: rename atom(Family)WithInitialValue to initializableAtom(Fa…
Browse files Browse the repository at this point in the history
…mily)
  • Loading branch information
koichik committed Aug 2, 2022
1 parent b6429f3 commit 2d14b85
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -196,14 +196,14 @@ function MyApp({ Component, pageProps }: AppProps) {

## Utilities

### atomWithInitialValue
### initializableAtom

`atom`, but initial value can be specified when using it.

Note: This is just a utility and does not depend on either Recoil Sync or Next.js.

```typescript
function atomWithInitialValue<T extends SerializableParam>(options: {
function initializableAtom<T extends SerializableParam>(options: {
key: string
effects?:
| ReadonlyArray<AtomEffect<T>>
Expand All @@ -229,9 +229,9 @@ A function which takes its `initialValue`.
#### Example

```tsx
import { atomWithInitialValue } from 'recoil-sync-next'
import { initializableAtom } from 'recoil-sync-next'

const countState = atomWithInitialValue<number>({
const countState = initializableAtom<number>({
key: 'count',
})

Expand All @@ -241,14 +241,14 @@ const MyComponent: React.FC = () => {
}
```
### atomFamilyWithInitialValue
### initializableAtomFamily
`atomFamily`, but initial value can be specified individually when using it.
Note: This is just a utility and does not depend on either Recoil Sync or Next.js.
```typescript
function atomFamilyWithInitialValue<
function initializableAtomFamily<
T extends SerializableParam,
P extends SerializableParam
>(options: {
Expand Down Expand Up @@ -280,9 +280,9 @@ A function which takes `paramter` that map to an atom, and its `initialValue`.
#### Example

```tsx
import { atomFamilyWithInitialValue } from 'recoil-sync-next'
import { initializableAtomFamily } from 'recoil-sync-next'
const countState = atomFamilyWithInitialValue<number, string>({
const countState = initializableAtomFamily<number, string>({
key: 'count',
})
Expand Down
6 changes: 3 additions & 3 deletions src/history/RecoilHistorySyncJSONNext.test.tsx
Expand Up @@ -12,7 +12,7 @@ import { act } from 'react-dom/test-utils'
import { atom, atomFamily, RecoilRoot, useRecoilState } from 'recoil'
import { syncEffect } from 'recoil-sync'

import { atomFamilyWithInitialValue } from '../utils/atomFamilyWithInitialValue'
import { initializableAtomFamily } from '../utils/initializableAtomFamily'

import { RecoilHistorySyncJSONNext } from './RecoilHistorySyncJSONNext'

Expand Down Expand Up @@ -235,8 +235,8 @@ describe('<RecoilHistorySyncJSONNext />', () => {
})
})

describe('use atomFamilyWithInitialValue()', () => {
const testStringState = atomFamilyWithInitialValue<string, string>({
describe('use initializableAtomFamily()', () => {
const testStringState = initializableAtomFamily<string, string>({
key: nextKey(),
effects: [syncEffect({ refine: string() })],
})
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -2,5 +2,5 @@ export * from './history/RecoilHistorySyncJSONNext'
export * from './history/RecoilHistorySyncTransitNext'
export * from './url/RecoilURLSyncJSONNext'
export * from './url/RecoilURLSyncTransitNext'
export * from './utils/atomFamilyWithInitialValue'
export * from './utils/atomWithInitialValue'
export * from './utils/initializableAtom'
export * from './utils/initializableAtomFamily'
Expand Up @@ -4,24 +4,24 @@ import React, { ReactNode } from 'react'
import { act } from 'react-dom/test-utils'
import { RecoilRoot, useRecoilState, useRecoilValue } from 'recoil'

import { atomWithInitialValue } from './atomWithInitialValue'
import { initializableAtom } from './initializableAtom'

let atomIndex = 0
const nextKey = () => `atomWithInitialValue/test/${atomIndex++}`
const nextKey = () => `initializableAtom/test/${atomIndex++}`

const testStringState = atomWithInitialValue<string>({
const testStringState = initializableAtom<string>({
key: nextKey(),
})

const testNumberState = atomWithInitialValue<number>({
const testNumberState = initializableAtom<number>({
key: nextKey(),
})

const App: React.FC<{ children: ReactNode }> = ({ children }) => (
<RecoilRoot>{children}</RecoilRoot>
)

describe('atomWithInitialValue', () => {
describe('initializableAtom', () => {
describe('just hook', () => {
describe('single state', () => {
it('should be initialized with a specific value', async () => {
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
AtomOptions,
} from 'recoil'

export function atomWithInitialValue<T extends SerializableParam>(
export function initializableAtom<T extends SerializableParam>(
options: Omit<AtomOptions<T>, 'default'>
): (initialValue: T) => RecoilState<T> {
const baseAtom: RecoilState<T> = atom<T>({
Expand Down
Expand Up @@ -4,24 +4,24 @@ import { ReactNode } from 'react'
import { act } from 'react-dom/test-utils'
import { RecoilRoot, useRecoilState, useRecoilValue } from 'recoil'

import { atomFamilyWithInitialValue } from './atomFamilyWithInitialValue'
import { initializableAtomFamily } from './initializableAtomFamily'

let atomIndex = 0
const nextKey = () => `atomFamilyWithInitialValue/test/${atomIndex++}`
const nextKey = () => `initializableAtomFamily/test/${atomIndex++}`

const testStringState = atomFamilyWithInitialValue<string, string>({
const testStringState = initializableAtomFamily<string, string>({
key: nextKey(),
})

const testNumberState = atomFamilyWithInitialValue<number, string>({
const testNumberState = initializableAtomFamily<number, string>({
key: nextKey(),
})

const App: React.FC<{ children: ReactNode }> = ({ children }) => (
<RecoilRoot>{children}</RecoilRoot>
)

describe('atomFamilyWithInitialValue', () => {
describe('initializableAtomFamily', () => {
describe('just hook', () => {
describe('single state', () => {
it('should be initialized with a specific value', async () => {
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
AtomFamilyOptions,
} from 'recoil'

export function atomFamilyWithInitialValue<
export function initializableAtomFamily<
T extends SerializableParam,
P extends SerializableParam
>(
Expand Down

0 comments on commit 2d14b85

Please sign in to comment.