Чтобы добавить перевод, откройте Pull Request по этой ссылке.
Отображается содержимое для языка по умолчанию.
import { useUnit } from "effector-vue/composition";
Bind Stores to Vue reactivity system or, in the case of Events/Effects - bind to current Scope to use in DOM event handlers.
Designed for Vue 3 and Composition API exclusively.
This API can completely replace the following APIs:
In the future, these APIs can be deprecated and removed.
Methods
useUnit(unit)
Arguments
Returns
(Function
): Function to pass to event handlers. Will trigger given unit in current scope
Examples
Basic Usage
// model.js
import { createEvent, createStore, fork } from "effector";
const incremented = createEvent();
const $count = createStore(0);
$count.on(incremented, (count) => count + 1);
// App.vue
<script setup>
import { useUnit } from "effector-vue/composition";
import { incremented, $count } from "./model.js";
const onClick = useUnit(incremented);
</script>
<template>
<button @click="onClick">increment</button>
</template>
useUnit($store)
Arguments
$store
(Store): Store which will be bound to Vue reactivity system
Returns
Reactive value of given Store
Examples
Basic Usage
// model.js
import { createEvent, createStore, fork } from "effector";
const incremented = createEvent();
const $count = createStore(0);
$count.on(incremented, (count) => count + 1);
// App.vue
<script setup>
import { useUnit } from "effector-vue/composition";
import { $count } from "./model.js";
const count = useUnit($count);
</script>
<template>
<p>Count: {{ count }}</p>
</template>
useUnit(shape)
Arguments
shape
Object or array of (Events or Effects or Stores): Every unit will be processed byuseUnit
and returned as a reactive value in case of Store or as a function to pass to event handlers in case of Event or Effect.
Returns
(Object or Array):
- if Event or Effect: functions with the same names or keys as argument to pass to event handlers. Will trigger given unit in current Scope.
- if Store: reactive value of given Store with the same names or keys as argument.
Examples
Basic Usage
// model.js
import { createEvent, createStore, fork } from "effector";
const incremented = createEvent();
const $count = createStore(0);
$count.on(incremented, (count) => count + 1);
// App.vue
<script setup>
import { useUnit } from "effector-vue/composition";
import { $count, incremented } from "./model.js";
const { count, handleClick } = useUnit({ count: $count, handleClick: incremented });
</script>
<template>
<p>Count: {{ count }}</p>
<button @click="handleClick">increment</button>
</template>
Документация на английском языке - самая актуальная, поскольку её пишет и обновляет команда effector. Перевод документации на другие языки осуществляется сообществом по мере наличия сил и желания.
Помните, что переведенные статьи могут быть неактуальными, поэтому для получения наиболее точной и актуальной информации рекомендуем использовать оригинальную англоязычную версию документации.