Skip to content

Commit

Permalink
Merge pull request #12 from jotai-labs/jotai-new-async-api
Browse files Browse the repository at this point in the history
Migrate to Jotai v2 API
  • Loading branch information
barelyhuman committed Dec 11, 2022
2 parents d896b19 + 87487eb commit 37c1a90
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion __tests__/01_basic_spec.tsx
@@ -1,6 +1,6 @@
import { fireEvent, render, waitFor } from '@testing-library/react';
import React from 'react';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from '../src/index';

describe('atomWithValidate spec', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/02_form_validation.tsx
Expand Up @@ -2,7 +2,7 @@ import 'regenerator-runtime/runtime';

import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
import React from 'react';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import * as Yup from 'yup';
import { atomWithValidate, validateAtoms } from '../src/index';

Expand Down
2 changes: 1 addition & 1 deletion examples/01_minimal/src/index.js
@@ -1,6 +1,6 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';

const fieldAtom = atomWithValidate(0, {
Expand Down
2 changes: 1 addition & 1 deletion examples/02_typescript/src/App.tsx
@@ -1,5 +1,5 @@
import React from 'react';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';
import { number } from 'yup';

Expand Down
2 changes: 1 addition & 1 deletion examples/03_joi/src/App.tsx
@@ -1,5 +1,5 @@
import React from 'react';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';
import Joi from 'joi';

Expand Down
2 changes: 1 addition & 1 deletion examples/04_demo/src/index.js
@@ -1,7 +1,7 @@
import 'normalize.css/normalize.css';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';
import styled from 'styled-components';
import * as Yup from 'yup';
Expand Down
2 changes: 1 addition & 1 deletion examples/04_demo/src/resources/code.js
@@ -1,5 +1,5 @@
export const defaultCode = `
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';
import * as Yup from 'yup';
Expand Down
2 changes: 1 addition & 1 deletion examples/05_zod/src/index.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import { useAtom } from 'jotai';
import { useAtom } from 'jotai/react';
import { atomWithValidate } from 'jotai-form';
import { z } from 'zod';

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -71,7 +71,7 @@
"html-webpack-plugin": "^5.5.0",
"jest": "^27.5.1",
"joi": "^17.7.0",
"jotai": "^1.9.2",
"jotai": "^1.11.0",
"microbundle": "^0.14.2",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5",
Expand All @@ -93,6 +93,6 @@
"zod": "^3.19.1"
},
"peerDependencies": {
"jotai": "*"
"jotai": ">=1.11.0"
}
}
8 changes: 4 additions & 4 deletions src/atomWithValidate.ts
@@ -1,5 +1,5 @@
import { atom } from 'jotai';
import type { WritableAtom, SetStateAction } from 'jotai';
import { atom } from 'jotai/vanilla';
import type { WritableAtom, SetStateAction } from 'jotai/vanilla';

export type CommonState<Value> = {
value: Value;
Expand Down Expand Up @@ -31,12 +31,12 @@ type SyncOptions<Value> = CommonOptions<Value> & {
export function atomWithValidate<Value>(
initialValue: Value,
options: AsyncOptions<Value>,
): WritableAtom<AsyncState<Value>, SetStateAction<Value>>;
): WritableAtom<AsyncState<Value>, [SetStateAction<Value>], void>;

export function atomWithValidate<Value>(
initialValue: Value,
options: SyncOptions<Value>,
): WritableAtom<SyncState<Value>, SetStateAction<Value>>;
): WritableAtom<SyncState<Value>, [SetStateAction<Value>], void>;

export function atomWithValidate<Value>(
initialValue: Value,
Expand Down
8 changes: 5 additions & 3 deletions src/validateAtoms.ts
@@ -1,5 +1,6 @@
import { atom, Getter, SetStateAction, WritableAtom } from 'jotai';
import { loadable } from 'jotai/utils';
import { atom } from 'jotai/vanilla';
import type { Getter, SetStateAction, WritableAtom } from 'jotai/vanilla';
import { loadable } from 'jotai/vanilla/utils';

import type { CommonState } from './atomWithValidate';

Expand All @@ -17,7 +18,8 @@ export type ValidatorState = {

type AtomWithValidation<Value> = WritableAtom<
CommonState<Value>,
SetStateAction<Value>
[SetStateAction<Value>],
void
>;

type State<Values extends Record<string, unknown>> = {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -5133,10 +5133,10 @@ joi@^17.7.0:
"@sideway/formula" "^3.0.0"
"@sideway/pinpoint" "^2.0.0"

jotai@^1.9.2:
version "1.11.1"
resolved "https://registry.yarnpkg.com/jotai/-/jotai-1.11.1.tgz#a85d2ba34363e831e1e2aa74dead4a0b1ac9e5ae"
integrity sha512-pHpaZUdvIpcS12ryMCrwtvmT/IovZAbicfrlll/Rb9394rwhqKoDFsDs0kv4oWtBy/XHHNv7iSZnQFmntiQj+w==
jotai@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/jotai/-/jotai-1.11.0.tgz#d2a666f16935797743eb41a3b75583ea4e17fefb"
integrity sha512-8OzJmRxcTZoAOJSz6uTnmofmjAOgNOdAOy26rvyw3OBxt6XIoklNnfUTCm8wgp84SSLJbPZA01VS5O/SUz+QYg==

js-sdsl@^4.1.4:
version "4.2.0"
Expand Down

0 comments on commit 37c1a90

Please sign in to comment.