refactor(components): [collection] switch to script-setup syntax (#7710)

Co-authored-by: metanas <matanas@pre-history.com>
This commit is contained in:
Anas Boudih 2022-05-16 15:33:46 +01:00 committed by GitHub
parent c77155b899
commit 9edd89c642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 12 deletions

View File

@ -75,6 +75,6 @@ describe('<ElCollectionItem />', () => {
expect(childVm.itemMap.size).toBe(3)
const items = childVm.getItems()
expect(childVm.getItems()).toHaveLength(3)
expect(items[0].ref).toBe(collectionItems.at(0).element)
expect(items[0].ref).toBe(collectionItems.at(0)?.element)
})
})

View File

@ -2,10 +2,8 @@
<slot />
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
<script lang="ts" setup>
defineOptions({
name: 'ElCollectionItem',
inheritAttrs: false,
})

View File

@ -3,6 +3,7 @@ import Collection from './collection.vue'
import CollectionItem from './collection-item.vue'
import type { InjectionKey } from 'vue'
import type { SetupContext } from '@vue/runtime-core'
import type {
ElCollectionInjectionContext,
ElCollectionItemInjectionContext,
@ -35,10 +36,9 @@ export const createCollectionWithScope = (name: string) => {
const items = [...itemMap.values()]
const orderedItems = items.sort(
return items.sort(
(a, b) => orderedNodes.indexOf(a.ref!) - orderedNodes.indexOf(b.ref!)
)
return orderedItems
}
provide(COLLECTION_INJECTION_KEY, {
@ -52,7 +52,7 @@ export const createCollectionWithScope = (name: string) => {
const ElCollectionItem = {
...CollectionItem,
name: COLLECTION_ITEM_NAME,
setup(_, { attrs }) {
setup(_, { attrs }: SetupContext) {
const collectionItemRef = ref<HTMLElement | null>(null)
const collectionInjection = inject(COLLECTION_INJECTION_KEY, undefined)!

View File

@ -2,10 +2,8 @@
<slot />
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
<script lang="ts" setup>
defineOptions({
inheritAttrs: false,
})
</script>