Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create useRender helper instead of expose() #13214

Merged
merged 1 commit into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}