Skip to content

Commit

Permalink
refactor: create useRender helper instead of expose() (#13214)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD authored Mar 6, 2021
1 parent 178948d commit e7bf13a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
25 changes: 11 additions & 14 deletions packages/vuetify/src/components/VImg/VImg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import './VImg.sass'
import {
computed,
defineComponent,
getCurrentInstance,
h,
nextTick,
onBeforeMount,
reactive,
ref,
vShow,
watch,
Expand All @@ -25,6 +23,7 @@ import type { ObserveDirectiveBinding } from '@/directives/intersect'

// Utils
import makeProps from '@/util/makeProps'
import { useRender } from '@/util/useRender'
import { useDirective } from '@/util/useDirective'
import { maybeTransition } from '@/util'

Expand Down Expand Up @@ -83,16 +82,6 @@ export default defineComponent({
const naturalWidth = ref<number>()
const naturalHeight = ref<number>()

// TODO: use expose() https://github.com/vuejs/vue-test-utils-next/issues/435
const vm = getCurrentInstance() as any
vm.setupState = reactive({
currentSrc,
image,
state,
naturalWidth,
naturalHeight,
})

const normalisedSrc = computed<srcObject>(() => {
return props.src && typeof props.src === 'object'
? {
Expand Down Expand Up @@ -242,7 +231,7 @@ export default defineComponent({
return maybeTransition(props, { appear: true }, error)
})

return () => withDirectives(
useRender(() => withDirectives(
<VResponsive
class="v-img"
aspectRatio={ aspectRatio.value }
Expand All @@ -260,6 +249,14 @@ export default defineComponent({
},
modifiers: { once: true },
})]
)
))

return {
currentSrc,
image,
state,
naturalWidth,
naturalHeight,
}
},
})
17 changes: 9 additions & 8 deletions packages/vuetify/src/components/VLayout/VLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './VLayout.sass'

// Utilities
import { defineComponent } from 'vue'
import { useRender } from '@/util/useRender'
import makeProps from '@/util/makeProps'

// Composables
Expand All @@ -13,21 +14,21 @@ export default defineComponent({

props: makeProps(makeLayoutProps()),

setup (props, { slots, expose }) {
setup (props, { slots }) {
const { layoutClasses, getLayoutItem, items } = createLayout(props)

expose({
getLayoutItem,
items,
})

return () => (
useRender(() => (
<div
class={layoutClasses.value}
style={{
height: props.fullHeight ? '100vh' : undefined,
}}
>{ slots.default?.() }</div>
)
))

return {
getLayoutItem,
items,
}
},
})
7 changes: 7 additions & 0 deletions packages/vuetify/src/util/useRender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getCurrentInstance } from 'vue'
import type { VNode } from 'vue'

export function useRender (render: () => VNode): void {
const vm = getCurrentInstance() as any
vm.render = render
}

0 comments on commit e7bf13a

Please sign in to comment.