@zhsz/cool-design-crud
Version:
26 lines (25 loc) • 573 B
JavaScript
import { getCurrentInstance } from "vue";
import { useCore } from "./core.mjs";
import { isFunction } from "../utils/index.mjs";
function useProxy(ctx) {
const { type } = getCurrentInstance();
const { mitt, crud } = useCore();
crud[type.name] = ctx;
mitt.on("crud.proxy", ({ name, data = [], callback }) => {
if (ctx[name]) {
let d = null;
if (isFunction(ctx[name])) {
d = ctx[name](...data);
} else {
d = ctx[name];
}
if (callback) {
callback(d);
}
}
});
return ctx;
}
export {
useProxy
};