Skip to content

Commit aa4256b

Browse files
committed
style: reformat whole code with prettier
1 parent b0bd4a2 commit aa4256b

28 files changed

+4533
-1778
lines changed

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dist-test
2+
./core
3+
node_modules
4+
dist
5+
.idea
6+
.vscode
7+
.husky
8+
.github

.prettierrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"arrowParens": "always",
3-
"printWidth": 80,
3+
"printWidth": 86,
44
"semi": true,
55
"singleQuote": true,
66
"tabWidth": 2,
77
"trailingComma": "all",
8-
"useTabs": false
8+
"useTabs": false,
9+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
10+
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"],
11+
"importOrderSeparation": true,
12+
"importOrderSortSpecifiers": true,
13+
"importOrderCaseInsensitive": true
914
}

Readme.md

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ It's the API design that, using the classic HOC pattern, allows you to write Rea
2121
Let's take a look at typical example of hooks usage:
2222

2323
```tsx
24-
import { Input, Button, FormContainer, ErrorMessage } from "ui-lib"
25-
import { useUnit } from "effector-react"
24+
import { useUnit } from 'effector-react';
25+
import { Button, ErrorMessage, FormContainer, Input } from 'ui-lib';
2626

27-
import * as model from "./form-model"
27+
import * as model from './form-model';
2828

2929
export function UserForm() {
3030
const {
@@ -42,16 +42,16 @@ export function UserForm() {
4242
lastName: model.lastNameChanged,
4343
formSubmitted: model.formSubmitted,
4444
error: model.$error,
45-
})
45+
});
4646

4747
return (
4848
<FormContainer>
4949
<Input value={name} onChange={nameChanged} />
5050
<Input value={lastName} onChange={lastNameChanged} />
51-
{error && (<ErrorMessage text={error} />)}
51+
{error && <ErrorMessage text={error} />}
5252
<Button type="submit" disabled={!formValid} onClick={formSubmitted} />
5353
</FormContainer>
54-
)
54+
);
5555
}
5656
```
5757

@@ -63,15 +63,12 @@ This can be fixed by moving the subscriptions further down the component tree by
6363

6464
```tsx
6565
function UserFormSubmitButton() {
66-
const {
67-
formValid,
68-
formSubmitted,
69-
} = useUnit({
66+
const { formValid, formSubmitted } = useUnit({
7067
formValid: model.$formValid,
71-
formSubmitted: model.formSubmitted
72-
})
68+
formSubmitted: model.formSubmitted,
69+
});
7370

74-
return <Button type="submit" disabled={!formValid} onClick={formSubmitted} />
71+
return <Button type="submit" disabled={!formValid} onClick={formSubmitted} />;
7572
}
7673
```
7774

@@ -84,7 +81,7 @@ Also, in most cases it's not a big problem, since React is pretty fast at diffin
8481
That's where reflect comes to the rescue:
8582

8683
```tsx
87-
import { reflect, variant } from "@effector/reflect"
84+
import { reflect, variant } from '@effector/reflect';
8885

8986
export function UserForm() {
9087
return (
@@ -94,43 +91,43 @@ export function UserForm() {
9491
<Error />
9592
<SubmitButton />
9693
</FormContainer>
97-
)
94+
);
9895
}
9996

10097
const Name = reflect({
10198
view: Input,
10299
bind: {
103100
value: model.$name,
104-
onChange: model.nameChanged
105-
}
106-
})
101+
onChange: model.nameChanged,
102+
},
103+
});
107104

108105
const LastName = reflect({
109106
view: Input,
110107
bind: {
111108
value: model.$lastName,
112-
onChange: model.lastNameChanged
113-
}
114-
})
109+
onChange: model.lastNameChanged,
110+
},
111+
});
115112

116113
const Error = variant({
117114
if: model.$error,
118115
then: reflect({
119116
view: ErrorMessage,
120117
bind: {
121118
text: model.$error,
122-
}
123-
})
124-
})
119+
},
120+
}),
121+
});
125122

126123
const SubmitButton = reflect({
127124
view: Button,
128125
bind: {
129-
type: "submit", // plain values are allowed too!
130-
disabled: model.$formValid.map(valid => !valid),
131-
onClick: model.formSubmitted
132-
}
133-
})
126+
type: 'submit', // plain values are allowed too!
127+
disabled: model.$formValid.map((valid) => !valid),
128+
onClick: model.formSubmitted,
129+
},
130+
});
134131
```
135132

136133
Here we've separated this component into small parts, which were created in a convenient way using `reflect` operators, which is a very simple description of the `props -> values` mapping, which is easier to read and modify.
@@ -171,9 +168,9 @@ Static method to create a component bound to effector stores and events as store
171168

