Tarjima qoshish uchun havola boyicha o'tib Pull Request oching (havolaga o'tish).
Standart til uchun tarkibni ko'rsatadi.
import { forward, type Subscription } from "effector";
Method to create connection between units in a declarative way. Send updates from one set of units to another.
Methods
forward({ from, to })
Since effector 23.0.0.
The core team recommends using sample instead of forward
.
Formulae
forward({
from: Unit | Unit[],
to: Unit | Unit[]
}): Subscription
Arguments
from
(Unit | Unit[]): Source of updates. Forward will listen for changes of these units- if an Event is passed,
to
will be triggered on each event trigger and receives event argument - if a Store is passed,
to
will be triggered on each store change and receives new value of the store - if an Effect is passed,
to
will be triggered on each effect call and receives effect parameter - if an array of units is passed,
to
will be triggered when any unit infrom
array is triggered
- if an Event is passed,
to
(Unit | Unit[]): Target for updates.forward
will trigger these units with data fromfrom
Returns
Subscription: Unsubscribe function. It breaks connection between from
and to
. After call, to
will not be triggered anymore.
Arrays of units are supported since effector 20.6.0
Examples
Send store updates to another store
import { createStore, createEvent, forward } from "effector";
const $store = createStore(1);
const event = createEvent();
forward({
from: event,
to: $store,
});
$store.watch((state) => console.log("store changed: ", state));
// => store changed: 1
event(200);
// => store changed: 200
Forward between arrays of units
import { createEvent, forward } from "effector";
const firstSource = createEvent();
const secondSource = createEvent();
const firstTarget = createEvent();
const secondTarget = createEvent();
forward({
from: [firstSource, secondSource],
to: [firstTarget, secondTarget],
});
firstTarget.watch((e) => console.log("first target", e));
secondTarget.watch((e) => console.log("second target", e));
firstSource("A");
// => first target A
// => second target A
secondSource("B");
// => first target B
// => second target B
Ingliz tilidagi hujjatlar eng dolzarb hisoblanadi, chunki u effector guruhi tomonidan yozilgan va yangilanadi. Hujjatlarni boshqa tillarga tarjima qilish jamiyat tomonidan kuch va istaklar mavjud bo'lganda amalga oshiriladi.
Esda tutingki, tarjima qilingan maqolalar yangilanmasligi mumkin, shuning uchun eng aniq va dolzarb ma'lumot uchun hujjatlarning asl inglizcha versiyasidan foydalanishni tavsiya etamiz.