Skip to content
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

Migrate to Jotai v2 API #12

Merged
merged 4 commits into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -60,6 +60,7 @@
"@types/react-dom": "^18.0.1",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"add": "^2.0.6",
dai-shi marked this conversation as resolved.
Show resolved Hide resolved
"bumpp": "^8.2.1",
"css-loader": "^6.7.1",
"eslint": "^8.13.0",
Expand All @@ -72,7 +73,7 @@
"html-webpack-plugin": "^5.5.0",
"jest": "^27.5.1",
"joi": "^17.6.0",
"jotai": "^1.6.4",
"jotai": "^1.11.0",
"microbundle": "^0.14.2",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5",
Expand All @@ -90,10 +91,11 @@
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.8.1",
"yarn": "^1.22.19",
dai-shi marked this conversation as resolved.
Show resolved Hide resolved
"yup": "^0.32.11",
"zod": "^3.18.0"
},
"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
18 changes: 14 additions & 4 deletions yarn.lock
Expand Up @@ -2135,6 +2135,11 @@ acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf"
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==

add@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/add/-/add-2.0.6.tgz#248f0a9f6e5a528ef2295dbeec30532130ae2235"
integrity sha512-j5QzrmsokwWWp6kUcJQySpbG+xfOBqqKnup3OIk1pz+kB/80SLorZ9V8zHFLO92Lcd+hbvq8bT+zOGoPkmBV0Q==

agent-base@6:
version "6.0.2"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
Expand Down Expand Up @@ -5073,10 +5078,10 @@ joi@^17.6.0:
"@sideway/formula" "^3.0.0"
"@sideway/pinpoint" "^2.0.0"

jotai@^1.6.4:
version "1.6.4"
resolved "https://registry.yarnpkg.com/jotai/-/jotai-1.6.4.tgz#4d9904362c53c4293d32e21fb358d3de34b82912"
integrity sha512-XC0ExLhdE6FEBdIjKTe6kMlHaAUV/QiwN7vZond76gNr/WdcdonJOEW79+5t8u38sR41bJXi26B1dRi7cCRz9A==
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-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -7896,6 +7901,11 @@ yargs@^16.2.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"

yarn@^1.22.19:
version "1.22.19"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.19.tgz#4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
integrity sha512-/0V5q0WbslqnwP91tirOvldvYISzaqhClxzyUKXYxs07yUILIs5jx/k6CFe8bvKSkds5w+eiOqta39Wk3WxdcQ==

yup@^0.32.11:
version "0.32.11"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.32.11.tgz#d67fb83eefa4698607982e63f7ca4c5ed3cf18c5"
Expand Down