Bu sahifa hali tarjima qilinmagan

Tarjima qoshish uchun havola boyicha o'tib Pull Request oching (havolaga o'tish).

Standart til uchun tarkibni ko'rsatadi.

Scope API

import { type Scope, fork } from "effector";
const scope = fork();

Scope is a fully isolated instance of application. The primary purpose of scope includes SSR (Server-Side Rendering) but is not limited to this use case. A Scope contains an independent clone of all units (including connections between them) and basic methods to access them.

scope matters

If you want to get deeper about scopes then check out great article about isolated scopes.
We also have few related guides:

Scope peculiarities

  1. There are a few rules that must be followed to work successfully with scope.
  2. Your scope can be lost to avoid this use scopeBind.

Scope methods

.getState($store)

Returns the value of a store in a given scope:

  • Formula
const scope: Scope;
const $value: Store<T> | StoreWritable<T>;
const value: T = scope.getState($value);
  • Type
scope.getState<T>(store: Store<T>): T;
  • Returns

The value of the store.

  • Examples

Create two instances of an application, trigger events in them, and test the $counter store value in both instances:

import { createStore, createEvent, fork, allSettled } from "effector";
const inc = createEvent();
const dec = createEvent();
const $counter = createStore(0);
$counter.on(inc, (value) => value + 1);
$counter.on(dec, (value) => value - 1);
const scopeA = fork();
const scopeB = fork();
await allSettled(inc, { scope: scopeA });
await allSettled(dec, { scope: scopeB });
console.log($counter.getState()); // => 0
console.log(scopeA.getState($counter)); // => 1
console.log(scopeB.getState($counter)); // => -1

Try it.

Tarjima jamiyat tomonidan qollanilyapti

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.

Hammualliflar