|
277 | 277 | }
|
278 | 278 |
|
279 | 279 | function Data() {
|
280 |
| - return function (target, key) { |
281 |
| - if (target['data'] && target['data'] instanceof Function) { |
282 |
| - throw "vue-typed error: [" + target.constructor.name + "]: You can't use @data attribute while you have already data() function in your class."; |
283 |
| - } |
284 |
| - var id = '$_vt_data'; |
285 |
| - if (!target[id]) { |
286 |
| - target[id] = {}; |
287 |
| - } |
288 |
| - if (!target[id][key]) { |
289 |
| - target[id][key] = key; |
290 |
| - } |
291 |
| - }; |
| 280 | + return function (target, key) {}; |
292 | 281 | }
|
293 | 282 |
|
294 | 283 | function Getter(getter) {
|
|
305 | 294 | };
|
306 | 295 | }
|
307 | 296 |
|
| 297 | + var vueInternalPropNames = Object.getOwnPropertyNames(new Vue()); |
| 298 | + var vueInternalHooks = ['activate', 'init', 'ready', 'beforeCompile', 'compiled', 'attached', 'detached', 'created', 'beforeDestroy', 'destroyed', 'props', 'watch', 'data', 'beforeCreate', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'el', 'vuex']; |
308 | 299 | function Component(options) {
|
309 |
| - var internalHooks = ['activate', 'init', 'ready', 'beforeCompile', 'compiled', 'attached', 'detached', 'created', 'beforeDestroy', 'destroyed', 'props', 'watch', 'data', 'beforeCreate', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'render', 'el', 'vuex']; |
310 | 300 | var factory = function factory(Component, options) {
|
311 | 301 | if (!options) {
|
312 | 302 | options = {};
|
|
328 | 318 | });
|
329 | 319 | }
|
330 | 320 | }
|
331 |
| - var dataAttrs = proto['$_vt_data']; |
332 |
| - delete proto['$_vt_data']; |
333 |
| - if (dataAttrs) { |
334 |
| - var data_keys = Object.getOwnPropertyNames(dataAttrs); |
335 |
| - options['data'] = function () { |
336 |
| - var data_obj = {}; |
337 |
| - for (var i = 0; i < data_keys.length; i++) { |
338 |
| - var prop = data_keys[i]; |
339 |
| - data_obj[prop] = constructor[prop]; |
340 |
| - } |
341 |
| - return data_obj; |
342 |
| - }; |
343 |
| - } |
344 | 321 | var propAttrs = proto['$_vt_props'];
|
| 322 | + var propNames = undefined; |
345 | 323 | delete proto['$_vt_props'];
|
346 | 324 | if (propAttrs) {
|
347 | 325 | var key = 'props';
|
348 | 326 | var props = {};
|
349 |
| - var prop_keys = Object.getOwnPropertyNames(propAttrs); |
350 |
| - for (var i = 0; i < prop_keys.length; i++) { |
351 |
| - var prop = prop_keys[i]; |
| 327 | + propNames = Object.getOwnPropertyNames(propAttrs); |
| 328 | + for (var i = 0; i < propNames.length; i++) { |
| 329 | + var prop = propNames[i]; |
352 | 330 | var propVal = undefined;
|
353 | 331 | var descriptor = Object.getOwnPropertyDescriptor(propAttrs, prop);
|
354 | 332 | var constructorDefault = constructor[prop];
|
|
371 | 349 | if (key === 'constructor') {
|
372 | 350 | return;
|
373 | 351 | }
|
374 |
| - if (internalHooks.indexOf(key) > -1) { |
| 352 | + if (vueInternalHooks.indexOf(key) > -1) { |
375 | 353 | options[key] = proto[key];
|
376 | 354 | return;
|
377 | 355 | }
|
|
386 | 364 | };
|
387 | 365 | }
|
388 | 366 | });
|
| 367 | + var dataNames = []; |
| 368 | + var restrictedNames = vueInternalPropNames; |
| 369 | + if (propNames) restrictedNames = restrictedNames.concat(propNames); |
| 370 | + if (vueKeys && vueKeys.length) restrictedNames = restrictedNames.concat(vueKeys); |
| 371 | + Object.getOwnPropertyNames(constructor).forEach(function (key) { |
| 372 | + if (restrictedNames.indexOf(key) === -1) { |
| 373 | + dataNames.push(key); |
| 374 | + } |
| 375 | + }); |
| 376 | + if (dataNames.length > 0) { |
| 377 | + var parentData = undefined; |
| 378 | + var parentDataType = _typeof(options['data']); |
| 379 | + if (parentDataType === 'function') { |
| 380 | + parentData = options['data'](); |
| 381 | + } else if (parentDataType === 'object') { |
| 382 | + parentData = options['data']; |
| 383 | + } |
| 384 | + options['data'] = function () { |
| 385 | + var data_obj = parentData || {}; |
| 386 | + dataNames.forEach(function (prop) { |
| 387 | + var descriptor = Object.getOwnPropertyDescriptor(constructor, prop); |
| 388 | + if (!descriptor.get && !descriptor.set && typeof descriptor.value !== 'function') { |
| 389 | + data_obj[prop] = constructor[prop]; |
| 390 | + } |
| 391 | + }); |
| 392 | + return data_obj; |
| 393 | + }; |
| 394 | + } |
389 | 395 | var superProto = Object.getPrototypeOf(proto);
|
390 | 396 | var Super = superProto instanceof Vue ? superProto.constructor : Vue;
|
391 | 397 | return Super['extend'](options);
|
|
0 commit comments