Skip to content

Composables Reference

Vue Composition API functions for state and logic.

Overview

Composables encapsulate reactive state and business logic, keeping components clean and focused on UI.

javascript
// Usage pattern
import { useComposable } from '../../composables/feature/useComposable.js'

const { data, loading, error, fetchData } = useComposable()

Authentication

useNostrAuth

Handles Nostr identity and authentication.

Location: src/composables/auth/useNostrAuth.js

Returns:

PropertyTypeDescription
pubkeyRef<String>User's public key
profileRef<Object>User profile data
isConnectedRef<Boolean>Connection status
connectFunctionConnect identity
disconnectFunctionDisconnect

Usage:

javascript
import { useNostrAuth } from '../../composables/auth/useNostrAuth.js'

const { pubkey, profile, isConnected, connect } = useNostrAuth()

async function handleConnect() {
  await connect()
  console.log('Connected as:', pubkey.value)
}

Wallet

useLightningNetwork

Manages Lightning wallet via NWC.

Location: src/composables/wallet/useLightningNetwork.js

Returns:

PropertyTypeDescription
balanceRef<Number>Wallet balance in sats
isConnectedRef<Boolean>NWC connection status
loadingRef<Boolean>Loading state
connectFunctionConnect with NWC URL
disconnectFunctionDisconnect wallet
sendPaymentFunctionSend Lightning payment
createInvoiceFunctionGenerate invoice

Usage:

javascript
import { useLightningNetwork } from '../../composables/wallet/useLightningNetwork.js'

const { balance, isConnected, connect, sendPayment } = useLightningNetwork()

async function connectWallet(nwcUrl) {
  await connect(nwcUrl)
}

async function pay(invoice) {
  const result = await sendPayment(invoice)
  return result
}

Content

useContent

Manages content creation and retrieval.

Location: src/composables/content/useContent.js

Returns:

PropertyTypeDescription
contentRef<Array>User's content
loadingRef<Boolean>Loading state
fetchContentFunctionLoad content
publishNoteFunctionPublish short note
publishArticleFunctionPublish long-form

useNostrLongForm

Long-form article operations (NIP-23).

Location: src/composables/content/useNostrLongForm.js

Returns:

PropertyTypeDescription
articlesRef<Array>User's articles
publishFunctionPublish article
updateFunctionUpdate article
deleteFunctionDelete article

useContentZaps

Track zaps on content.

Location: src/composables/content/useContentZaps.js

Returns:

PropertyTypeDescription
zapsPerContentRef<Map>Zaps by content ID
totalZapsComputedTotal zap count
totalSatsComputedTotal sats earned

Audience

useAudience

Audience analytics and data.

Location: src/composables/audience/useAudience.js

Returns:

PropertyTypeDescription
followersRef<Array>Follower list
followerCountComputedTotal followers
recentFollowersComputedRecent follows
fetchAudienceFunctionLoad data

useFollowLists

Manage follow lists.

Location: src/composables/audience/useFollowLists.js

Returns:

PropertyTypeDescription
listsRef<Array>User's follow lists
createListFunctionCreate new list
updateListFunctionUpdate list
deleteListFunctionDelete list
publishListFunctionPublish to Nostr

Campaigns

useCampaigns

Campaign management.

Location: src/composables/campaigns/useCampaigns.js

Returns:

PropertyTypeDescription
campaignsRef<Array>User's campaigns
activeCampaignsComputedActive only
createCampaignFunctionCreate campaign
updateCampaignFunctionUpdate campaign
deleteCampaignFunctionDelete campaign

Analytics

useEngagementMetrics

Engagement analytics data.

Location: src/composables/analytics/useEngagementMetrics.js

Returns:

PropertyTypeDescription
metricsRef<Object>Engagement data
loadingRef<Boolean>Loading state
periodRef<String>Time period
setPeriodFunctionChange period
fetchMetricsFunctionLoad metrics

Core

useBtcPrice

Bitcoin price tracking.

Location: src/composables/core/useBtcPrice.js

Returns:

PropertyTypeDescription
priceRef<Number>Current BTC/USD
loadingRef<Boolean>Loading state
satsToUsdFunctionConvert sats to USD

useNotifications

In-app notifications.

Location: src/composables/core/useNotifications.js

Returns:

PropertyTypeDescription
notificationsRef<Array>Active notifications
addFunctionAdd notification
removeFunctionRemove notification
clearFunctionClear all

useNostrConnections

Relay connection management.

Location: src/composables/core/useNostrConnections.js

Returns:

PropertyTypeDescription
relaysRef<Array>Connected relays
statusRef<Object>Connection status
addRelayFunctionAdd relay
removeRelayFunctionRemove relay

Social

useBadges

Nostr badges.

Location: src/composables/social/useBadges.js

Returns:

PropertyTypeDescription
badgesRef<Array>User's badges
fetchBadgesFunctionLoad badges

useNostrChat

Chat functionality.

Location: src/composables/social/useNostrChat.js

Returns:

PropertyTypeDescription
messagesRef<Array>Chat messages
sendMessageFunctionSend message
subscribeFunctionSubscribe to chat

Creating Composables

Pattern

javascript
import { ref, computed, onMounted } from 'vue'

export function useFeature() {
  // State
  const data = ref(null)
  const loading = ref(false)
  const error = ref(null)

  // Computed
  const isEmpty = computed(() => !data.value || data.value.length === 0)

  // Methods
  async function fetchData() {
    loading.value = true
    error.value = null
    try {
      data.value = await api.fetch()
    } catch (e) {
      error.value = e.message
    } finally {
      loading.value = false
    }
  }

  // Initialize
  onMounted(() => {
    fetchData()
  })

  // Return public API
  return {
    data,
    loading,
    error,
    isEmpty,
    fetchData
  }
}

Best Practices

  1. Return refs, not .value - Let consumers access reactivity
  2. Handle loading/error - Always provide state indicators
  3. Clean up - Use onUnmounted for subscriptions
  4. Single responsibility - One domain per composable