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(noElement): use the full array of VNodes from the default slot #1474

Merged
merged 2 commits into from
May 22, 2024
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
7 changes: 3 additions & 4 deletions packages/x-components/src/components/global-x-bus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
export default defineComponent({
name: 'GlobalXBus',
setup(_, { listeners }) {
setup(_, { listeners, slots }) {
const xBus = useXBus();

/**
Expand Down Expand Up @@ -46,9 +46,8 @@
onBeforeUnmount(() => {
subscription.unsubscribe();
});
},
render() {
return useNoElementRender(this.$slots);

return () => useNoElementRender(slots);
}
});
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/x-components/src/components/no-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNoElementRender } from '../composables/use-no-element-render';
* @internal
*/
export const NoElement = defineComponent({
render() {
return useNoElementRender(this.$slots);
setup(props, { slots }) {
return () => useNoElementRender(slots);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const renderUseNoElementRender = ({
const wrapper = mount(
component ??
(defineComponent({
render() {
return useNoElementRender(this.$slots);
setup(props, { slots }) {
return () => useNoElementRender(slots);
}
}) as ComponentOptions<Vue>),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { VNode } from 'vue/types/vnode';
*/
export function useNoElementRender(
slots: { [key: string]: VNode[] | undefined } | SetupContext['slots']
): VNode {
const defaultSlotContent =
typeof slots.default === 'function' ? slots.default()?.[0] : slots.default?.[0];
): VNode | VNode[] {
const defaultSlotContent = typeof slots.default === 'function' ? slots.default() : slots.default;

return defaultSlotContent ?? h();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
default: () => []
}
},
setup(props) {
setup(props, { slots }) {
const xBus = useXBus();

/**
Expand Down Expand Up @@ -67,9 +67,8 @@
* computed prop changes.
*/
watch(preselectedFilters, emitPreselectedFilters, { immediate: true });
},
render() {
return useNoElementRender(this.$slots);

return () => useNoElementRender(slots);
}
});
</script>
Expand Down
Loading