UNPKG

framework4js

Version:

Framework-for-js is a better Javascript's framework

161 lines (152 loc) 4.08 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _Exception = _interopRequireDefault(require("../spanners/Exception")); var _Lib = _interopRequireDefault(require("../spanners/Lib")); /** * Class Vue2Adapter Vue.js 2.x adapter * This class is not inheritable. * */ var Vue2Adapter = /*#__PURE__*/function () { function Vue2Adapter($class) { (0, _classCallCheck2["default"])(this, Vue2Adapter); // Vue Class (0, _defineProperty2["default"])(this, "Vue", Function); // Vue model (0, _defineProperty2["default"])(this, "$vm", null); // Vue element (0, _defineProperty2["default"])(this, "hasEl", true); // Vue configs (0, _defineProperty2["default"])(this, "_configs", null); if (!_Lib["default"].isClass($class)) { throw new _Exception["default"]('The first argument must be a class', 'Adapter Error'); } this.Vue = $class; } /** * Method setConfig 设置配置文件 * @param {*} router * @param {*} store * @param {*} render * @param {*} el * @param {*} mounted * @returns */ (0, _createClass2["default"])(Vue2Adapter, [{ key: "setConfig", value: function setConfig(_ref) { var router = _ref.router, store = _ref.store, render = _ref.render, el = _ref.el, mounted = _ref.mounted; var configs = { router: router, store: store, render: render, el: el, mounted: mounted }; // Manually mount node if (!el) { this.hasEl = false; delete configs.el; } // Not use Vuex if (!store) { delete configs.store; } // No mounted if (!mounted) { delete configs.mounted; } this._configs = configs; return this; } /** * Method use 使用插件 * @param args */ }, { key: "use", value: function use() { var _this$Vue; if (this.$vm) { throw new _Exception["default"]('Error', 'Vue.js Error : The use method must be invoked before the run method.'); } (_this$Vue = this.Vue).use.apply(_this$Vue, arguments); } /** * Method mixin 混入 * @param {*} obj */ }, { key: "mixin", value: function mixin(obj) { this.Vue.mixin(obj); } /** * Method component 组件 * @param {...any} args */ }, { key: "component", value: function component() { var _this$Vue2; (_this$Vue2 = this.Vue).component.apply(_this$Vue2, arguments); } /** * Method observable 响应对象 * @param {*} obj * @returns */ }, { key: "observable", value: function observable(obj) { return this.Vue.observable(obj); } /** * Method $mount 挂载 * @param {*} root */ }, { key: "$mount", value: function $mount(root) { this.$vm.$mount(root); } /** * Method instance */ }, { key: "instance", value: function instance() { this.$vm = new this.Vue(this._configs); return this.$vm; } /** * Method run * @returns */ }, { key: "run", value: function run(root) { this.instance(); if (root && !this.hasEl) { this.$mount(root); } else if (root && this.hasEl) { throw new _Exception["default"]('Error', 'Vue root element Error : Nodes can only be bound once'); } else if (!root && !this.hasEl) { throw new _Exception["default"]('Error', 'Vue root element Error : A node must be bound'); } } }]); return Vue2Adapter; }(); exports["default"] = Vue2Adapter;