UNPKG

9.14 kBJavaScriptView Raw
1/**
2 * vue-class-component v8.0.0-alpha.2
3 * (c) 2015-present Evan You
4 * @license MIT
5 */
6'use strict';
7
8Object.defineProperty(exports, '__esModule', { value: true });
9
10function _classCallCheck(instance, Constructor) {
11 if (!(instance instanceof Constructor)) {
12 throw new TypeError("Cannot call a class as a function");
13 }
14}
15
16function _defineProperties(target, props) {
17 for (var i = 0; i < props.length; i++) {
18 var descriptor = props[i];
19 descriptor.enumerable = descriptor.enumerable || false;
20 descriptor.configurable = true;
21 if ("value" in descriptor) descriptor.writable = true;
22 Object.defineProperty(target, descriptor.key, descriptor);
23 }
24}
25
26function _createClass(Constructor, protoProps, staticProps) {
27 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
28 if (staticProps) _defineProperties(Constructor, staticProps);
29 return Constructor;
30}
31
32function _defineProperty(obj, key, value) {
33 if (key in obj) {
34 Object.defineProperty(obj, key, {
35 value: value,
36 enumerable: true,
37 configurable: true,
38 writable: true
39 });
40 } else {
41 obj[key] = value;
42 }
43
44 return obj;
45}
46
47function ownKeys(object, enumerableOnly) {
48 var keys = Object.keys(object);
49
50 if (Object.getOwnPropertySymbols) {
51 var symbols = Object.getOwnPropertySymbols(object);
52 if (enumerableOnly) symbols = symbols.filter(function (sym) {
53 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
54 });
55 keys.push.apply(keys, symbols);
56 }
57
58 return keys;
59}
60
61function _objectSpread2(target) {
62 for (var i = 1; i < arguments.length; i++) {
63 var source = arguments[i] != null ? arguments[i] : {};
64
65 if (i % 2) {
66 ownKeys(Object(source), true).forEach(function (key) {
67 _defineProperty(target, key, source[key]);
68 });
69 } else if (Object.getOwnPropertyDescriptors) {
70 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
71 } else {
72 ownKeys(Object(source)).forEach(function (key) {
73 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
74 });
75 }
76 }
77
78 return target;
79}
80
81function _inherits(subClass, superClass) {
82 if (typeof superClass !== "function" && superClass !== null) {
83 throw new TypeError("Super expression must either be null or a function");
84 }
85
86 subClass.prototype = Object.create(superClass && superClass.prototype, {
87 constructor: {
88 value: subClass,
89 writable: true,
90 configurable: true
91 }
92 });
93 if (superClass) _setPrototypeOf(subClass, superClass);
94}
95
96function _getPrototypeOf(o) {
97 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
98 return o.__proto__ || Object.getPrototypeOf(o);
99 };
100 return _getPrototypeOf(o);
101}
102
103function _setPrototypeOf(o, p) {
104 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
105 o.__proto__ = p;
106 return o;
107 };
108
109 return _setPrototypeOf(o, p);
110}
111
112function _assertThisInitialized(self) {
113 if (self === void 0) {
114 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
115 }
116
117 return self;
118}
119
120function _possibleConstructorReturn(self, call) {
121 if (call && (typeof call === "object" || typeof call === "function")) {
122 return call;
123 }
124
125 return _assertThisInitialized(self);
126}
127
128function _toConsumableArray(arr) {
129 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
130}
131
132function _arrayWithoutHoles(arr) {
133 if (Array.isArray(arr)) {
134 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
135
136 return arr2;
137 }
138}
139
140function _iterableToArray(iter) {
141 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
142}
143
144function _nonIterableSpread() {
145 throw new TypeError("Invalid attempt to spread non-iterable instance");
146}
147
148function isFunction(value) {
149 return typeof value === 'function';
150}
151
152function getSuperOptions(Ctor) {
153 var superProto = Object.getPrototypeOf(Ctor.prototype);
154
155 if (!superProto) {
156 return undefined;
157 }
158
159 var Super = superProto.constructor;
160 return Super.__vccOpts;
161}
162
163var Vue =
164/*#__PURE__*/
165function () {
166 function Vue(props) {
167 var _this = this;
168
169 _classCallCheck(this, Vue);
170
171 this.$props = props;
172 Object.keys(props).forEach(function (key) {
173 Object.defineProperty(_this, key, {
174 enumerable: false,
175 configurable: true,
176 writable: true,
177 value: props[key]
178 });
179 });
180 }
181 /** @internal */
182
183
184 _createClass(Vue, null, [{
185 key: "registerHooks",
186 value: function registerHooks(keys) {
187 var _this$__vccHooks;
188
189 (_this$__vccHooks = this.__vccHooks).push.apply(_this$__vccHooks, _toConsumableArray(keys));
190 }
191 }, {
192 key: "__vccOpts",
193 get: function get() {
194 // Early return if `this` is base class as it does not have any options
195 if (this === Vue) {
196 return {};
197 }
198
199 var cache = this.hasOwnProperty('__vccCache') && this.__vccCache;
200
201 if (cache) {
202 return cache;
203 }
204
205 var Ctor = this; // If the options are provided via decorator use it as a base
206
207 var options = this.__vccCache = this.hasOwnProperty('__vccBase') ? _objectSpread2({}, this.__vccBase) : {}; // Handle super class options
208
209 options["extends"] = getSuperOptions(Ctor); // Handle mixins
210
211 var mixins = this.hasOwnProperty('__vccMixins') && this.__vccMixins;
212
213 if (mixins) {
214 options.mixins = options.mixins ? options.mixins.concat(mixins) : mixins;
215 } // Class name -> component name
216
217
218 options.name = options.name || Ctor.name;
219 options.methods = _objectSpread2({}, options.methods);
220 options.computed = _objectSpread2({}, options.computed);
221 var proto = Ctor.prototype;
222 Object.getOwnPropertyNames(proto).forEach(function (key) {
223 if (key === 'constructor') {
224 return;
225 } // hooks
226
227
228 if (Ctor.__vccHooks.indexOf(key) > -1) {
229 options[key] = proto[key];
230 return;
231 }
232
233 var descriptor = Object.getOwnPropertyDescriptor(proto, key); // methods
234
235 if (typeof descriptor.value === 'function') {
236 options.methods[key] = descriptor.value;
237 return;
238 } // computed properties
239
240
241 if (descriptor.get || descriptor.set) {
242 options.computed[key] = {
243 get: descriptor.get,
244 set: descriptor.set
245 };
246 return;
247 }
248 }); // Class properties -> reactive data
249
250 var hookDataOption = options.data;
251
252 options.data = function () {
253 var hookData = isFunction(hookDataOption) ? hookDataOption.call(this, this) : hookDataOption; // should be acquired class property values
254
255 var data = new Ctor(this.$props); // create plain data object
256
257 var plainData = {};
258 Object.keys(data).forEach(function (key) {
259 if (data[key] !== undefined && key !== '$props') {
260 plainData[key] = data[key];
261 }
262 });
263 return _objectSpread2({}, hookData, {}, plainData);
264 };
265
266 var decorators = this.hasOwnProperty('__vccDecorators') && this.__vccDecorators;
267
268 if (decorators) {
269 decorators.forEach(function (fn) {
270 return fn(options);
271 });
272 } // from Vue Loader
273
274
275 if (Ctor.render) {
276 options.render = Ctor.render;
277 }
278
279 if (Ctor.__file) {
280 options.__file = Ctor.__file;
281 }
282
283 if (Ctor.__cssModules) {
284 options.__cssModules = Ctor.__cssModules;
285 }
286
287 if (Ctor.__scopeId) {
288 options.__scopeId = Ctor.__scopeId;
289 }
290
291 return options;
292 }
293 }]);
294
295 return Vue;
296}();
297/** @internal */
298
299Vue.__vccHooks = ['data', 'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUnmount', 'unmounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'errorCaptured', 'serverPrefetch'];
300
301function Options(options) {
302 return function (Component) {
303 Component.__vccBase = options;
304 return Component;
305 };
306}
307function createDecorator(factory) {
308 return function (target, key, index) {
309 var Ctor = typeof target === 'function' ? target : target.constructor;
310
311 if (!Ctor.__vccDecorators) {
312 Ctor.__vccDecorators = [];
313 }
314
315 if (typeof index !== 'number') {
316 index = undefined;
317 }
318
319 Ctor.__vccDecorators.push(function (options) {
320 return factory(options, key, index);
321 });
322 };
323}
324function mixins() {
325 var _a;
326
327 for (var _len = arguments.length, Ctors = new Array(_len), _key = 0; _key < _len; _key++) {
328 Ctors[_key] = arguments[_key];
329 }
330
331 return _a =
332 /*#__PURE__*/
333 function (_Vue) {
334 _inherits(MixedVue, _Vue);
335
336 function MixedVue() {
337 _classCallCheck(this, MixedVue);
338
339 return _possibleConstructorReturn(this, _getPrototypeOf(MixedVue).apply(this, arguments));
340 }
341
342 return MixedVue;
343 }(Vue), _a.__vccMixins = Ctors.map(function (Ctor) {
344 return Ctor.__vccOpts;
345 }), _a;
346}
347
348exports.Options = Options;
349exports.Vue = Vue;
350exports.createDecorator = createDecorator;
351exports.mixins = mixins;