0.1.0 • Published 4 years ago
vue-coupled v0.1.0
vue-coupled
Background
See discussion here.
This package serves as a POC that:
- Allows any level of component encapsulation for child components.
- Supports dynamically toggling children with
v-ifand re-ordering withv-for. - Support TypeScript.
- Whose implementation details are abstracted away from the consumer components.
Usage
npm i --save vue-coupledeg. A <Select> / <Option> couple:
option-group.ts
import { createCoupled } from 'vue-coupled'
type Option = {
value: string
label: string
disabled?: boolean
}
export const { useParent, useChild } = createCoupled<Option>()Select.vue
<script setup lang="ts">
import { useParent } from './option-group'
const children = useParent()
// children will be a shallow ref for the reactive options array, whose
// option data is provided by the `Option` component via `useChild`
</script><script setup lang="ts">
import { useChild } from './option-group'
// Vue doesn't support imported type in defineProps transformation yet
type Option = {
value: string
label: string
disabled?: boolean
}
const props = defineProps<Option>()
useChild(props)
</script>0.1.0
4 years ago