1.0.0 • Published 10 months ago

create-unique-shared-composable v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

GitHub License GitHub commit activity GitHub Actions Workflow Status GitHub Release GitHub Release Date GitHub Issues or Pull Requests GitHub watchers GitHub forks GitHub Repo stars NPM Version NPM Type Definitions NPM Downloads Node Current

createUniqueSharedComposable

Create Vue3 unique shared composables based on keys.

This is similar to the createSharedComposable and createGlobalStates of vueuse, however, uses keys to create independent shared states.

Install

Using pnpm:

pnpm add create-unique-shared-composable

Using yarn:

yarn add create-unique-shared-composable

Using npm:

npm install create-unique-shared-composable

Usage

import { createUniqueSharedComposable } from 'create-unique-shared-composable'
const useFoo = createUniqueSharedComposable((_) => {
  const counter = ref(0)
  const doubled = computed(() => counter.value * 2)
  return {
    counter,
    doubled
  }
})

const { counter, doubled } = useFoo('key')
const { counter: counter1, doubled: doubled1 } = useFoo('key')
const { counter: counter2, doubled: doubled2 } = useFoo('key2')

counter.value++
console.log(counter.value) // 1
console.log(doubled.value) // 2

console.log(counter1.value) // 1
console.log(doubled1.value) // 2

console.log(counter1.value) // 0
console.log(doubled1.value) // 0

Authors

👤 GloryWong

Show Your Support

Give a ⭐️ if this project helped you!

1.0.0

10 months ago