172169
```tsx
173170
// ./user.tsx
174-
import React, { FC, ChangeEvent } from 'react';
175-
import { createEvent, restore } from 'effector';
176171
import { reflect } from '@effector/reflect';
172+
import { createEvent, restore } from 'effector';
173+
import React, { ChangeEvent, FC } from 'react';
177174

178175
// Base components
179176
type InputProps = {
@@ -202,7 +199,7 @@ const Name = reflect({
202199
view: Input,
203200
bind: {
204201
value: $name,
205-
placeholder: "Name",
202+
placeholder: 'Name',
206203
onChange: changeName.prepend(inputChanged),
207204
},
208205
});
@@ -211,7 +208,7 @@ const Age = reflect({
211208
view: Input,
212209
bind: {
213210
value: $age,
214-
placeholder: "Age",
211+
placeholder: 'Age',
215212
onChange: changeAge.prepend(parseInt).prepend(inputChanged),
216213
},
217214
});
@@ -253,10 +250,10 @@ Method allows to change component based on value in `$typeSelector`. Optional `b
253250
When `Field` is rendered it checks for `$fieldType` value, selects the appropriate component from `cases` and bound props to it.
254251

255252
```tsx
256-
import React from 'react';
257-
import { createStore, createEvent } from 'effector';
258253
import { variant } from '@effector/reflect';
259-
import { TextInput, Range, DateSelector } from '@org/ui-lib';
254+
import { DateSelector, Range, TextInput } from '@org/ui-lib';
255+
import { createEvent, createStore } from 'effector';
256+
import React from 'react';
260257

261258
const $fieldType = createStore<'date' | 'number' | 'string'>('string');
262259

@@ -315,7 +312,7 @@ const Items: React.FC = list({
315312
mapItem: {
316313
propName: (item: Item, index: number) => propValue, // maps array store item to View props
317314
},
318-
getKey: (item: Item) => React.Key // optional, will use index by default
315+
getKey: (item: Item) => React.Key, // optional, will use index by default
319316
});
320317
```
321318

@@ -337,9 +334,9 @@ Method creates component, which renders list of `view` components based on items
337334
#### Example
338335

339336
```tsx
340-
import React from 'react';
341-
import { createStore, createEvent } from 'effector';
342337
import { list } from '@effector/reflect';
338+
import { createEvent, createStore } from 'effector';
339+
import React from 'react';
343340

344341
const $color = createStore('red');
345342

@@ -382,8 +379,8 @@ Method for creating reflect a view. So you can create a UI kit by views and use
382379

383380
```tsx
384381
// ./ui.tsx
385-
import React, { FC, useCallback, ChangeEvent, MouseEvent } from 'react';
386382
import { createReflect } from '@effector/reflect';
383+
import React, { ChangeEvent, FC, MouseEvent, useCallback } from 'react';
387384

