Tarjima qoshish uchun havola boyicha o'tib Pull Request oching (havolaga o'tish).
Standart til uchun tarkibni ko'rsatadi.
import { useGate } from "effector-vue/composition";useGate introduced in effector-vue 21.1.0
Methods
useGate(Gate, props?, options?)
Opens a Gate for the lifetime of the component or the effect scope that called it, and keeps Gate.state in sync with props. Designed for Vue 3.
Formulae
useGate(Gate: Gate<Props>, props?: MaybeRefOrGetter<Props>, options?: ScopeOptions): void;Arguments
Gate<Props>(Gate)props?(Props | Ref<Props> | () => Props): a value, a ref or a getter. A ref, a getter and areactive()object keepGate.statein sync. A value that is not reactive is read when the gate opens and when it closes.options?(Object):{ scope, forceScope }, see EffectorScopePlugin. Theopen,closeandsetevents of the gate are called in the resolved scope.
options argument introduced in effector-vue 23.3.0
props accepts a value or a ref since effector-vue 23.3.0. Before that it accepted a getter only
The events of the gate are called in the resolved scope since effector-vue 23.3.0. Before that they were called outside of the scope of the plugin
Returns
(void)
Lifetime
- In a component the gate opens on mount and closes when the component unmounts. Deactivation by
<KeepAlive>keeps the gate open, only unmounting closes it. - Outside of a component the gate opens right away and closes when the surrounding effect scope is stopped,
effectScope()for example. - With no active effect scope there is nothing to close the gate, so the call warns and leaves it open.
app.runWithContext()gives an injection context and no effect scope, so run it insideeffectScope().
Closing with the effect scope since effector-vue 23.3.0. Before that the gate worked only inside a component
Order of the events
open before set since effector-vue 23.3.0. Before that set ran first, while the gate was closed
open is called first, with the current props, and the gate samples them into set on its own. Later changes of the props reach set after that. Gate.state is not written while the gate is closed, and a mount runs one set:
import { sample } from "effector";import { PageGate, loadPageFx } from "./model";
sample({ clock: PageGate.open, target: loadPageFx }); // gets the props of the mountServer-side rendering
During a server render the gate stays closed: nothing unmounts on the server, so a gate opened there would never be closed, and its state would be serialized into the client. Load the data of a page with onServerPrefetch instead and use the gate on the client. This matches useGate of effector-react.
Since effector-vue 23.3.0 set is not called during a server render either. Before that the props reached Gate.state on the server
Examples
<script setup lang="ts">import { useGate } from "effector-vue/composition";import { PageGate } from "./model";
const props = defineProps<{ id: string }>();
useGate(PageGate, () => ({ id: props.id }));</script>
<template> <div>{{ id }}</div></template>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.