@pravosleva/reactive-engine 1.2.1-beta → 1.2.2-beta
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.
- package/README.md +117 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,34 @@ A lightweight, type-safe reactive engine built with TypeScript, featuring Depend
|
|
|
5
5
|
- 🇬🇧 [In English](https://pravosleva.pro/reactive-engine/en)
|
|
6
6
|
- 🇷🇺 [In Russian](https://pravosleva.pro/reactive-engine)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
## 🎯 What Problems This Library Solves
|
|
10
|
+
|
|
11
|
+
When building large-scale React applications, developers constantly run into architectural bottlenecks imposed by built-in state tools. `@pravosleva/reactive-engine` is designed to elegantly solve the following pain points:
|
|
12
|
+
|
|
13
|
+
1. **Unnecessary Over-Rendering:**
|
|
14
|
+
> * *The Problem:* React Context API and traditional immutability-based stores (Redux/Zustand) force all components reading from that state slice to re-render whenever even a single deeply nested property changes.
|
|
15
|
+
> * *The Solution:* Fine-grained reactivity. Components micro-subscribe only to the specific primitive signals they display. State mutations update strictly the necessary DOM nodes.
|
|
16
|
+
|
|
17
|
+
2. **UI Tearing and Lags in React 18+:**
|
|
18
|
+
> * *The Problem:* Under React Concurrent Mode, standard external state managers can lead to UI tearing, where different parts of the screen temporarily display asynchronous, mismatching data.
|
|
19
|
+
> * *The Solution:* The `useReactiveValue` hook is built on top of native `useSyncExternalStore`. This ensures absolute cross-component synchronization, shielding your interface from glitches and tearing.
|
|
20
|
+
|
|
21
|
+
3. **Expensive CPU Re-calculations:**
|
|
22
|
+
> * *The Problem:* Heavy array filtration, sorting, or data analytics functions trigger re-evaluations on every parent re-render or whenever unrelated props shift.
|
|
23
|
+
> * *The Solution:* Lazy `Computed` properties with O(1) computation caching. The logic evaluates *only* when its underlying dependency signals change.
|
|
24
|
+
|
|
25
|
+
4. **Network Request Flooding (Race Conditions):**
|
|
26
|
+
> * *The Problem:* A user rapidly clicking through catalog filters or pagination options spawns cascades of overlapping network requests. An older, slower request might resolve *after* a newer one, overwriting fresh data (Race Condition).
|
|
27
|
+
> * *The Solution:* The `Resource` utility automatically orchestrates native `AbortController` instances. Whenever dependency signals change, the previous pending fetch request is instantly cancelled at the browser's system level.
|
|
28
|
+
|
|
29
|
+
5. **Cascading UI Updates (Render Cascades):**
|
|
30
|
+
> * *The Problem:* Updating 3–4 connected state parameters inside a single event handler prompts 3–4 sequential UI update ticks, clogging the Event Loop.
|
|
31
|
+
> * *The Solution:* 100% out-of-the-box automatic batching. The engine bundles all consecutive synchronous and asynchronous modifications into a single microtask, triggering exactly 1 final unified re-render.
|
|
32
|
+
|
|
33
|
+
6. **Memory Leaks in Dynamic Architectures:**
|
|
34
|
+
> * *The Problem:* Dynamically instantiating computed properties (e.g., dynamically filtering an active tab) accumulates abandoned reactive effects in memory that continue to listen to global state updates forever.
|
|
35
|
+
> * *The Solution:* Built-in memory cleanup and computation memoization inside the core engine. The library hooks automatically trigger `.destroy()` on component unmount, seamlessly purging dead reactive effects from RAM.
|
|
9
36
|
|
|
10
37
|
## 📦 Installation
|
|
11
38
|
|
|
@@ -15,8 +42,22 @@ Install the package via your favorite package manager:
|
|
|
15
42
|
yarn add @pravosleva/reactive-engine
|
|
16
43
|
```
|
|
17
44
|
|
|
45
|
+
## `peerDependencies`
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"@angular/core": ">=16.0.0",
|
|
50
|
+
"react": "^18.0.0 || ^19.2.0",
|
|
51
|
+
"react-dom": "^18.0.0 || ^19.2.0",
|
|
52
|
+
"vue": ">=3.2.0"
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## React
|
|
57
|
+
|
|
18
58
|
```tsx
|
|
19
|
-
import { AbstractService
|
|
59
|
+
import { AbstractService } from '@pravosleva/reactive-engine'
|
|
60
|
+
import { ReactiveEngine } from '@pravosleva/reactive-engine/react'
|
|
20
61
|
|
|
21
62
|
class Logic extends AbstractService {
|
|
22
63
|
public counter = this.engine.signal<number>(0, 'example-01:signal:counter');
|
|
@@ -44,30 +85,84 @@ export const Example001 = () => {
|
|
|
44
85
|
}
|
|
45
86
|
```
|
|
46
87
|
|
|
47
|
-
##
|
|
88
|
+
## Vue 3
|
|
48
89
|
|
|
49
|
-
|
|
90
|
+
```vue
|
|
91
|
+
<script setup lang="ts">
|
|
92
|
+
import { AbstractService } from '@pravosleva/reactive-engine'
|
|
93
|
+
import { ReactiveEngine as ReactiveEngine4Vue } from '@pravosleva/reactive-engine/vue'
|
|
50
94
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
> * *The Solution:* Fine-grained reactivity. Components micro-subscribe only to the specific primitive signals they display. State mutations update strictly the necessary DOM nodes.
|
|
95
|
+
class CounterLogic extends AbstractService {
|
|
96
|
+
public counter = this.engine.signal<number>(0, 'vue-example:counter');
|
|
54
97
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
98
|
+
public inc = () => {
|
|
99
|
+
this.counter.value += 1
|
|
100
|
+
}
|
|
101
|
+
}
|
|
58
102
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
103
|
+
const engine = new ReactiveEngine4Vue()
|
|
104
|
+
const logic = engine.inject(CounterLogic)
|
|
105
|
+
const counter = engine.use(logic.counter)
|
|
106
|
+
</script>
|
|
62
107
|
|
|
63
|
-
|
|
64
|
-
>
|
|
65
|
-
>
|
|
108
|
+
<template>
|
|
109
|
+
<div>
|
|
110
|
+
<div>Vue 3 Signal Example</div>
|
|
66
111
|
|
|
67
|
-
|
|
68
|
-
>
|
|
69
|
-
> * *The Solution:* 100% out-of-the-box automatic batching. The engine bundles all consecutive synchronous and asynchronous modifications into a single microtask, triggering exactly 1 final unified re-render.
|
|
112
|
+
<!-- Убираем .value, доверяем автоматическому развертыванию Vue -->
|
|
113
|
+
<code>{{ counter }}</code>
|
|
70
114
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
<div>
|
|
116
|
+
<button @click="logic.inc">
|
|
117
|
+
INC
|
|
118
|
+
</button>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
</template>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Angular
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { Component } from '@angular/core'
|
|
128
|
+
import { AbstractService } from '@pravosleva/reactive-engine'
|
|
129
|
+
import { ReactiveEngine as ReactiveEngine4Angular } from '@pravosleva/reactive-engine/angular'
|
|
130
|
+
|
|
131
|
+
// 1. Описываем изолированную бизнес-логику (Ядро/Сервис) — код 1-в-1 как в React/Vue
|
|
132
|
+
class CounterLogic extends AbstractService {
|
|
133
|
+
public counter = this.engine.signal<number>(0, 'angular-example:counter');
|
|
134
|
+
|
|
135
|
+
public inc = () => {
|
|
136
|
+
this.counter.value += 1;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@Component({
|
|
141
|
+
selector: 'app-counter-example',
|
|
142
|
+
standalone: true,
|
|
143
|
+
// В шаблоне Angular Signals вызываются как функции: counter()
|
|
144
|
+
template: `
|
|
145
|
+
<div class="unit stack2">
|
|
146
|
+
<div class="absoluteUnitLabel">Angular 16+ Signal Example</div>
|
|
147
|
+
<code>{{ counter() }}</code>
|
|
148
|
+
<div class="catSection">
|
|
149
|
+
<button (click)="logic.inc()" class="btn neonBtn neonBtn--primary neonBtn--outlined">
|
|
150
|
+
INC (Angular)
|
|
151
|
+
</button>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
`,
|
|
155
|
+
styleUrls: ['./ui.common.module.scss', './ui.button.module.scss'] // Ваши SCSS стили
|
|
156
|
+
})
|
|
157
|
+
export class AngularCounterComponent {
|
|
158
|
+
// 2. Инициализируем Angular-версию движка
|
|
159
|
+
private engine = new ReactiveEngine4Angular();
|
|
160
|
+
|
|
161
|
+
// 3. Внедряем сервис из DI-контейнера
|
|
162
|
+
public logic = this.engine.inject(CounterLogic);
|
|
163
|
+
|
|
164
|
+
// 4. Превращаем сигнал ядра в нативный Angular Signal через метод .use()
|
|
165
|
+
// Метод inject(DestroyRef) под капотом use() отработает корректно, так как мы находимся в фазе инициализации класса
|
|
166
|
+
public counter = this.engine.use(this.logic.counter);
|
|
167
|
+
}
|
|
168
|
+
```
|