[improvement] Cell: functional (#2729)

This commit is contained in:
neverland
2019-02-13 15:37:11 +08:00
committed by GitHub
parent a08666947f
commit 4aad9add9c
19 changed files with 162 additions and 129 deletions

View File

@@ -1,4 +1,5 @@
import { RenderContext, VNodeData } from 'vue';
import { RenderContext, VNodeData } from 'vue/types';
import { ScopedSlot } from 'vue/types/vnode';
type ObjectIndex = {
[key: string]: any;
@@ -40,9 +41,23 @@ export function emit(context: Context, eventName: string, ...args: any[]) {
if (Array.isArray(listeners)) {
listeners.forEach(listener => {
listener(...args);
})
});
} else {
listeners(...args);
}
}
}
// unify slots & scopedSlots
export function unifySlots(context: Context) {
const { scopedSlots } = context;
const slots = context.slots();
Object.keys(slots).forEach(key => {
if (!scopedSlots[key]) {
scopedSlots[key] = () => slots[key];
}
});
return scopedSlots;
}