@tramvai/state 1.50.1 → 1.50.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +32 -20
  2. package/package.json +2 -2
  3. package/README.en.md +0 -53
package/README.md CHANGED
@@ -1,37 +1,49 @@
1
1
  # State
2
2
 
3
- **State** - встроенная в `tramvai` библиотека для управления состоянием приложения.
3
+ **State** is a library built into `tramvai` for managing application state.
4
4
 
5
- ## Особенности
5
+ ## Peculiarities
6
6
 
7
- - Redux-like стейт-менеджер
8
- - Встроенная библиотека, похожая на [redux-act](https://github.com/pauldijou/redux-act), для уменьшения boilerplate кода
9
- - Содержит привязки к `react` компонентам, такие как `connect` и `useSelector`
10
- - Динамическая инициализация редьюсеров. Можно в любое время зарегистрировать редьюсер или сгенерировать новый.
11
- - Точечные подписки на изменения состояний редьюсеров. При изменении данных повторно пересчитываются только затронутые `connect` и `useSelector`, а не все.
12
- - Поддержка SSR режима.
7
+ - Redux-like state manager
8
+ - Built-in library similar to [redux-act](https://github.com/pauldijou/redux-act) to reduce boilerplate code
9
+ - Contains bindings to `react` components such as `connect` and `useSelector`
10
+ - Dynamic initialization of reducers. You can register a reducer at any time or generate a new one.
11
+ - Point subscriptions to changes in the states of reducers. When data changes, only the affected `connect` and `useSelector` are recalculated, not everything.
12
+ - Support for SSR mode.
13
13
 
14
- ## Основные концепции
14
+ ## Basic concepts
15
15
 
16
- - Стор - Класс, который содержит состояние всех редьюсеров, подписки на изменения и создается для каждого клиента
17
- - Редьюсеры - сущности в которых мы описываем то, как будут храниться и преобразовываться данные
18
- - Эвенты - события, с помощью которых можно изменить состояния редьюсеров
19
- - Экшены - функции, которые позволяют выполнять сайд-эффекты и обновлять данные в сторе. Похожи на `redux-thunk`
16
+ - Store - A class that contains the state of all reducers, change subscriptions and is created for each client
17
+ - Reducers - entities in which we describe how data will be stored and transformed
18
+ - Events - events with which you can change the states of reducers
19
+ - Actions - functions that allow you to perform side effects and update data in the store. Similar to `redux-thunk`
20
20
 
21
- ## Рекомендации
21
+ ## Recommendations
22
22
 
23
- - Нельзя мутировать данные в редьюсерах. Иначе из-за различных оптимизаций не произойдёт оповещение подписчиков о изменениях
24
- - Инициализировать редьюсеры как можно раньше и до его использования. Иначе при вызове `dispatch(userLoadInformation())` редьюсер еще не будет отслеживать события и не получит данные.
25
- - Не хранить статичные данные в сторах. Так как эти данные будут передаваться с сервера на клиент, то данные задублируются. Лучше вынести в константы.
26
- - Разбивать на небольшие редьюсеры. Иначе у нас появляется огромный редьюсер, который содержит большое количество информации и любые изменения будут вызывать перерасчеты для большого количества компонентов.
23
+ - You cannot mutate data in reducers. Otherwise, due to various optimizations, subscribers will not be notified about the changes.
24
+ - Initialize reducers as early as possible and before using it. Otherwise, when calling `dispatch(userLoadInformation())`, the reducer will not yet track events and will not receive data.
25
+ - Do not store static data in stores. Since this data will be transferred from the server to the client, the data will be duplicated. Better to put in constants.
26
+ - Break into small reducers. Otherwise, we have a huge reducer that contains a large amount of information and any changes will cause recalculations for a large number of components.
27
27
 
28
- ## Установка
28
+ ## Installation
29
29
 
30
30
  ```bash
31
31
  npm i --save @tramvai/state
32
32
  ```
33
33
 
34
- ## Базовый пример
34
+ ## Explanation
35
+
36
+ ### schedule
37
+
38
+ Some of the functions that deals with state (e.g. connect, useStoreSelector) will use some sort of batching (using requestAnimationFrame or SetTimeout) in browser. So any updates to state are not synchronous and happens after some time.
39
+
40
+ Most of the time this is not an issue or noticeable thing. But in tests that might be unexpected.
41
+
42
+ > In order to take into account scheduling while testing use [waitRaf helper](references/test/test-jsdom.md#waitraf) or [act from test-unit](references/test/test-unit.md#act)
43
+
44
+ ## How to
45
+
46
+ ### Basic example
35
47
 
36
48
  ```tsx
37
49
  import { createReducer, createEvent } from '@tramvai/state';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/state",
3
- "version": "1.50.1",
3
+ "version": "1.50.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@tinkoff/react-hooks": "0.0.23",
22
22
  "@tinkoff/utils": "^2.1.2",
23
- "@tramvai/types-actions-state-context": "1.50.1",
23
+ "@tramvai/types-actions-state-context": "1.50.2",
24
24
  "@types/hoist-non-react-statics": "^3.3.1",
25
25
  "invariant": "^2.2.4",
26
26
  "react-is": ">=17",
package/README.en.md DELETED
@@ -1,53 +0,0 @@
1
- # State
2
-
3
- **State** is a library built into `tramvai` for managing application state.
4
-
5
- ## Peculiarities
6
-
7
- - Redux-like state manager
8
- - Built-in library similar to [redux-act](https://github.com/pauldijou/redux-act) to reduce boilerplate code
9
- - Contains bindings to `react` components such as `connect` and `useSelector`
10
- - Dynamic initialization of reducers. You can register a reducer at any time or generate a new one.
11
- - Point subscriptions to changes in the states of reducers. When data changes, only the affected `connect` and `useSelector` are recalculated, not everything.
12
- - Support for SSR mode.
13
-
14
- ## Basic concepts
15
-
16
- - Store - A class that contains the state of all reducers, change subscriptions and is created for each client
17
- - Reducers - entities in which we describe how data will be stored and transformed
18
- - Events - events with which you can change the states of reducers
19
- - Actions - functions that allow you to perform side effects and update data in the store. Similar to `redux-thunk`
20
-
21
- ## Recommendations
22
-
23
- - You cannot mutate data in reducers. Otherwise, due to various optimizations, subscribers will not be notified about the changes.
24
- - Initialize reducers as early as possible and before using it. Otherwise, when calling `dispatch(userLoadInformation())`, the reducer will not yet track events and will not receive data.
25
- - Do not store static data in stores. Since this data will be transferred from the server to the client, the data will be duplicated. Better to put in constants.
26
- - Break into small reducers. Otherwise, we have a huge reducer that contains a large amount of information and any changes will cause recalculations for a large number of components.
27
-
28
- ## Installation
29
-
30
- ```bash
31
- npm i --save @tramvai/state
32
- ```
33
-
34
- ## Basic example
35
-
36
- ```tsx
37
- import { createReducer, createEvent } from '@tramvai/state';
38
-
39
- export const userLoadInformation = createEvent('user load information');
40
- export const userAddInformation = createEvent('user add information');
41
-
42
- const userReducer = createReducer('user', {
43
- info: {},
44
- })
45
- .on(userLoadInformation, (state, info) => ({ info }))
46
- .on(userAddInformation, (state, { name, info }) => ({
47
- ...state,
48
- state: {
49
- ...state.info,
50
- [name]: info,
51
- },
52
- }));
53
- ```