@directive-run/vue

Vue composition API adapter for Directive.
13,087 5
Install
npm install @directive-run/vue
Latest Version:1.35.0
Vue:3
License:(MIT OR Apache-2.0)
Last Updated:Oct 24, 2026
Links: GitHub  ·  npm
Maintainer: jasonwcomes

@directive-run/vue

npm downloads bundle size

Vue 3 composables for Directive. Returns reactive Ref and ShallowRef values that integrate with Vue's reactivity system.

Install

npm install @directive-run/core @directive-run/vue

Quick Start

Define a module in a shared file, then use it in any component:

// system.ts
import { createModule, createSystem, t } from "@directive-run/core";

const counter = createModule("counter", {
  schema: {
    facts: { count: t.number() },
    derivations: { doubled: t.number() },
    events: { increment: {}, decrement: {} },
    requirements: {},
  },
  init: (facts) => {
    facts.count = 0;
  },
  derive: {
    doubled: (facts) => facts.count * 2,
  },
  events: {
    increment: (facts) => { facts.count += 1; },
    decrement: (facts) => { facts.count -= 1; },
  },
});

export const system = createSystem({ module: counter });
system.start();
<!-- Counter.vue -->
<script setup lang="ts">
import { useFact, useDerived, useEvents } from "@directive-run/vue";
import { system } from "./system";

const count = useFact(system, "count");
const doubled = useDerived(system, "doubled");
const events = useEvents(system);
</script>

<template>
  <p>Count: {{ count }} (doubled: {{ doubled }})</p>
  <button @click="events.increment()">+</button>
  <button @click="events.decrement()">&minus;</button>
</template>

useSelector

Auto-tracking selector over facts and derivations. Returns a Ref that updates when accessed keys change:

<script setup lang="ts">
import { useSelector } from "@directive-run/vue";
import { system } from "./system";

const label = useSelector(system, (state) => {
  return state.count > 10 ? "High" : "Low";
});
</script>

<template>
  <span>{{ label }}</span>
</template>

API Reference

Core Composables

Composable Return Type Description
useFact(system, key) Ref<T> Subscribe to a single fact value
useFact(system, [keys]) ShallowRef<Pick<Facts, K>> Subscribe to multiple facts
useDerived(system, key) Ref<T> Subscribe to a single derivation
useDerived(system, [keys]) ShallowRef<Pick<Derivations, K>> Subscribe to multiple derivations
useSelector(system, fn) Ref<R> Auto-tracking selector with optional equality function
useEvents(system) Events Events dispatcher
useDispatch(system) (event) => void Low-level dispatch function

Advanced Composables

Composable Return Type Description
useWatch(system, key, cb) void Side-effect on fact or derivation change
useInspect(system) ShallowRef<InspectState> Consolidated system state (isSettled, unmet, inflight)
useRequirementStatus(plugin, type) ShallowRef<RequirementTypeStatus> Requirement loading/error state
useExplain(system, reqId) Ref<string | null> Human-readable requirement explanation
useConstraintStatus(system) ComputedRef<ConstraintInfo[]> All constraint states
useOptimisticUpdate(system) { mutate, isPending: Ref, error: Ref, rollback } Optimistic mutation with auto-rollback
useHistory(system) ShallowRef<HistoryState | null> Undo/redo navigation

Vue-Specific

Export Description
useDirective(module, config?) Scoped system with lifecycle (auto-start/destroy)
createTypedHooks() Factory for pre-typed composables
shallowEqual Shallow equality helper for selectors

Peer Dependencies

  • vue >= 3
  • @directive-run/core

Documentation

License

MIT

Related Packages

@favorodera/use-promise

A Vue composable for managing async operations with reactive state, cancellation...

1,225 1
@illinois-grad/vue-useful-api

Vue 3 API integration utilities with reactive state management for Graduate Coll...

5,456 0
reactive-vscode

Develop VSCode extension with Vue Reactivity API

107,143 825
@kontsedal/olas-vue

Olas Vue adapter — olasPlugin, useRoot, useValue, useQuery, useInfiniteQuery, us...

450 0
@composy/store-vue

Vue 3 状态管理适配器 - 基于 Pinia 的增强版状态管理解决方案

0

Version History

Version Released Vue License
1.35.0 >=3 (MIT OR Apache-2.0)
1.34.1 >=3 (MIT OR Apache-2.0)
1.33.1 >=3 (MIT OR Apache-2.0)
1.33.0 >=3 (MIT OR Apache-2.0)
1.32.0 >=3 (MIT OR Apache-2.0)