refactor: remove useChildren

This commit is contained in:
chenjiahan 2020-08-24 19:02:13 +08:00
parent b463fa5f69
commit e893efd60d
2 changed files with 4 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import { ref, provide } from 'vue';
import { createNamespace } from '../utils';
import { useChildren } from '../api/use-relation';
const [createComponent, bem] = createNamespace('action-bar');
@ -14,7 +14,8 @@ export default createComponent({
},
setup(props, { slots }) {
useChildren(ACTION_BAR_KEY);
const children = ref([]);
provide(ACTION_BAR_KEY, children);
return () => (
<div class={bem({ unfit: !props.safeAreaInsetBottom })}>

View File

@ -1,15 +1,9 @@
import { ref, Ref, provide, inject, computed, onUnmounted } from 'vue';
import { Ref, inject, computed, onUnmounted } from 'vue';
export type Parent<T = unknown> = null | {
children: Ref<Ref<T>[]>;
};
export function useChildren(key: string) {
const children = ref<unknown>([]);
provide(key, { children });
return children;
}
export function useParent<T = unknown>(key: string, child: Ref<T>) {
const parent = inject<Parent<T>>(key, null);