UNPKG

vue-facing-decorator

Version:

Vue typescript class and decorator based component.

50 lines 2.22 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.build = exports.decorator = void 0; const utils_1 = require("../utils"); exports.decorator = (0, utils_1.optionNullableMemberDecorator)(function (proto, name, key) { const slot = (0, utils_1.obtainSlot)(proto); const map = slot.obtainMap('emit'); map.set(name, typeof key === 'undefined' ? null : key); }); function build(cons, optionBuilder) { var _a; (_a = optionBuilder.methods) !== null && _a !== void 0 ? _a : (optionBuilder.methods = {}); const proto = cons.prototype; const slot = (0, utils_1.obtainSlot)(proto); const names = slot.getMap('emit'); if (!names || names.size === 0) { return; } const emits = slot.obtainMap('emits'); names.forEach((value, key) => { const eventName = value === null ? key : value; emits.set(eventName, true); optionBuilder.methods[key] = function () { return __awaiter(this, arguments, void 0, function* () { const ret = proto[key].apply(this, arguments); if (ret instanceof Promise) { const proRet = yield ret; this.$emit(eventName, proRet); } else if (ret === undefined) { this.$emit(eventName); } else { this.$emit(eventName, ret); } }); }; }); } exports.build = build; //# sourceMappingURL=emit.js.map