@zhsz/cool-design-crud
Version:
26 lines (25 loc) • 659 B
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const core = require("./core.js");
const index = require("../utils/index.js");
function useProxy(ctx) {
const { type } = vue.getCurrentInstance();
const { mitt, crud } = core.useCore();
crud[type.name] = ctx;
mitt.on("crud.proxy", ({ name, data = [], callback }) => {
if (ctx[name]) {
let d = null;
if (index.isFunction(ctx[name])) {
d = ctx[name](...data);
} else {
d = ctx[name];
}
if (callback) {
callback(d);
}
}
});
return ctx;
}
exports.useProxy = useProxy;