index.ts 840 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { inject } from 'vue'
  2. import {
  3. COLLECTION_ITEM_SIGN,
  4. createCollectionWithScope,
  5. } from '../src/collection'
  6. const TestCollection = createCollectionWithScope('Test')
  7. export default TestCollection
  8. export const CollectionChildComponent = {
  9. setup() {
  10. const { getItems, collectionRef, itemMap } = inject(
  11. TestCollection.COLLECTION_INJECTION_KEY,
  12. undefined
  13. )!
  14. return {
  15. itemMap,
  16. getItems,
  17. collectionRef,
  18. }
  19. },
  20. template: `<div ref="collectionRef"><slot/></div>`,
  21. }
  22. export const CollectionItemChildComponent = {
  23. setup() {
  24. const { collectionItemRef } = inject(
  25. TestCollection.COLLECTION_ITEM_INJECTION_KEY,
  26. undefined
  27. )!
  28. return {
  29. collectionItemRef,
  30. }
  31. },
  32. template: `<div ref="collectionItemRef" class="${COLLECTION_ITEM_SIGN}" ><slot /></div>`,
  33. }