388385
// Input
389386
type InputProps = {
@@ -416,10 +413,10 @@ export const reflectButton = createReflect(Button);
416413

417414
```tsx
418415
// ./user.tsx
419-
import React, { FC } from 'react';
420416
import { createEvent, restore } from 'effector';
417+
import React, { FC } from 'react';
421418

422-
import { reflectInput, reflectButton } from './ui';
419+
import { reflectButton, reflectInput } from './ui';
423420

424421
// Model
425422
const changeName = createEvent<string>();
@@ -464,9 +461,9 @@ Hooks is an object passed to `variant()` or `match()` with properties `mounted`
464461
#### Example
465462

466463
```tsx
467-
import { createStore, createEvent } from 'effector';
468464
import { reflect, variant } from '@effector/reflect';
469-
import { TextInput, Range } from '@org/my-ui';
465+
import { Range, TextInput } from '@org/my-ui';
466+
import { createEvent, createStore } from 'effector';
470467

471468
const $type = createStore<'text' | 'range'>('text');
472469
const $value = createStore('');
@@ -493,10 +490,8 @@ const Field = variant({
493490

494491
When `Field` is mounted, `fieldMounted` and `rangeMounted` would be called.
495492

496-
497493
### SSR and tests via Fork API
498494

499-
500495
Since [effector-react 22.5.0](https://github.com/effector/effector/releases/tag/effector-react%4022.5.0) it is no longer necessary to use `@effector/reflect/ssr` due to isomorphic nature of `effector-react` hooks after this release, you can just use `@effector/reflect` main imports.
501496

502497
Just add `Provider` from `effector-react` to your app root, and you are good to go.
@@ -507,7 +502,7 @@ Also for this case you need to use `event.prepend(params => params.something)` i
507502

508503
```tsx
509504
// ./ui.tsx
510-
import React, { FC, useCallback, ChangeEvent, MouseEvent } from 'react';
505+
import React, { ChangeEvent, FC, MouseEvent, useCallback } from 'react';
511506

512507
// Input
513508
type InputProps = {
@@ -522,24 +517,24 @@ const Input: FC<InputProps> = ({ value, onChange }) => {
522517

523518
```tsx
524519
// ./app.tsx
525-
import React, { FC } from 'react';
526-
import { createEvent, restore, sample, Scope } from 'effector';
527520
import { reflect } from '@effector/reflect';
521+
import { createEvent, restore, sample, Scope } from 'effector';
528522
import { Provider } from 'effector-react';
523+
import React, { FC } from 'react';
529524

530525
import { Input } from './ui';
531526

532527
// Model
533-
export const appStarted = createEvent<{name: string}>()
528+
export const appStarted = createEvent<{ name: string }>();
534529

535530
const changeName = createEvent<string>();
536531
const $name = restore(changeName, '');
537532

538533
sample({
539534
clock: appStarted,
540-
fn: ctx => ctx.name,
535+
fn: (ctx) => ctx.name,
541536
target: changeName,
542-
})
537+
});
543538

544539
// Component
545540
const Name = reflect({
@@ -561,7 +556,7 @@ export const App: FC<{ scope: Scope }> = ({ scope }) => {
561556

562557
```tsx
563558
// ./server.tsx
564-
import { fork, serialize, allSettled } from 'effector';
559+
import { allSettled, fork, serialize } from 'effector';
565560

566561
import { App, appStarted } from './app';
567562

@@ -572,7 +567,7 @@ const render = async (reqCtx) => {
572567
scope: serverScope,
573568
params: {
574569
name: reqCtx.cookies.name,
575-
}
570+
},
576571
});
577572

578573
const content = renderToString(<App scope={serverScope} />);
@@ -592,15 +587,15 @@ const render = async (reqCtx) => {
592587
```tsx
593588
// client.tsx
594589
import { fork } from 'effector';
595-
import { hydrateRoot } from 'react-dom/client'
590+
import { hydrateRoot } from 'react-dom/client';
596591

597592
import { App, appStarted } from './app';
598593

599594
const clientScope = fork({
600-
values: window.__initialState__
601-
})
595+
values: window.__initialState__,
596+
});
602597

603-
hydrateRoot(document.body, <App scope={clientScope} />)
598+
hydrateRoot(document.body, <App scope={clientScope} />);
604599
```
605600

606601
## Release process

babel.config.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"presets": [
3-
"@babel/preset-env",
4-
"@babel/preset-typescript",
5-
"@babel/preset-react"
6-
],
2+
"presets": ["@babel/preset-env", "@babel/preset-typescript", "@babel/preset-react"],
73
"plugins": ["@babel/plugin-transform-runtime"]
84
}

dist-test/no-ssr/create-reflect.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React, { FC, InputHTMLAttributes } from 'react';
2-
import { createStore, createEvent, restore, createEffect } from 'effector';
3-
import { act } from 'react-dom/test-utils';
4-
1+
import { createReflect } from '../../reflect.cjs';
52
import { render } from '@testing-library/react';
63
import userEvent from '@testing-library/user-event';
7-
8-
import { createReflect } from '../../reflect.cjs';
4+
import { createEffect, createEvent, createStore, restore } from 'effector';
5+
import React, { FC, InputHTMLAttributes } from 'react';
6+
import { act } from 'react-dom/test-utils';
97

108
// Example1 (InputCustom)
119
const InputCustom: FC<{
@@ -158,8 +156,8 @@ describe('hooks', () => {
158156
true,
159157
);
160158

161-
const Branch = createReflect<{ visible: boolean }>(
162-
({ visible, children }) => (visible ? <>{children}</> : null),
159+
const Branch = createReflect<{ visible: boolean }>(({ visible, children }) =>
160+
visible ? <>{children}</> : null,
163161
)({
164162
visible: $visible,
165163
});

dist-test/no-ssr/reflect.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React, { FC, InputHTMLAttributes, ChangeEvent } from 'react';
2-
import { createStore, createEvent, restore, createEffect } from 'effector';
3-
import { act } from 'react-dom/test-utils';
4-
1+
import { reflect } from '../../reflect.cjs';
52
import { render } from '@testing-library/react';
63
import userEvent from '@testing-library/user-event';
7-
8-
import { reflect } from '../../reflect.cjs';
4+
import { createEffect, createEvent, createStore, restore } from 'effector';
5+
import React, { ChangeEvent, FC, InputHTMLAttributes } from 'react';
6+
import { act } from 'react-dom/test-utils';
97

108
// Example1 (InputCustom)
119
const InputCustom: FC<{

0 commit comments

Comments
 (0)