Index of every page on this site: llms.txt
All skills
vuejs-ai avatar

/create-adaptable-composable

@198f0cd official
by Vue AIvuejs-ai/skills3.4k stars
199
Run it yourself

Create a library-grade Vue composable that accepts maybe-reactive inputs (MaybeRef / MaybeRefOrGetter) so callers can pass a plain value, ref, or getter. Normalize inputs with toValue()/toRef() inside reactive effects (watch/watchEffect) to keep behavior predictable and reactive. Use this skill when user asks for creating adaptable or reusable composables.

Use this Skill: https://skilld.dev/gh/vuejs-ai/skills/create-adaptable-composable

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈97 tokens for metadata: the name and description. ≈529 when used: this file.

Description uses 4.9% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈388 characters, or 4.9%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Create Adaptable Composable

Adaptable composables are reusable functions that can accept both reactive and non-reactive inputs. This allows developers to use the composable in a variety of contexts without worrying about the reactivity of the inputs.

Steps to design an adaptable composable in Vue.js:

  1. Confirm the composable's purpose and API design and expected inputs/outputs.
  2. Identify inputs params that should be reactive (MaybeRef / MaybeRefOrGetter).
  3. Use toValue() or toRef() to normalize inputs inside reactive effects.
  4. Implement the core logic of the composable using Vue's reactivity APIs.

Core Type Concepts

Type Utilities

/**
 * value or writable ref (value/ref/shallowRef/writable computed)
 */
export type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>;

/**
 * MaybeRef<T> + ComputedRef<T> + () => T
 */
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T);

Policy and Rules

  • Read-only, computed-friendly input: use MaybeRefOrGetter
  • Needs to be writable / two-way input: use MaybeRef
  • Parameter might be a function value (callback/predicate/comparator): do not use MaybeRefOrGetter, or you may accidentally invoke it as a getter.
  • DOM/Element targets: if you want computed/derived targets, use MaybeRefOrGetter.

When MaybeRefOrGetter or MaybeRef is used:

  • resolve reactive value using toRef() (e.g. watcher source)
  • resolve non-reactive value using toValue()

Examples

Adaptable useDocumentTitle Composable: read-only title parameter

import { watch, toRef } from 'vue'
import type { MaybeRefOrGetter } from 'vue'

export function useDocumentTitle(title: MaybeRefOrGetter<string>) {
  watch(toRef(title), (t) => {
    document.title = t
  }, { immediate: true })
}

Adaptable useCounter Composable: two-way writable count parameter

import { watch, toRef } from 'vue'
import type { MaybeRef } from 'vue'

function useCounter(count: MaybeRef<number>) {
  const countRef = toRef(count)
  function add() {
    countRef.value++
  }
  return { add }
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides standard architectural patterns and code templates for creating reactive Vue 3 composables. It contains no malicious code, suspicious dependencies, or data exfiltration risks.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer8mo

    1 file scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 198f0cd. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 10 months ago
metadata
{
  "author": "github.com/vuejs-ai",
  "version": "17.0.0"
}
compatibility
Requires Vue 3 (or above) or Nuxt 3 (or above) project

README badge

README badge for vuejs-ai/skills/create-adaptable-composable

Teaches how to write Vue 3 composables that accept both reactive and non-reactive inputs (plain values, refs, or getters) using MaybeRef and MaybeRefOrGetter types. Use this skill when designing library-grade composables that need to work flexibly across different caller contexts.

Generated from the current SKILL.md.

Does this skill work with Vue 2?
No. This skill requires Vue 3 or above (or Nuxt 3 or above). MaybeRef and MaybeRefOrGetter are Vue 3 composition API utilities.
When should I use MaybeRef vs MaybeRefOrGetter?
Use MaybeRefOrGetter for read-only inputs where the caller might pass a plain value, ref, computed ref, or getter function. Use MaybeRef when the input needs to be writable (two-way). Never use MaybeRefOrGetter if the parameter is a callback or predicate, since it may be invoked as a getter.
How do I resolve MaybeRef or MaybeRefOrGetter inputs inside effects?
Use toRef() to normalize the input as a reactive source for watchers, and toValue() to extract the current value synchronously outside of effects.
Can I use MaybeRefOrGetter for DOM element targets?
Yes. Use MaybeRefOrGetter for DOM/Element targets if you want to support computed or derived target references; this allows callers to pass plain elements, refs, or getters.

Generated from the current SKILL.md. These answers refresh after source changes.