UNPKG

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